From 2f6198196893b137ecc875adad3e59ec35b3e991 Mon Sep 17 00:00:00 2001 From: Justin Field Date: Thu, 6 Dec 2018 13:41:35 -0800 Subject: [PATCH] Add flag to skip loading props that don't exist when creating a new env (#127) --- gradle.properties | 2 +- .../cms/CreateCmsConfigOperation.java | 2 +- .../cms/UpdateCmsConfigOperation.java | 2 +- .../com/nike/cerberus/store/ConfigStore.java | 22 +++++++++++-------- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/gradle.properties b/gradle.properties index 55d595d6..aa28fd10 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,4 +16,4 @@ group=com.nike artifactId=cerberus-lifecycle-cli -version=4.6.3 +version=4.6.4 diff --git a/src/main/java/com/nike/cerberus/operation/cms/CreateCmsConfigOperation.java b/src/main/java/com/nike/cerberus/operation/cms/CreateCmsConfigOperation.java index 4bca8e3c..0881f826 100644 --- a/src/main/java/com/nike/cerberus/operation/cms/CreateCmsConfigOperation.java +++ b/src/main/java/com/nike/cerberus/operation/cms/CreateCmsConfigOperation.java @@ -44,7 +44,7 @@ public CreateCmsConfigOperation(final ConfigStore configStore) { @Override public void run(final CreateCmsConfigCommand command) { logger.info("Retrieving configuration data from the configuration bucket."); - final Properties cmsConfigProperties = configStore.getCmsSystemProperties(); + final Properties cmsConfigProperties = configStore.getCmsSystemProperties(false); cmsConfigProperties.put(CMS_ADMIN_GROUP_KEY, command.getAdminGroup()); diff --git a/src/main/java/com/nike/cerberus/operation/cms/UpdateCmsConfigOperation.java b/src/main/java/com/nike/cerberus/operation/cms/UpdateCmsConfigOperation.java index 2a2c6b7e..add18073 100644 --- a/src/main/java/com/nike/cerberus/operation/cms/UpdateCmsConfigOperation.java +++ b/src/main/java/com/nike/cerberus/operation/cms/UpdateCmsConfigOperation.java @@ -49,7 +49,7 @@ public void run(final UpdateCmsConfigCommand command) { logger.debug("Retrieving configuration data from the configuration bucket."); - final Properties newProperties = configStore.getCmsSystemProperties(); + final Properties newProperties = configStore.getCmsSystemProperties(true); final Properties existingCustomProperties = configStore.getExistingCmsUserProperties(); if (!command.getOverwrite()) { // keep existing custom properties diff --git a/src/main/java/com/nike/cerberus/store/ConfigStore.java b/src/main/java/com/nike/cerberus/store/ConfigStore.java index 61364200..072c1e1b 100644 --- a/src/main/java/com/nike/cerberus/store/ConfigStore.java +++ b/src/main/java/com/nike/cerberus/store/ConfigStore.java @@ -324,19 +324,23 @@ private Properties generateBaseCmsSystemProperties() { /** * System properties not set with -P param */ - public Properties getCmsSystemProperties() { + public Properties getCmsSystemProperties(boolean shouldLoadExistingProperties) { Properties properties = new Properties(); - Properties existingProperties = getAllExistingCmsEnvProperties(); - // overwrite any of the automatically generated properties that may have changed - existingProperties.putAll(generateBaseCmsSystemProperties()); + Properties existingProperties; + if (shouldLoadExistingProperties) { + existingProperties = getAllExistingCmsEnvProperties(); - existingProperties.forEach((key, value) -> { - if (SYSTEM_CONFIGURED_CMS_PROPERTIES.contains(key)) { - properties.put(key, value); - } - }); + existingProperties.forEach((key, value) -> { + if (SYSTEM_CONFIGURED_CMS_PROPERTIES.contains(key)) { + properties.put(key, value); + } + }); + } + + // overwrite any of the automatically generated properties that may have changed + properties.putAll(generateBaseCmsSystemProperties()); if (!properties.containsKey(HASH_SALT)) { properties.put(HASH_SALT, saltGenerator.generateSalt());