Skip to content

Commit

Permalink
Refactors some class names
Browse files Browse the repository at this point in the history
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
  • Loading branch information
DarshitChanpura committed Nov 13, 2023
1 parent 5866fb9 commit a7defce
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
/**
* This class creates demo certificate files
*/
public class CertificateGenerator extends InstallDemoConfiguration {
public class CertificateGenerator extends Installer {

/**
* Creates demo super-admin, node and root certificates
*/
public void createDemoCertificates() {
for (DemoCertificate cert : DemoCertificate.values()) {
for (Certificates cert : Certificates.values()) {
String filePath = OPENSEARCH_CONF_DIR + File.separator + cert.getFileName();
writeCertificateToFile(filePath, cert.getContent());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* Enum for demo certificates
*/
public enum DemoCertificate {
public enum Certificates {
ADMIN_CERT(
"kirk.pem",
"-----BEGIN CERTIFICATE-----\n"
Expand Down Expand Up @@ -159,7 +159,7 @@ public enum DemoCertificate {
private final String fileName;
private final String content;

DemoCertificate(String fileName, String content) {
Certificates(String fileName, String content) {
this.fileName = fileName;
this.content = content;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/**
* This class installs demo configuration for security plugin
*/
public class InstallDemoConfiguration {
public class Installer {

static boolean assumeyes = false;
static boolean initsecurity = false;
Expand Down Expand Up @@ -55,19 +55,19 @@ public class InstallDemoConfiguration {
+ ".opendistro-reports-*, .opensearch-notifications-*, .opensearch-notebooks, .opensearch-observability, .ql-datasources, "
+ ".opendistro-asynchronous-search-response*, .replication-metadata-store, .opensearch-knn-models, .geospatial-ip2geo-data*";

static SecurityConfigurator securityConfigurator;
static SecuritySettingsConfigurer securitySettingsConfigurer;
static CertificateGenerator certificateGenerator;

public static void main(String[] options) {
securityConfigurator = new SecurityConfigurator();
securitySettingsConfigurer = new SecuritySettingsConfigurer();
certificateGenerator = new CertificateGenerator();

printScriptHeaders();
readOptions(options);
gatherUserInputs();
initializeVariables();
printVariables();
securityConfigurator.configureSecurity();
securitySettingsConfigurer.configureSecuritySettings();
certificateGenerator.createDemoCertificates();
finishScriptExecution();
}
Expand Down Expand Up @@ -319,7 +319,7 @@ private static void finishScriptExecution() {
+ FILE_EXTENSION;
String securityAdminDemoScriptPath = OPENSEARCH_CONF_DIR + "securityadmin_demo" + FILE_EXTENSION;

securityConfigurator.createSecurityAdminDemoScript(securityAdminScriptPath, securityAdminDemoScriptPath);
securitySettingsConfigurer.createSecurityAdminDemoScript(securityAdminScriptPath, securityAdminDemoScriptPath);

// Make securityadmin_demo script executable
// not needed for windows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@
/**
* This class updates the security related configuration, as needed.
*/
public class SecurityConfigurator extends InstallDemoConfiguration {
public class SecuritySettingsConfigurer extends Installer {

/**
* Configures security related changes to the opensearch configuration
* 1. Checks if plugins is already configuration. If yes, exit
* 2. Sets the custom admin password (Generates one if none is provided)
* 3. Write the security config to opensearch.yml
*/
public void configureSecurity() {
public void configureSecuritySettings() {
checkIfSecurityPluginIsAlreadyConfigured();
setAdminPassword();
updateAdminPassword();
writeSecurityConfigToOpenSearchYML();
}

/**
* Replaces the admin password in internal_users.yml with the custom or generated password
*/
private static void setAdminPassword() {
private static void updateAdminPassword() {
String ADMIN_PASSWORD = "";
String initialAdminPassword = System.getenv("initialAdminPassword");
String ADMIN_PASSWORD_FILE_PATH = OPENSEARCH_CONF_DIR + "initialAdminPassword.txt";
Expand Down Expand Up @@ -291,13 +291,13 @@ void createSecurityAdminDemoScript(String securityAdminScriptPath, String securi
+ OPENSEARCH_CONF_DIR
+ "opensearch-security\" -icl -key \""
+ OPENSEARCH_CONF_DIR
+ DemoCertificate.ADMIN_CERT_KEY.getFileName()
+ Certificates.ADMIN_CERT_KEY.getFileName()
+ "\" -cert \""
+ OPENSEARCH_CONF_DIR
+ DemoCertificate.ADMIN_CERT.getFileName()
+ Certificates.ADMIN_CERT.getFileName()
+ "\" -cacert \""
+ OPENSEARCH_CONF_DIR
+ DemoCertificate.ROOT_CA.getFileName()
+ Certificates.ROOT_CA.getFileName()
+ "\" -nhnv";

if (OS.toLowerCase().contains("win")) {
Expand Down

0 comments on commit a7defce

Please sign in to comment.