use of org.opensearch.common.settings.SettingsException in project OpenSearch by opensearch-project.
the class GoogleCloudStorageClientSettingsTests method testProxyTypeNotSet.
public void testProxyTypeNotSet() {
final Settings hostPortSettings = Settings.builder().put("gcs.client.default.proxy.host", "127.0.0.1").put("gcs.client.default.proxy.port", 8080).build();
SettingsException e = expectThrows(SettingsException.class, () -> GoogleCloudStorageClientSettings.load(hostPortSettings));
assertEquals("Google Cloud Storage proxy port or host or username or password have been set but proxy type is not defined.", e.getMessage());
final MockSecureSettings secureSettings = new MockSecureSettings();
secureSettings.setString("gcs.client.default.proxy.username", "aaaa");
secureSettings.setString("gcs.client.default.proxy.password", "bbbb");
final Settings usernamePasswordSettings = Settings.builder().setSecureSettings(secureSettings).build();
e = expectThrows(SettingsException.class, () -> GoogleCloudStorageClientSettings.load(usernamePasswordSettings));
assertEquals("Google Cloud Storage proxy port or host or username or password have been set but proxy type is not defined.", e.getMessage());
}
use of org.opensearch.common.settings.SettingsException in project OpenSearch by opensearch-project.
the class S3ClientSettingsTests method testProxyWrongHost.
public void testProxyWrongHost() {
final Settings settings = Settings.builder().put("s3.client.default.proxy.type", randomFrom("socks", "http")).put("s3.client.default.proxy.host", "thisisnotavalidhostorwehavebeensuperunlucky").put("s3.client.default.proxy.port", 8080).build();
final SettingsException e = expectThrows(SettingsException.class, () -> S3ClientSettings.load(settings));
assertEquals("S3 proxy host is unknown.", e.getMessage());
}
use of org.opensearch.common.settings.SettingsException in project OpenSearch by opensearch-project.
the class S3ClientSettingsTests method testProxyHostNotSet.
public void testProxyHostNotSet() {
final Settings settings = Settings.builder().put("s3.client.default.proxy.port", 8080).put("s3.client.default.proxy.type", randomFrom("socks", "http", "https")).build();
final SettingsException e = expectThrows(SettingsException.class, () -> S3ClientSettings.load(settings));
assertEquals("S3 proxy type has been set but proxy host or port is not defined.", e.getMessage());
}
use of org.opensearch.common.settings.SettingsException in project OpenSearch by opensearch-project.
the class Ec2ClientSettings method loadCredentials.
static AWSCredentials loadCredentials(Settings settings) {
try (SecureString key = ACCESS_KEY_SETTING.get(settings);
SecureString secret = SECRET_KEY_SETTING.get(settings);
SecureString sessionToken = SESSION_TOKEN_SETTING.get(settings)) {
if (key.length() == 0 && secret.length() == 0) {
if (sessionToken.length() > 0) {
throw new SettingsException("Setting [{}] is set but [{}] and [{}] are not", SESSION_TOKEN_SETTING.getKey(), ACCESS_KEY_SETTING.getKey(), SECRET_KEY_SETTING.getKey());
}
logger.debug("Using either environment variables, system properties or instance profile credentials");
return null;
} else {
if (key.length() == 0) {
deprecationLogger.deprecate("ec2_invalid_key_settings", "Setting [{}] is set but [{}] is not, which will be unsupported in future", SECRET_KEY_SETTING.getKey(), ACCESS_KEY_SETTING.getKey());
}
if (secret.length() == 0) {
deprecationLogger.deprecate("ec2_invalid_settings", "Setting [{}] is set but [{}] is not, which will be unsupported in future", ACCESS_KEY_SETTING.getKey(), SECRET_KEY_SETTING.getKey());
}
final AWSCredentials credentials;
if (sessionToken.length() == 0) {
logger.debug("Using basic key/secret credentials");
credentials = new BasicAWSCredentials(key.toString(), secret.toString());
} else {
logger.debug("Using basic session credentials");
credentials = new BasicSessionCredentials(key.toString(), secret.toString(), sessionToken.toString());
}
return credentials;
}
}
}
use of org.opensearch.common.settings.SettingsException in project OpenSearch by opensearch-project.
the class GoogleCloudStorageClientSettings method validateAndCreateProxySettings.
static ProxySettings validateAndCreateProxySettings(final Settings settings, final String clientName) {
final Proxy.Type proxyType = getConfigValue(settings, clientName, PROXY_TYPE_SETTING);
final String proxyHost = getConfigValue(settings, clientName, PROXY_HOST_SETTING);
final int proxyPort = getConfigValue(settings, clientName, PROXY_PORT_SETTING);
final SecureString proxyUserName = getConfigValue(settings, clientName, PROXY_USERNAME_SETTING);
final SecureString proxyPassword = getConfigValue(settings, clientName, PROXY_PASSWORD_SETTING);
// Validate proxy settings
if (proxyType == Proxy.Type.DIRECT && (proxyPort != 0 || Strings.hasText(proxyHost) || Strings.hasText(proxyUserName) || Strings.hasText(proxyPassword))) {
throw new SettingsException("Google Cloud Storage proxy port or host or username or password have been set but proxy type is not defined.");
}
if (proxyType != Proxy.Type.DIRECT && (proxyPort == 0 || Strings.isEmpty(proxyHost))) {
throw new SettingsException("Google Cloud Storage proxy type has been set but proxy host or port is not defined.");
}
if (proxyType == Proxy.Type.DIRECT) {
return ProxySettings.NO_PROXY_SETTINGS;
}
try {
final InetAddress proxyHostAddress = InetAddress.getByName(proxyHost);
return new ProxySettings(proxyType, proxyHostAddress, proxyPort, proxyUserName.toString(), proxyPassword.toString());
} catch (final UnknownHostException e) {
throw new SettingsException("Google Cloud Storage proxy host is unknown.", e);
}
}
Aggregations