Skip to content

Commit

Permalink
Temp commit
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura committed Nov 22, 2023
1 parent 5354951 commit c643093
Show file tree
Hide file tree
Showing 3 changed files with 274 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,23 +205,28 @@ static void setOpenSearchVariables() {
OPENSEARCH_LIB_PATH = BASE_DIR + "lib" + File.separator;
OPENSEARCH_INSTALL_TYPE = determineInstallType();

boolean shouldExit = false;
if (!(new File(OPENSEARCH_CONF_FILE).exists())) {
System.out.println("Unable to determine OpenSearch config directory. Quit.");
System.exit(-1);
System.out.println("Unable to determine OpenSearch config file. Quit.");
shouldExit = true;
}

if (!(new File(OPENSEARCH_BIN_DIR).exists())) {
System.out.println("Unable to determine OpenSearch bin directory. Quit.");
System.exit(-1);
shouldExit = true;
}

if (!(new File(OPENSEARCH_PLUGINS_DIR).exists())) {
System.out.println("Unable to determine OpenSearch plugins directory. Quit.");
System.exit(-1);
shouldExit = true;
}

if (!(new File(OPENSEARCH_LIB_PATH).exists())) {
System.out.println("Unable to determine OpenSearch lib directory. Quit.");
shouldExit = true;
}

if (shouldExit) {
System.exit(-1);
}

Expand All @@ -240,7 +245,8 @@ static String determineInstallType() {
}

// other OS (.sh execution)
if (new File("/usr/share/opensearch").equals(new File(BASE_DIR))) {
File opensearch = new File("/usr/share/opensearch");
if (opensearch.exists() && opensearch.equals(new File(BASE_DIR))) {
OPENSEARCH_CONF_FILE = "/usr/share/opensearch/config/opensearch.yml";
if (!new File(OPENSEARCH_CONF_FILE).exists()) {
OPENSEARCH_CONF_FILE = "/etc/opensearch/opensearch.yml";
Expand Down Expand Up @@ -363,4 +369,26 @@ static void finishScriptExecution() {
System.out.println(e.getMessage());
}
}

/**
* FOR TESTS ONLY
* Resets the class-level variables to their original values
* Is needed for tests since the variables are declared static
*/
static void resetState() {
assumeyes = false;
initsecurity = false;
cluster_mode = false;
environment = ExecutionEnvironment.DEMO;
SCRIPT_DIR = null;
BASE_DIR = null;
OPENSEARCH_CONF_FILE = null;
OPENSEARCH_BIN_DIR = null;
OPENSEARCH_PLUGINS_DIR = null;
OPENSEARCH_LIB_PATH = null;
OPENSEARCH_INSTALL_TYPE = null;
OPENSEARCH_CONF_DIR = null;
OPENSEARCH_VERSION = null;
SECURITY_VERSION = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,16 @@ static String buildSecurityConfigString() {
StringBuilder securityConfigLines = new StringBuilder();

securityConfigLines.append("\n")
.append("######## Start OpenSearch Security Demo Configuration ########\n")
.append("# WARNING: revise all the lines below before you go into production\n")
.append("plugins.security.ssl.transport.pemcert_filepath: esnode.pem\n")
.append("plugins.security.ssl.transport.pemkey_filepath: esnode-key.pem\n")
.append("plugins.security.ssl.transport.pemtrustedcas_filepath: root-ca.pem\n")
.append("######## Start OpenSearch Security Demo Configuration ########\n")
.append("# WARNING: revise all the lines below before you go into production\n")
.append("plugins.security.ssl.transport.pemcert_filepath: ").append(Certificates.NODE_CERT.getFileName()).append("\n")
.append("plugins.security.ssl.transport.pemkey_filepath: ").append(Certificates.NODE_KEY.getFileName()).append("\n")
.append("plugins.security.ssl.transport.pemtrustedcas_filepath: ").append(Certificates.ROOT_CA.getFileName()).append("\n")
.append("plugins.security.ssl.transport.enforce_hostname_verification: false\n")
.append("plugins.security.ssl.http.enabled: true\n")
.append("plugins.security.ssl.http.pemcert_filepath: esnode.pem\n")
.append("plugins.security.ssl.http.pemkey_filepath: esnode-key.pem\n")
.append("plugins.security.ssl.http.pemtrustedcas_filepath: root-ca.pem\n")
.append("plugins.security.ssl.http.pemcert_filepath: ").append(Certificates.NODE_CERT.getFileName()).append("\n")
.append("plugins.security.ssl.http.pemkey_filepath: ").append(Certificates.NODE_KEY.getFileName()).append("\n")
.append("plugins.security.ssl.http.pemtrustedcas_filepath: ").append(Certificates.ROOT_CA.getFileName()).append("\n")
.append("plugins.security.allow_unsafe_democertificates: true\n");

if (initsecurity) {
Expand Down
Loading

0 comments on commit c643093

Please sign in to comment.