Search in sources :

Example 6 with SettingsException

use of org.elasticsearch.common.settings.SettingsException in project crate by crate.

the class AzureStorageServiceTests method testProxyWrongHost.

public void testProxyWrongHost() {
    final Settings settings = Settings.builder().put(buildClientCredSettings()).put("proxy_type", randomFrom("socks", "http")).put("proxy_host", "thisisnotavalidhostorwehavebeensuperunlucky").put("proxy_port", 8080).build();
    final SettingsException e = expectThrows(SettingsException.class, () -> storageServiceWithSettings(settings));
    assertEquals("Azure proxy host is unknown.", e.getMessage());
}
Also used : SettingsException(org.elasticsearch.common.settings.SettingsException) Settings(org.elasticsearch.common.settings.Settings)

Example 7 with SettingsException

use of org.elasticsearch.common.settings.SettingsException in project crate by crate.

the class AzureStorageServiceTests method testProxyNoPort.

public void testProxyNoPort() {
    final Settings settings = Settings.builder().put(buildClientCredSettings()).put("proxy_host", "127.0.0.1").put("proxy_type", randomFrom("socks", "http")).build();
    final SettingsException e = expectThrows(SettingsException.class, () -> storageServiceWithSettings(settings));
    assertEquals("Azure Proxy type has been set but proxy host or port is not defined.", e.getMessage());
}
Also used : SettingsException(org.elasticsearch.common.settings.SettingsException) Settings(org.elasticsearch.common.settings.Settings)

Example 8 with SettingsException

use of org.elasticsearch.common.settings.SettingsException in project crate by crate.

the class AzureStorageServiceTests method testProxyNoType.

public void testProxyNoType() {
    final Settings settings = Settings.builder().put(buildClientCredSettings()).put("proxy_host", "127.0.0.1").put("proxy_port", 8080).build();
    final SettingsException e = expectThrows(SettingsException.class, () -> storageServiceWithSettings(settings));
    assertEquals("Azure Proxy port or host have been set but proxy type is not defined.", e.getMessage());
}
Also used : SettingsException(org.elasticsearch.common.settings.SettingsException) Settings(org.elasticsearch.common.settings.Settings)

Example 9 with SettingsException

use of org.elasticsearch.common.settings.SettingsException in project crate by crate.

the class Netty4HttpServerTransport method buildCorsConfig.

// package private for testing
static Netty4CorsConfig buildCorsConfig(Settings settings) {
    if (SETTING_CORS_ENABLED.get(settings) == false) {
        return Netty4CorsConfigBuilder.forOrigins().disable().build();
    }
    String origin = SETTING_CORS_ALLOW_ORIGIN.get(settings);
    final Netty4CorsConfigBuilder builder;
    if (Strings.isNullOrEmpty(origin)) {
        builder = Netty4CorsConfigBuilder.forOrigins();
    } else if (origin.equals(ANY_ORIGIN)) {
        builder = Netty4CorsConfigBuilder.forAnyOrigin();
    } else {
        try {
            Pattern p = RestUtils.checkCorsSettingForRegex(origin);
            if (p == null) {
                builder = Netty4CorsConfigBuilder.forOrigins(RestUtils.corsSettingAsArray(origin));
            } else {
                builder = Netty4CorsConfigBuilder.forPattern(p);
            }
        } catch (PatternSyntaxException e) {
            throw new SettingsException("Bad regex in [" + SETTING_CORS_ALLOW_ORIGIN.getKey() + "]: [" + origin + "]", e);
        }
    }
    if (SETTING_CORS_ALLOW_CREDENTIALS.get(settings)) {
        builder.allowCredentials();
    }
    String[] strMethods = Strings.tokenizeToStringArray(SETTING_CORS_ALLOW_METHODS.get(settings), ",");
    HttpMethod[] methods = Arrays.stream(strMethods).map(HttpMethod::valueOf).toArray(HttpMethod[]::new);
    return builder.allowedRequestMethods(methods).maxAge(SETTING_CORS_MAX_AGE.get(settings)).allowedRequestHeaders(Strings.tokenizeToStringArray(SETTING_CORS_ALLOW_HEADERS.get(settings), ",")).shortCircuit().build();
}
Also used : Pattern(java.util.regex.Pattern) Netty4CorsConfigBuilder(org.elasticsearch.http.netty4.cors.Netty4CorsConfigBuilder) SettingsException(org.elasticsearch.common.settings.SettingsException) HttpMethod(io.netty.handler.codec.http.HttpMethod) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 10 with SettingsException

use of org.elasticsearch.common.settings.SettingsException in project elasticsearch by elastic.

the class InternalSettingsPreparerTests method testGarbageIsNotSwallowed.

public void testGarbageIsNotSwallowed() throws IOException {
    try {
        InputStream garbage = getClass().getResourceAsStream("/config/garbage/garbage.yml");
        Path home = createTempDir();
        Path config = home.resolve("config");
        Files.createDirectory(config);
        Files.copy(garbage, config.resolve("elasticsearch.yml"));
        InternalSettingsPreparer.prepareEnvironment(Settings.builder().put(baseEnvSettings).build(), null);
    } catch (SettingsException e) {
        assertEquals("Failed to load settings from [elasticsearch.yml]", e.getMessage());
    }
}
Also used : Path(java.nio.file.Path) InputStream(java.io.InputStream) SettingsException(org.elasticsearch.common.settings.SettingsException)

Aggregations

SettingsException (org.elasticsearch.common.settings.SettingsException)16 Settings (org.elasticsearch.common.settings.Settings)10 Path (java.nio.file.Path)5 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 AzureStorageSettings (org.elasticsearch.cloud.azure.storage.AzureStorageSettings)2 Environment (org.elasticsearch.env.Environment)2 AWSCredentials (com.amazonaws.auth.AWSCredentials)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 BasicSessionCredentials (com.amazonaws.auth.BasicSessionCredentials)1 HttpMethod (io.netty.handler.codec.http.HttpMethod)1 HashSet (java.util.HashSet)1 Pattern (java.util.regex.Pattern)1 PatternSyntaxException (java.util.regex.PatternSyntaxException)1 Strings.cleanPath (org.elasticsearch.common.Strings.cleanPath)1 SecureString (org.elasticsearch.common.settings.SecureString)1 Netty4CorsConfigBuilder (org.elasticsearch.http.netty4.cors.Netty4CorsConfigBuilder)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1