Skip to content

Commit

Permalink
Removes 'this' reference to Installer
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <[email protected]>
  • Loading branch information
DarshitChanpura committed Dec 8, 2023
1 parent 8926ce4 commit d4dbac3
Showing 1 changed file with 17 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,9 @@ public void configureSecuritySettings() {
*/
void updateAdminPassword() {
String initialAdminPassword = System.getenv().get("initialAdminPassword");
String ADMIN_PASSWORD_FILE_PATH = this.installer.OPENSEARCH_CONF_DIR + "initialAdminPassword.txt";
String INTERNAL_USERS_FILE_PATH = this.installer.OPENSEARCH_CONF_DIR
+ "opensearch-security"
+ File.separator
+ "internal_users.yml";
boolean shouldValidatePassword = this.installer.environment.equals(ExecutionEnvironment.DEMO);
String ADMIN_PASSWORD_FILE_PATH = installer.OPENSEARCH_CONF_DIR + "initialAdminPassword.txt";
String INTERNAL_USERS_FILE_PATH = installer.OPENSEARCH_CONF_DIR + "opensearch-security" + File.separator + "internal_users.yml";
boolean shouldValidatePassword = installer.environment.equals(ExecutionEnvironment.DEMO);
try {
final PasswordValidator passwordValidator = PasswordValidator.of(
Settings.builder()
Expand Down Expand Up @@ -189,13 +186,13 @@ void writePasswordToInternalUsersFile(String adminPassword, String internalUsers
*/
void checkIfSecurityPluginIsAlreadyConfigured() {
// Check if the configuration file contains the 'plugins.security' string
if (this.installer.OPENSEARCH_CONF_FILE != null && new File(this.installer.OPENSEARCH_CONF_FILE).exists()) {
try (BufferedReader br = new BufferedReader(new FileReader(this.installer.OPENSEARCH_CONF_FILE, StandardCharsets.UTF_8))) {
if (installer.OPENSEARCH_CONF_FILE != null && new File(installer.OPENSEARCH_CONF_FILE).exists()) {
try (BufferedReader br = new BufferedReader(new FileReader(installer.OPENSEARCH_CONF_FILE, StandardCharsets.UTF_8))) {
String line;
while ((line = br.readLine()) != null) {
if (line.toLowerCase().contains("plugins.security")) {
System.out.println(this.installer.OPENSEARCH_CONF_FILE + " seems to be already configured for Security. Quit.");
System.exit(this.installer.skip_updates);
System.out.println(installer.OPENSEARCH_CONF_FILE + " seems to be already configured for Security. Quit.");
System.exit(installer.skip_updates);
}
}
} catch (IOException e) {
Expand All @@ -222,7 +219,7 @@ void writeSecurityConfigToOpenSearchYML() {

Map<String, Object> securityConfigAsMap = buildSecurityConfigMap();

try (FileWriter writer = new FileWriter(this.installer.OPENSEARCH_CONF_FILE, StandardCharsets.UTF_8, true)) {
try (FileWriter writer = new FileWriter(installer.OPENSEARCH_CONF_FILE, StandardCharsets.UTF_8, true)) {
writer.write(configHeader);
Yaml yaml = new Yaml();
DumperOptions options = new DumperOptions();
Expand Down Expand Up @@ -253,7 +250,7 @@ Map<String, Object> buildSecurityConfigMap() {
configMap.put("plugins.security.ssl.http.pemtrustedcas_filepath", Certificates.ROOT_CA.getFileName());
configMap.put("plugins.security.allow_unsafe_democertificates", true);

if (this.installer.initsecurity) {
if (installer.initsecurity) {
configMap.put("plugins.security.allow_default_init_securityindex", true);
}

Expand All @@ -267,15 +264,15 @@ Map<String, Object> buildSecurityConfigMap() {
configMap.put("plugins.security.system_indices.enabled", true);
configMap.put("plugins.security.system_indices.indices", SYSTEM_INDICES);

if (!isNetworkHostAlreadyPresent(this.installer.OPENSEARCH_CONF_FILE)) {
if (this.installer.cluster_mode) {
if (!isNetworkHostAlreadyPresent(installer.OPENSEARCH_CONF_FILE)) {
if (installer.cluster_mode) {
configMap.put("network.host", "0.0.0.0");
configMap.put("node.name", "smoketestnode");
configMap.put("cluster.initial_cluster_manager_nodes", "smoketestnode");
}
}

if (!isNodeMaxLocalStorageNodesAlreadyPresent(this.installer.OPENSEARCH_CONF_FILE)) {
if (!isNodeMaxLocalStorageNodesAlreadyPresent(installer.OPENSEARCH_CONF_FILE)) {
configMap.put("node.max_local_storage_nodes", 3);
}

Expand Down Expand Up @@ -349,19 +346,19 @@ void createSecurityAdminDemoScript(String securityAdminScriptPath, String securi
String[] getSecurityAdminCommands(String securityAdminScriptPath) {
String securityAdminExecutionPath = securityAdminScriptPath
+ "\" -cd \""
+ this.installer.OPENSEARCH_CONF_DIR
+ installer.OPENSEARCH_CONF_DIR
+ "opensearch-security\" -icl -key \""
+ this.installer.OPENSEARCH_CONF_DIR
+ installer.OPENSEARCH_CONF_DIR
+ Certificates.ADMIN_CERT_KEY.getFileName()
+ "\" -cert \""
+ this.installer.OPENSEARCH_CONF_DIR
+ installer.OPENSEARCH_CONF_DIR
+ Certificates.ADMIN_CERT.getFileName()
+ "\" -cacert \""
+ this.installer.OPENSEARCH_CONF_DIR
+ installer.OPENSEARCH_CONF_DIR
+ Certificates.ROOT_CA.getFileName()
+ "\" -nhnv";

if (this.installer.OS.toLowerCase().contains("win")) {
if (installer.OS.toLowerCase().contains("win")) {
return new String[] { "@echo off", "call \"" + securityAdminExecutionPath };
}

Expand Down

0 comments on commit d4dbac3

Please sign in to comment.