use of org.opensearch.common.settings.SettingsException in project OpenSearch by opensearch-project.
the class InternalSettingsPreparer method prepareEnvironment.
/**
* Prepares the settings by gathering all opensearch system properties, optionally loading the configuration settings.
*
* @param input the custom settings to use; these are not overwritten by settings in the configuration file
* @param properties map of properties key/value pairs (usually from the command-line)
* @param configPath path to config directory; (use null to indicate the default)
* @param defaultNodeName supplier for the default node.name if the setting isn't defined
* @return the {@link Environment}
*/
public static Environment prepareEnvironment(Settings input, Map<String, String> properties, Path configPath, Supplier<String> defaultNodeName) {
// just create enough settings to build the environment, to get the config dir
Settings.Builder output = Settings.builder();
initializeSettings(output, input, properties);
Environment environment = new Environment(output.build(), configPath);
// start with a fresh output
output = Settings.builder();
Path path = environment.configFile().resolve("opensearch.yml");
if (Files.exists(path)) {
try {
output.loadFromPath(path);
} catch (IOException e) {
throw new SettingsException("Failed to load settings from " + path.toString(), e);
}
}
// re-initialize settings now that the config file has been loaded
initializeSettings(output, input, properties);
checkSettingsForTerminalDeprecation(output);
finalizeSettings(output, defaultNodeName);
return new Environment(output.build(), configPath);
}
use of org.opensearch.common.settings.SettingsException in project OpenSearch by opensearch-project.
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("opensearch.yml"));
InternalSettingsPreparer.prepareEnvironment(Settings.builder().put(baseEnvSettings).build(), emptyMap(), null, () -> "default_node_name");
} catch (SettingsException e) {
assertEquals("Failed to load settings from [opensearch.yml]", e.getMessage());
}
}
use of org.opensearch.common.settings.SettingsException in project OpenSearch by opensearch-project.
the class CorsHandlerTests method testCorsConfigWithBadRegex.
public void testCorsConfigWithBadRegex() {
final Settings settings = Settings.builder().put(SETTING_CORS_ENABLED.getKey(), true).put(SETTING_CORS_ALLOW_ORIGIN.getKey(), "/[*/").put(SETTING_CORS_ALLOW_CREDENTIALS.getKey(), true).build();
SettingsException e = expectThrows(SettingsException.class, () -> CorsHandler.buildConfig(settings));
assertThat(e.getMessage(), containsString("Bad regex in [http.cors.allow-origin]: [/[*/]"));
assertThat(e.getCause(), instanceOf(PatternSyntaxException.class));
}
Aggregations