use of org.elasticsearch.env.Environment in project elasticsearch by elastic.
the class InternalSettingsPreparerTests method testSecureSettings.
public void testSecureSettings() {
MockSecureSettings secureSettings = new MockSecureSettings();
secureSettings.setString("foo", "secret");
Settings input = Settings.builder().put(baseEnvSettings).setSecureSettings(secureSettings).build();
Environment env = InternalSettingsPreparer.prepareEnvironment(input, null);
Setting<SecureString> fakeSetting = SecureSetting.secureString("foo", null, false);
assertEquals("secret", fakeSetting.get(env.settings()).toString());
}
use of org.elasticsearch.env.Environment in project elasticsearch by elastic.
the class InternalSettingsPreparerTests method testEmptySettings.
public void testEmptySettings() {
Settings settings = InternalSettingsPreparer.prepareSettings(Settings.EMPTY);
// a name was not set
assertNull(settings.get("node.name"));
// a cluster name was set
assertNotNull(settings.get(ClusterName.CLUSTER_NAME_SETTING.getKey()));
int size = settings.names().size();
Environment env = InternalSettingsPreparer.prepareEnvironment(baseEnvSettings, null);
settings = env.settings();
// a name was not set
assertNull(settings.get("node.name"));
// a cluster name was set
assertNotNull(settings.get(ClusterName.CLUSTER_NAME_SETTING.getKey()));
assertEquals(settings.toString(), size + 1, /* path.home is in the base settings */
settings.names().size());
String home = Environment.PATH_HOME_SETTING.get(baseEnvSettings);
String configDir = env.configFile().toString();
assertTrue(configDir, configDir.startsWith(home));
}
use of org.elasticsearch.env.Environment in project elasticsearch by elastic.
the class InternalSettingsPreparer method prepareEnvironment.
/**
* Prepares the settings by gathering all elasticsearch system properties, optionally loading the configuration settings,
* and then replacing all property placeholders. If a {@link Terminal} is provided and configuration settings are loaded,
* settings with a value of <code>${prompt.text}</code> or <code>${prompt.secret}</code> will result in a prompt for
* the setting to the user.
* @param input The custom settings to use. These are not overwritten by settings in the configuration file.
* @param terminal the Terminal to use for input/output
* @param properties Map of properties key/value pairs (usually from the command-line)
* @return the {@link Settings} and {@link Environment} as a {@link Tuple}
*/
public static Environment prepareEnvironment(Settings input, Terminal terminal, Map<String, String> properties) {
// 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());
// start with a fresh output
output = Settings.builder();
boolean settingsFileFound = false;
Set<String> foundSuffixes = new HashSet<>();
for (String allowedSuffix : ALLOWED_SUFFIXES) {
Path path = environment.configFile().resolve("elasticsearch" + allowedSuffix);
if (Files.exists(path)) {
if (!settingsFileFound) {
try {
output.loadFromPath(path);
} catch (IOException e) {
throw new SettingsException("Failed to load settings from " + path.toString(), e);
}
}
settingsFileFound = true;
foundSuffixes.add(allowedSuffix);
}
}
if (foundSuffixes.size() > 1) {
throw new SettingsException("multiple settings files found with suffixes: " + Strings.collectionToDelimitedString(foundSuffixes, ","));
}
// re-initialize settings now that the config file has been loaded
initializeSettings(output, input, properties);
finalizeSettings(output, terminal);
environment = new Environment(output.build());
// we put back the path.logs so we can use it in the logging configuration file
output.put(Environment.PATH_LOGS_SETTING.getKey(), cleanPath(environment.logsFile().toAbsolutePath().toString()));
return new Environment(output.build());
}
use of org.elasticsearch.env.Environment in project elasticsearch by elastic.
the class HunspellServiceTests method testLocaleDirectoryWithNodeLevelConfig.
public void testLocaleDirectoryWithNodeLevelConfig() throws Exception {
Settings settings = Settings.builder().put(Environment.PATH_CONF_SETTING.getKey(), getDataPath("/indices/analyze/conf_dir")).put(HUNSPELL_LAZY_LOAD.getKey(), randomBoolean()).put(HUNSPELL_IGNORE_CASE.getKey(), true).put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).build();
Dictionary dictionary = new HunspellService(settings, new Environment(settings), emptyMap()).getDictionary("en_US");
assertThat(dictionary, notNullValue());
assertTrue(dictionary.getIgnoreCase());
}
use of org.elasticsearch.env.Environment in project elasticsearch by elastic.
the class FileScriptTests method makeScriptService.
ScriptService makeScriptService(Settings settings) throws Exception {
Path homeDir = createTempDir();
Path scriptsDir = homeDir.resolve("config").resolve("scripts");
Files.createDirectories(scriptsDir);
Path mockscript = scriptsDir.resolve("script1.mockscript");
String scriptSource = "1";
Files.write(mockscript, scriptSource.getBytes("UTF-8"));
settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), homeDir).put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING.getKey(), false).put(settings).build();
MockScriptEngine scriptEngine = new MockScriptEngine(MockScriptEngine.NAME, Collections.singletonMap(scriptSource, script -> "1"));
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singleton(scriptEngine));
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(Collections.emptyList());
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
return new ScriptService(settings, new Environment(settings), null, scriptEngineRegistry, scriptContextRegistry, scriptSettings);
}
Aggregations