Search in sources :

Example 11 with SettingsException

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());
}
Also used : SettingsException(org.opensearch.common.settings.SettingsException) GoogleCloudStorageClientSettings.getClientSettings(org.opensearch.repositories.gcs.GoogleCloudStorageClientSettings.getClientSettings) MockSecureSettings(org.opensearch.common.settings.MockSecureSettings) Settings(org.opensearch.common.settings.Settings) MockSecureSettings(org.opensearch.common.settings.MockSecureSettings)

Example 12 with SettingsException

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());
}
Also used : SettingsException(org.opensearch.common.settings.SettingsException) MockSecureSettings(org.opensearch.common.settings.MockSecureSettings) Settings(org.opensearch.common.settings.Settings)

Example 13 with SettingsException

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());
}
Also used : SettingsException(org.opensearch.common.settings.SettingsException) MockSecureSettings(org.opensearch.common.settings.MockSecureSettings) Settings(org.opensearch.common.settings.Settings)

Example 14 with SettingsException

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;
        }
    }
}
Also used : BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials) SettingsException(org.opensearch.common.settings.SettingsException) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) AWSCredentials(com.amazonaws.auth.AWSCredentials) SecureString(org.opensearch.common.settings.SecureString) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 15 with SettingsException

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);
    }
}
Also used : Proxy(java.net.Proxy) UnknownHostException(java.net.UnknownHostException) SecureString(org.opensearch.common.settings.SecureString) SettingsException(org.opensearch.common.settings.SettingsException) InetAddress(java.net.InetAddress) SecureString(org.opensearch.common.settings.SecureString)

Aggregations

SettingsException (org.opensearch.common.settings.SettingsException)23 Settings (org.opensearch.common.settings.Settings)15 MockSecureSettings (org.opensearch.common.settings.MockSecureSettings)14 SecureString (org.opensearch.common.settings.SecureString)4 BlobServiceClient (com.azure.storage.blob.BlobServiceClient)3 GoogleCloudStorageClientSettings.getClientSettings (org.opensearch.repositories.gcs.GoogleCloudStorageClientSettings.getClientSettings)3 IOException (java.io.IOException)2 InetAddress (java.net.InetAddress)2 UnknownHostException (java.net.UnknownHostException)2 Path (java.nio.file.Path)2 AWSCredentials (com.amazonaws.auth.AWSCredentials)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Proxy (java.net.Proxy)1 HashMap (java.util.HashMap)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 ToXContent (org.opensearch.common.xcontent.ToXContent)1 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)1