X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Fclamp%2Fclds%2Fconfig%2Fsdc%2FSdcSingleControllerConfiguration.java;h=2afc3d91b45814765b0f3380c77cfaf47dfa5954;hb=2c468da869bdcb8bde16758aff061fb58ac48730;hp=c97beb08d22eb2ea3576afa526087ee35346af24;hpb=56e71d901f858fd960d72d0e71d06d4de5953900;p=clamp.git diff --git a/src/main/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfiguration.java b/src/main/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfiguration.java index c97beb08..2afc3d91 100644 --- a/src/main/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfiguration.java +++ b/src/main/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfiguration.java @@ -18,7 +18,7 @@ * limitations under the License. * ============LICENSE_END============================================ * =================================================================== - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * */ package org.onap.clamp.clds.config.sdc; @@ -28,6 +28,7 @@ import com.att.eelf.configuration.EELFManager; import com.fasterxml.jackson.databind.JsonNode; import java.security.GeneralSecurityException; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -35,7 +36,7 @@ import java.util.List; import org.apache.commons.codec.DecoderException; import org.onap.clamp.clds.exception.sdc.controller.SdcParametersException; import org.onap.clamp.clds.util.CryptoUtils; -import org.openecomp.sdc.api.consumer.IConfiguration; +import org.onap.sdc.api.consumer.IConfiguration; /** * This class maps the SDC config JSON for one controller. @@ -56,15 +57,16 @@ public class SdcSingleControllerConfiguration implements IConfiguration { public static final String CONSUMER_GROUP_ATTRIBUTE_NAME = "consumerGroup"; public static final String CONSUMER_ID_ATTRIBUTE_NAME = "consumerId"; public static final String ENVIRONMENT_NAME_ATTRIBUTE_NAME = "environmentName"; - public static final String PASSWORD_ATTRIBUTE_NAME = "password"; + public static final String SDC_KEY_ATTRIBUTE_NAME = "password"; public static final String POLLING_INTERVAL_ATTRIBUTE_NAME = "pollingInterval"; public static final String RELEVANT_ARTIFACT_TYPES_ATTRIBUTE_NAME = "relevantArtifactTypes"; public static final String USER_ATTRIBUTE_NAME = "user"; public static final String SDC_ADDRESS_ATTRIBUTE_NAME = "sdcAddress"; public static final String POLLING_TIMEOUT_ATTRIBUTE_NAME = "pollingTimeout"; public static final String ACTIVATE_SERVER_TLS_AUTH = "activateServerTLSAuth"; - public static final String KEY_STORE_PASSWORD = "keyStorePassword"; + public static final String KEY_STORE_KEY = "keyStorePassword"; public static final String KEY_STORE_PATH = "keyStorePath"; + public static final String MESSAGE_BUS_ADDRESSES = "messageBusAddresses"; private String errorMessageKeyNotFound; /** * Supported artifact types. @@ -109,6 +111,30 @@ public class SdcSingleControllerConfiguration implements IConfiguration { testAllRequiredParameters(); } + private String getStringConfig(String key) { + if (jsonRootNode != null && jsonRootNode.get(key) != null) { + String config = jsonRootNode.get(key).asText(); + return config.isEmpty() ? null : config; + } + return null; + } + + private Integer getIntConfig(String key) { + if (jsonRootNode != null && jsonRootNode.get(key) != null) { + return jsonRootNode.get(key).asInt(); + } else { + return 0; + } + } + + private String getEncryptedStringConfig(String key) throws GeneralSecurityException, DecoderException { + if (jsonRootNode != null && jsonRootNode.get(key) != null) { + return jsonRootNode.get(key).asText().isEmpty() ? null + : CryptoUtils.decrypt(jsonRootNode.get(key).asText()); + } + return null; + } + @Override public java.lang.Boolean isUseHttpsWithDmaap() { return false; @@ -125,42 +151,27 @@ public class SdcSingleControllerConfiguration implements IConfiguration { @Override public String getConsumerID() { - if (jsonRootNode != null && jsonRootNode.get(CONSUMER_ID_ATTRIBUTE_NAME) != null) { - String config = jsonRootNode.get(CONSUMER_ID_ATTRIBUTE_NAME).asText(); - return config.isEmpty() ? null : config; - } - return null; + return getStringConfig(CONSUMER_ID_ATTRIBUTE_NAME); } @Override public String getEnvironmentName() { - if (jsonRootNode != null && jsonRootNode.get(ENVIRONMENT_NAME_ATTRIBUTE_NAME) != null) { - String config = jsonRootNode.get(ENVIRONMENT_NAME_ATTRIBUTE_NAME).asText(); - return config.isEmpty() ? null : config; - } - return null; + return getStringConfig(ENVIRONMENT_NAME_ATTRIBUTE_NAME); } @Override public String getPassword() { try { - if (jsonRootNode != null && jsonRootNode.get(PASSWORD_ATTRIBUTE_NAME) != null) { - String config = CryptoUtils.decrypt(jsonRootNode.get(PASSWORD_ATTRIBUTE_NAME).asText()); - return config.isEmpty() ? null : config; - } + return getEncryptedStringConfig(SDC_KEY_ATTRIBUTE_NAME); } catch (GeneralSecurityException | DecoderException e) { logger.error("Unable to decrypt the SDC password", e); + return null; } - return null; } @Override public int getPollingInterval() { - if (jsonRootNode != null && jsonRootNode.get(POLLING_INTERVAL_ATTRIBUTE_NAME) != null) { - return jsonRootNode.get(POLLING_INTERVAL_ATTRIBUTE_NAME).asInt(); - } else { - return 0; - } + return getIntConfig(POLLING_INTERVAL_ATTRIBUTE_NAME); } @Override @@ -172,29 +183,17 @@ public class SdcSingleControllerConfiguration implements IConfiguration { @Override public String getUser() { - if (jsonRootNode != null && jsonRootNode.get(USER_ATTRIBUTE_NAME) != null) { - String config = jsonRootNode.get(USER_ATTRIBUTE_NAME).asText(); - return config.isEmpty() ? null : config; - } - return null; + return getStringConfig(USER_ATTRIBUTE_NAME); } @Override public String getAsdcAddress() { - if (jsonRootNode != null && jsonRootNode.get(SDC_ADDRESS_ATTRIBUTE_NAME) != null) { - String config = jsonRootNode.get(SDC_ADDRESS_ATTRIBUTE_NAME).asText(); - return config.isEmpty() ? null : config; - } - return null; + return getStringConfig(SDC_ADDRESS_ATTRIBUTE_NAME); } @Override public int getPollingTimeout() { - if (jsonRootNode != null && jsonRootNode.get(POLLING_TIMEOUT_ATTRIBUTE_NAME) != null) { - return jsonRootNode.get(POLLING_TIMEOUT_ATTRIBUTE_NAME).asInt(); - } else { - return 0; - } + return getIntConfig(POLLING_TIMEOUT_ATTRIBUTE_NAME); } @Override @@ -209,23 +208,16 @@ public class SdcSingleControllerConfiguration implements IConfiguration { @Override public String getKeyStorePassword() { try { - if (jsonRootNode != null && jsonRootNode.get(KEY_STORE_PASSWORD) != null) { - String config = CryptoUtils.decrypt(jsonRootNode.get(KEY_STORE_PASSWORD).asText()); - return config.isEmpty() ? null : config; - } + return getEncryptedStringConfig(KEY_STORE_KEY); } catch (GeneralSecurityException | DecoderException e) { logger.error("Unable to decrypt the SDC password", e); + return null; } - return null; } @Override public String getKeyStorePath() { - if (jsonRootNode != null && jsonRootNode.get(KEY_STORE_PATH) != null) { - String config = jsonRootNode.get(KEY_STORE_PATH).asText(); - return config.isEmpty() ? null : config; - } - return null; + return getStringConfig(KEY_STORE_PATH); } /** @@ -251,8 +243,11 @@ public class SdcSingleControllerConfiguration implements IConfiguration { if (this.getAsdcAddress() == null || this.getAsdcAddress().isEmpty()) { throw new SdcParametersException(SDC_ADDRESS_ATTRIBUTE_NAME + errorMessageKeyNotFound); } + if (this.getMsgBusAddress() == null || this.getMsgBusAddress().isEmpty()) { + throw new SdcParametersException(MESSAGE_BUS_ADDRESSES + errorMessageKeyNotFound); + } if (this.getPassword() == null || this.getPassword().isEmpty()) { - throw new SdcParametersException(PASSWORD_ATTRIBUTE_NAME + errorMessageKeyNotFound); + throw new SdcParametersException(SDC_KEY_ATTRIBUTE_NAME + errorMessageKeyNotFound); } if (this.getPollingInterval() == 0) { throw new SdcParametersException(POLLING_INTERVAL_ATTRIBUTE_NAME + errorMessageKeyNotFound); @@ -275,11 +270,17 @@ public class SdcSingleControllerConfiguration implements IConfiguration { */ @Override public boolean isFilterInEmptyResources() { - return true; + return false; } @Override public List getMsgBusAddress() { - return null; + List addressesList = new ArrayList<>(); + if (jsonRootNode != null && jsonRootNode.get(MESSAGE_BUS_ADDRESSES) != null) { + jsonRootNode.get(MESSAGE_BUS_ADDRESSES).forEach(k -> addressesList.add(k.asText())); + return addressesList; + } else { + return addressesList; + } } }