public static String resolve(String originalPath, String propName, Settings settings, Path configPath, boolean mustBeValid) { log.debug("Path is is {}", originalPath); String path = originalPath; final Environment env = new Environment(settings, configPath); if(env != null && originalPath != null && originalPath.length() > 0) { path = env.configFile().resolve(originalPath).toAbsolutePath().toString(); log.debug("Resolved {} to {} against {}", originalPath, path, env.configFile().toAbsolutePath().toString()); } if(mustBeValid) { checkPath(path, propName); } if("".equals(path)) { path = null; } return path; }
@Override public List<String> run() { final Path confPath = new Environment(settings, configPath).configFile().toAbsolutePath(); if(Files.isDirectory(confPath, LinkOption.NOFOLLOW_LINKS)) { try (Stream<Path> s = Files.walk(confPath)) { return s .distinct() .map(p->sha256(p)) .collect(Collectors.toList()); } catch (Exception e) { log.error(e); return null; } } return Collections.emptyList(); } });
@Override public List<Path> run() { final Path confPath = new Environment(settings, configPath).configFile().toAbsolutePath(); if(Files.isDirectory(confPath, LinkOption.NOFOLLOW_LINKS)) { try (Stream<Path> s = Files.walk(confPath)) { return s .distinct() .filter(p->checkFilePermissions(p)) .collect(Collectors.toList()); } catch (Exception e) { log.error(e); return null; } } return Collections.emptyList(); } });
private Dictionary(Configuration cfg) { this.configuration = cfg; this.props = new Properties(); this.conf_dir = cfg.getEnvironment().configFile().resolve(AnalysisIkPlugin.PLUGIN_NAME); Path configFile = conf_dir.resolve(FILE_NAME); InputStream input = null; try { logger.info("try load config from {}", configFile); input = new FileInputStream(configFile.toFile()); } catch (FileNotFoundException e) { conf_dir = cfg.getConfigInPluginDir(); configFile = conf_dir.resolve(FILE_NAME); try { logger.info("try load config from {}", configFile); input = new FileInputStream(configFile.toFile()); } catch (FileNotFoundException ex) { // We should report origin exception logger.error("ik-analyzer", e); } } if (input != null) { try { props.loadFromXML(input); } catch (InvalidPropertiesFormatException e) { logger.error("ik-analyzer", e); } catch (IOException e) { logger.error("ik-analyzer", e); } } }
private Path resolveHunspellDirectory(Environment env) { return env.configFile().resolve("hunspell"); }
/** * @return null If no settings set for "settingsPrefix" then return <code>null</code>. * @throws IllegalArgumentException * If the Reader can not be instantiated. */ public static Reader getReaderFromFile(Environment env, Settings settings, String settingPrefix) { String filePath = settings.get(settingPrefix, null); if (filePath == null) { return null; } final Path path = env.configFile().resolve(filePath); try { return Files.newBufferedReader(path, StandardCharsets.UTF_8); } catch (CharacterCodingException ex) { String message = String.format(Locale.ROOT, "Unsupported character encoding detected while reading %s_path: %s files must be UTF-8 encoded", settingPrefix, path.toString()); throw new IllegalArgumentException(message, ex); } catch (IOException ioe) { String message = String.format(Locale.ROOT, "IOException while reading %s_path: %s", settingPrefix, path.toString()); throw new IllegalArgumentException(message, ioe); } }
/** * Fetches a list of words from the specified settings file. The list should either be available at the key * specified by <code>settingList</code> or in a file specified by <code>settingPath</code>. * * @throws IllegalArgumentException * If the word list cannot be found at either key. */ public static List<String> getWordList(Environment env, Settings settings, String settingPath, String settingList) { String wordListPath = settings.get(settingPath, null); if (wordListPath == null) { List<String> explicitWordList = settings.getAsList(settingList, null); if (explicitWordList == null) { return null; } else { return explicitWordList; } } final Path path = env.configFile().resolve(wordListPath); try (BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) { return loadWordList(reader, "#"); } catch (CharacterCodingException ex) { String message = String.format(Locale.ROOT, "Unsupported character encoding detected while reading %s: %s - files must be UTF-8 encoded", settingPath, path.toString()); throw new IllegalArgumentException(message, ex); } catch (IOException ioe) { String message = String.format(Locale.ROOT, "IOException while reading %s: %s", settingPath, path.toString()); throw new IllegalArgumentException(message, ioe); } }
@Override protected void execute(Terminal terminal, OptionSet options, Environment env) throws Exception { Path keystoreFile = KeyStoreWrapper.keystorePath(env.configFile()); if (Files.exists(keystoreFile)) { if (terminal.promptYesNo("An elasticsearch keystore already exists. Overwrite?", false) == false) { terminal.println("Exiting without creating keystore."); return; } } char[] password = new char[0];// terminal.readSecret("Enter passphrase (empty for no passphrase): "); /* TODO: uncomment when entering passwords on startup is supported char[] passwordRepeat = terminal.readSecret("Enter same passphrase again: "); if (Arrays.equals(password, passwordRepeat) == false) { throw new UserException(ExitCodes.DATA_ERROR, "Passphrases are not equal, exiting."); }*/ KeyStoreWrapper keystore = KeyStoreWrapper.create(); keystore.save(env.configFile(), password); terminal.println("Created elasticsearch keystore in " + env.configFile()); } }
static SecureSettings loadSecureSettings(Environment initialEnv) throws BootstrapException { final KeyStoreWrapper keystore; try { keystore = KeyStoreWrapper.load(initialEnv.configFile()); } catch (IOException e) { throw new BootstrapException(e); } try { if (keystore == null) { final KeyStoreWrapper keyStoreWrapper = KeyStoreWrapper.create(); keyStoreWrapper.save(initialEnv.configFile(), new char[0]); return keyStoreWrapper; } else { keystore.decrypt(new char[0] /* TODO: read password from stdin */); KeyStoreWrapper.upgrade(keystore, initialEnv.configFile(), new char[0]); } } catch (Exception e) { throw new BootstrapException(e); } return keystore; }
@Override protected void execute(Terminal terminal, OptionSet options, Environment env) throws Exception { KeyStoreWrapper keystore = KeyStoreWrapper.load(env.configFile()); if (keystore == null) { throw new UserException(ExitCodes.DATA_ERROR, "Elasticsearch keystore not found. Use 'create' command to create one."); } keystore.decrypt(new char[0] /* TODO: prompt for password when they are supported */); List<String> sortedEntries = new ArrayList<>(keystore.getSettingNames()); Collections.sort(sortedEntries); for (String entry : sortedEntries) { terminal.println(entry); } } }
@Override protected void execute(Terminal terminal, OptionSet options, Environment env) throws Exception { KeyStoreWrapper keystore = KeyStoreWrapper.load(env.configFile()); if (keystore == null) { if (options.has(forceOption) == false && keystore.save(env.configFile(), new char[0] /* always use empty passphrase for auto created keystore */); terminal.println("Created elasticsearch keystore in " + env.configFile()); } else { keystore.decrypt(new char[0] /* TODO: prompt for password when they are supported */); keystore.save(env.configFile(), new char[0]);
@Override protected void execute(Terminal terminal, OptionSet options, Environment env) throws Exception { List<String> settings = arguments.values(options); if (settings.isEmpty()) { throw new UserException(ExitCodes.USAGE, "Must supply at least one setting to remove"); } KeyStoreWrapper keystore = KeyStoreWrapper.load(env.configFile()); if (keystore == null) { throw new UserException(ExitCodes.DATA_ERROR, "Elasticsearch keystore not found. Use 'create' command to create one."); } keystore.decrypt(new char[0] /* TODO: prompt for password when they are supported */); for (String setting : arguments.values(options)) { if (keystore.getSettingNames().contains(setting) == false) { throw new UserException(ExitCodes.CONFIG, "Setting [" + setting + "] does not exist in the keystore."); } keystore.remove(setting); } keystore.save(env.configFile(), new char[0]); } }
Environment environment = new Environment(output.build(), configPath); if (Files.exists(environment.configFile().resolve("elasticsearch.yaml"))) { throw new SettingsException("elasticsearch.yaml was deprecated in 5.5.0 and must be renamed to elasticsearch.yml"); if (Files.exists(environment.configFile().resolve("elasticsearch.json"))) { throw new SettingsException("elasticsearch.json was deprecated in 5.5.0 and must be converted to elasticsearch.yml"); Path path = environment.configFile().resolve("elasticsearch.yml"); if (Files.exists(path)) { try {
@Override protected NodesReloadSecureSettingsResponse.NodeResponse nodeOperation(NodeRequest nodeReloadRequest) { try (KeyStoreWrapper keystore = KeyStoreWrapper.load(environment.configFile())) {
/** * Configure logging reading from any log4j2.properties found in the config directory and its * subdirectories from the specified environment. Will also configure logging to point the logs * directory from the specified environment. * * @param environment the environment for reading configs and the logs path * @throws IOException if there is an issue readings any log4j2.properties in the config * directory * @throws UserException if there are no log4j2.properties in the specified configs path */ public static void configure(final Environment environment) throws IOException, UserException { Objects.requireNonNull(environment); try { // we are about to configure logging, check that the status logger did not log any error-level messages checkErrorListener(); } finally { // whether or not the error listener check failed we can remove the listener now StatusLogger.getLogger().removeListener(ERROR_LISTENER); } configure(environment.settings(), environment.configFile(), environment.logsFile()); }
@Override protected void execute(Terminal terminal, OptionSet options, Environment env) throws Exception { KeyStoreWrapper keystore = KeyStoreWrapper.load(env.configFile()); if (keystore == null) { if (options.has(forceOption) == false && keystore.save(env.configFile(), new char[0] /* always use empty passphrase for auto created keystore */); terminal.println("Created elasticsearch keystore in " + env.configFile()); } else { keystore.decrypt(new char[0] /* TODO: prompt for password when they are supported */); throw new UserException(ExitCodes.DATA_ERROR, "String value must contain only ASCII"); keystore.save(env.configFile(), new char[0]);
final Environment environment = createEnvironment(foreground, pidFile, keystore, initialEnv.settings(), initialEnv.configFile());
environment.configFile(), Arrays.toString(environment.dataFiles()), environment.logsFile(), environment.pluginsFile()); this.pluginsService = new PluginsService(tmpSettings, environment.configFile(), environment.modulesFile(), environment.pluginsFile(), classpathPlugins); this.settings = pluginsService.updatedSettings(); localNodeFactory = new LocalNodeFactory(settings, nodeEnvironment.nodeId()); this.environment = new Environment(this.settings, environment.configFile()); Environment.assertEquivalent(environment, this.environment); networkService, clusterService.getMasterService(), clusterService.getClusterApplierService(), clusterService.getClusterSettings(), pluginsService.filterPlugins(DiscoveryPlugin.class), clusterModule.getAllocationService(), environment.configFile()); this.nodeService = new NodeService(settings, threadPool, monitorService, discoveryModule.getDiscovery(), transportService, indicesService, pluginsService, circuitBreakerService, scriptModule.getScriptService(),
addDirectoryPath(policy, Environment.PATH_HOME_SETTING.getKey(), environment.modulesFile(), "read,readlink"); addDirectoryPath(policy, Environment.PATH_HOME_SETTING.getKey(), environment.pluginsFile(), "read,readlink"); addDirectoryPath(policy, "path.conf'", environment.configFile(), "read,readlink");
/** * asserts that the two environments are equivalent for all things the environment cares about (i.e., all but the setting * object which may contain different setting) */ public static void assertEquivalent(Environment actual, Environment expected) { assertEquals(actual.dataFiles(), expected.dataFiles(), "dataFiles"); assertEquals(actual.repoFiles(), expected.repoFiles(), "repoFiles"); assertEquals(actual.configFile(), expected.configFile(), "configFile"); assertEquals(actual.pluginsFile(), expected.pluginsFile(), "pluginsFile"); assertEquals(actual.binFile(), expected.binFile(), "binFile"); assertEquals(actual.libFile(), expected.libFile(), "libFile"); assertEquals(actual.modulesFile(), expected.modulesFile(), "modulesFile"); assertEquals(actual.logsFile(), expected.logsFile(), "logsFile"); assertEquals(actual.pidFile(), expected.pidFile(), "pidFile"); assertEquals(actual.tmpFile(), expected.tmpFile(), "tmpFile"); }