diff --git a/src/main/java/org/opensearch/security/tools/democonfig/CertificateGenerator.java b/src/main/java/org/opensearch/security/tools/democonfig/CertificateGenerator.java index a08ead5483..bc18d3a62e 100644 --- a/src/main/java/org/opensearch/security/tools/democonfig/CertificateGenerator.java +++ b/src/main/java/org/opensearch/security/tools/democonfig/CertificateGenerator.java @@ -36,7 +36,7 @@ public void createDemoCertificates() { * @param filePath the file which needs to be written * @param content the content which needs to be written to this file */ - private static void writeCertificateToFile(String filePath, String content) { + static void writeCertificateToFile(String filePath, String content) { try { FileWriter fileWriter = new FileWriter(filePath, StandardCharsets.UTF_8); fileWriter.write(content); diff --git a/src/main/java/org/opensearch/security/tools/democonfig/Installer.java b/src/main/java/org/opensearch/security/tools/democonfig/Installer.java index 4c7c79a1e5..947d49e691 100644 --- a/src/main/java/org/opensearch/security/tools/democonfig/Installer.java +++ b/src/main/java/org/opensearch/security/tools/democonfig/Installer.java @@ -75,7 +75,7 @@ public static void main(String[] options) { /** * Prints deprecation warning and other headers for the script */ - private static void printScriptHeaders() { + static void printScriptHeaders() { System.out.println("**************************************************************************"); System.out.println("** This tool will be deprecated in the next major release of OpenSearch **"); System.out.println("** https://github.com/opensearch-project/security/issues/1755 **"); @@ -89,7 +89,7 @@ private static void printScriptHeaders() { * Reads the options passed to the script * @param options an array of strings containing options passed to the script */ - private static void readOptions(String[] options) { + static void readOptions(String[] options) { // set script execution dir SCRIPT_DIR = options[0]; @@ -123,7 +123,7 @@ private static void readOptions(String[] options) { /** * Prints the help menu when -h option is passed */ - private static void showHelp() { + static void showHelp() { System.out.println("install_demo_configuration.sh [-y] [-i] [-c]"); System.out.println(" -h show help"); System.out.println(" -y confirm all installation dialogues automatically"); @@ -140,7 +140,7 @@ private static void showHelp() { * Prompt the user and collect user inputs * Input collection will be skipped if -y option was passed */ - private static void gatherUserInputs() { + static void gatherUserInputs() { if (!assumeyes) { try (Scanner scanner = new Scanner(System.in, StandardCharsets.UTF_8)) { @@ -170,7 +170,7 @@ private static void gatherUserInputs() { * @param message prompt question * @return true or false based on user input */ - private static boolean confirmAction(Scanner scanner, String message) { + static boolean confirmAction(Scanner scanner, String message) { System.out.print(message + " [y/N] "); String response = scanner.nextLine(); return response.equalsIgnoreCase("yes") || response.equalsIgnoreCase("y"); @@ -179,7 +179,7 @@ private static boolean confirmAction(Scanner scanner, String message) { /** * Initialize all class level variables required */ - private static void initializeVariables() { + static void initializeVariables() { setBaseDir(); setOpenSearchVariables(); setSecurityVariables(); @@ -188,7 +188,7 @@ private static void initializeVariables() { /** * Sets the base directory to be used by the script */ - private static void setBaseDir() { + static void setBaseDir() { File baseDirFile = new File(SCRIPT_DIR).getParentFile().getParentFile().getParentFile(); BASE_DIR = baseDirFile != null ? baseDirFile.getAbsolutePath() : null; @@ -203,7 +203,7 @@ private static void setBaseDir() { /** * Sets the variables for items at OpenSearch level */ - private static void setOpenSearchVariables() { + static void setOpenSearchVariables() { OPENSEARCH_CONF_FILE = BASE_DIR + "config" + File.separator + "opensearch.yml"; OPENSEARCH_BIN_DIR = BASE_DIR + "bin" + File.separator; OPENSEARCH_PLUGINS_DIR = BASE_DIR + "plugins" + File.separator; @@ -244,7 +244,7 @@ private static void setOpenSearchVariables() { * Returns the installation type based on the underlying operating system * @return will be one of `.zip`, `.tar.gz` or `rpm/deb` */ - private static String determineInstallType() { + static String determineInstallType() { // windows (.bat execution) if (OS.toLowerCase().contains("win")) { return ".zip"; @@ -264,7 +264,7 @@ private static String determineInstallType() { /** * Sets the path variables for items at OpenSearch security plugin level */ - private static void setSecurityVariables() { + static void setSecurityVariables() { if (!(new File(OPENSEARCH_PLUGINS_DIR + "opensearch-security").exists())) { System.out.println("OpenSearch Security plugin not installed. Quit."); System.exit(-1); @@ -291,7 +291,7 @@ private static void setSecurityVariables() { /** * Prints the initialized variables */ - private static void printVariables() { + static void printVariables() { System.out.println("OpenSearch install type: " + OPENSEARCH_INSTALL_TYPE + " on " + OS); System.out.println("OpenSearch config dir: " + OPENSEARCH_CONF_DIR); System.out.println("OpenSearch config file: " + OPENSEARCH_CONF_FILE); @@ -305,7 +305,7 @@ private static void printVariables() { /** * Prints end of script execution message and creates security admin demo file. */ - private static void finishScriptExecution() { + static void finishScriptExecution() { System.out.println("### Success"); System.out.println("### Execute this script now on all your nodes and then start all nodes"); diff --git a/src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java b/src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java index d7367925e5..17c2a34091 100644 --- a/src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java +++ b/src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java @@ -51,7 +51,7 @@ public void configureSecuritySettings() { /** * Replaces the admin password in internal_users.yml with the custom or generated password */ - private static void updateAdminPassword() { + static void updateAdminPassword() { String ADMIN_PASSWORD = ""; String initialAdminPassword = System.getenv("initialAdminPassword"); String ADMIN_PASSWORD_FILE_PATH = OPENSEARCH_CONF_DIR + "initialAdminPassword.txt"; @@ -114,7 +114,7 @@ private static void updateAdminPassword() { * @param internalUsersFile the file path string to internal_users.yml file * @throws IOException while reading, writing to files */ - private static void writePasswordToInternalUsersFile(String adminPassword, String internalUsersFile) throws IOException { + static void writePasswordToInternalUsersFile(String adminPassword, String internalUsersFile) throws IOException { String hashedAdminPassword = Hasher.hash(adminPassword.toCharArray()); if (hashedAdminPassword.isEmpty()) { @@ -148,7 +148,7 @@ private static void writePasswordToInternalUsersFile(String adminPassword, Strin /** * Checks if security plugin is already configured. If so, the script execution will not continue. */ - private static void checkIfSecurityPluginIsAlreadyConfigured() { + static void checkIfSecurityPluginIsAlreadyConfigured() { // Check if the configuration file contains the 'plugins.security' string if (OPENSEARCH_CONF_FILE != null && new File(OPENSEARCH_CONF_FILE).exists()) { try (BufferedReader br = new BufferedReader(new FileReader(OPENSEARCH_CONF_FILE, StandardCharsets.UTF_8))) { @@ -172,7 +172,7 @@ private static void checkIfSecurityPluginIsAlreadyConfigured() { /** * Update opensearch.yml with security configuration information */ - private static void writeSecurityConfigToOpenSearchYML() { + static void writeSecurityConfigToOpenSearchYML() { String securityConfig = buildSecurityConfigString(); try (FileWriter writer = new FileWriter(OPENSEARCH_CONF_FILE, StandardCharsets.UTF_8, true)) { @@ -187,7 +187,7 @@ private static void writeSecurityConfigToOpenSearchYML() { * Helper method to build security configuration to append to opensearch.yml * @return the configuration string to be written to opensearch.yml */ - private static String buildSecurityConfigString() { + static String buildSecurityConfigString() { StringBuilder securityConfigLines = new StringBuilder(); securityConfigLines.append("\n") @@ -235,7 +235,7 @@ private static String buildSecurityConfigString() { * @param filePath path to opensearch.yml * @return true is present, false otherwise */ - private static boolean isNetworkHostAlreadyPresent(String filePath) { + static boolean isNetworkHostAlreadyPresent(String filePath) { try { String searchString = "^network.host"; return isStringAlreadyPresentInFile(filePath, searchString); @@ -249,7 +249,7 @@ private static boolean isNetworkHostAlreadyPresent(String filePath) { * @param filePath path to opensearch.yml * @return true if present, false otherwise */ - private static boolean isNodeMaxLocalStorageNodesAlreadyPresent(String filePath) { + static boolean isNodeMaxLocalStorageNodesAlreadyPresent(String filePath) { try { String searchString = "^node.max_local_storage_nodes"; return isStringAlreadyPresentInFile(filePath, searchString); @@ -265,7 +265,7 @@ private static boolean isNodeMaxLocalStorageNodesAlreadyPresent(String filePath) * @return true if string is present, false otherwise * @throws IOException if there was exception reading the file */ - private static boolean isStringAlreadyPresentInFile(String filePath, String searchString) throws IOException { + static boolean isStringAlreadyPresentInFile(String filePath, String searchString) throws IOException { try (BufferedReader reader = new BufferedReader(new FileReader(filePath, StandardCharsets.UTF_8))) { String line; while ((line = reader.readLine()) != null) {