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 5ac9126b4b..31c37cfdff 100644 --- a/src/main/java/org/opensearch/security/tools/democonfig/Installer.java +++ b/src/main/java/org/opensearch/security/tools/democonfig/Installer.java @@ -35,6 +35,7 @@ */ public class Installer { + // Singleton Pattern private static Installer instance; private static SecuritySettingsConfigurer securitySettingsConfigurer; @@ -62,18 +63,27 @@ public class Installer { final String FILE_EXTENSION; - static File RPM_DEB_OPENSEARCH_HOME = new File("/usr/share/opensearch"); + static final File RPM_DEB_OPENSEARCH_HOME = new File("/usr/share/opensearch"); private final Options options; + // To print help information for this script private final HelpFormatter formatter = new HelpFormatter(); + /** + * We do not want this class to be instantiated more than once, + * as we are following Singleton Factory pattern + */ private Installer() { this.OS = System.getProperty("os.name") + " " + System.getProperty("os.version") + " " + System.getProperty("os.arch"); FILE_EXTENSION = OS.toLowerCase().contains("win") ? ".bat" : ".sh"; options = new Options(); } + /** + * Returns a singleton instance of this class + * @return an existing instance OR a new instance if there was no existing instance + */ public static Installer getInstance() { if (instance == null) { instance = new Installer(); @@ -83,6 +93,10 @@ public static Installer getInstance() { return instance; } + /** + * Installs the demo security configuration + * @param options the options passed to the script + */ public void installDemoConfiguration(String[] options) { readOptions(options); printScriptHeaders(); @@ -298,7 +312,7 @@ String determineInstallType() { // other OS (.sh execution) if (RPM_DEB_OPENSEARCH_HOME.exists() && RPM_DEB_OPENSEARCH_HOME.equals(new File(BASE_DIR))) { - OPENSEARCH_CONF_FILE = "/usr/share/opensearch/config/opensearch.yml"; + OPENSEARCH_CONF_FILE = RPM_DEB_OPENSEARCH_HOME.getAbsolutePath() + "/config/opensearch.yml"; if (!new File(OPENSEARCH_CONF_FILE).exists()) { OPENSEARCH_CONF_FILE = "/etc/opensearch/opensearch.yml"; } 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 b55b3ef0a1..2939824824 100644 --- a/src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java +++ b/src/main/java/org/opensearch/security/tools/democonfig/SecuritySettingsConfigurer.java @@ -343,6 +343,11 @@ void createSecurityAdminDemoScript(String securityAdminScriptPath, String securi writer.close(); } + /** + * Return the command to be added to securityadmin_demo script + * @param securityAdminScriptPath the path to securityadmin.(sh|bat) + * @return the command string + */ String[] getSecurityAdminCommands(String securityAdminScriptPath) { String securityAdminExecutionPath = securityAdminScriptPath + "\" -cd \""