X-Git-Url: https://gerrit.onap.org/r/gitweb?p=aai%2Fmodel-loader.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fmodelloader%2Fconfig%2FModelLoaderConfig.java;h=88735d4d5b21ef05a583554894cd2a6ce4dcb11f;hp=1d4f8548cbad5629c07b57aa7fae1284347e814f;hb=aecbb49acfb4dfb3ee5abd0b96a46f38a4b2f568;hpb=17b7235cdaca01a6d50d0b2bda6ceb2a239b8862 diff --git a/src/main/java/org/onap/aai/modelloader/config/ModelLoaderConfig.java b/src/main/java/org/onap/aai/modelloader/config/ModelLoaderConfig.java index 1d4f854..88735d4 100644 --- a/src/main/java/org/onap/aai/modelloader/config/ModelLoaderConfig.java +++ b/src/main/java/org/onap/aai/modelloader/config/ModelLoaderConfig.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 European Software Marketing Ltd. + * Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2017-2019 European Software Marketing Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.modelloader.config; import java.io.File; @@ -26,6 +27,7 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.Properties; +import org.apache.commons.lang3.StringUtils; import org.eclipse.jetty.util.security.Password; import org.onap.sdc.api.consumer.IConfiguration; @@ -54,6 +56,7 @@ public class ModelLoaderConfig implements IConfiguration { protected static final String PROP_ML_DISTRIBUTION_ASDC_CONNECTION_DISABLED = PREFIX_DISTRIBUTION_CLIENT + "ASDC_CONNECTION_DISABLE"; protected static final String PROP_ML_DISTRIBUTION_ASDC_ADDRESS = PREFIX_DISTRIBUTION_CLIENT + "ASDC_ADDRESS"; + protected static final String PROP_ML_DISTRIBUTION_ASDC_USE_HTTPS = PREFIX_DISTRIBUTION_CLIENT + "ASDC_USE_HTTPS"; protected static final String PROP_ML_DISTRIBUTION_CONSUMER_GROUP = PREFIX_DISTRIBUTION_CLIENT + "CONSUMER_GROUP"; protected static final String PROP_ML_DISTRIBUTION_CONSUMER_ID = PREFIX_DISTRIBUTION_CLIENT + "CONSUMER_ID"; protected static final String PROP_ML_DISTRIBUTION_ENVIRONMENT_NAME = @@ -97,8 +100,8 @@ public class ModelLoaderConfig implements IConfiguration { private static String configHome; private Properties modelLoaderProperties = null; private String certLocation = "."; - private List artifactTypes = null; - private List msgBusAddrs = null; + private List artifactTypes = new ArrayList<>(); + private List msgBusAddrs = new ArrayList<>(); private String modelVersion = null; public ModelLoaderConfig(Properties configProperties) { @@ -109,28 +112,26 @@ public class ModelLoaderConfig implements IConfiguration { * Original constructor * * @param modelLoaderProperties - * properties needed to be configured for the model loader + * properties needed to be configured for the model loader * @param certLocation - * location of the certificate + * location of the certificate */ public ModelLoaderConfig(Properties modelLoaderProperties, String certLocation) { this.modelLoaderProperties = modelLoaderProperties; this.certLocation = certLocation; - // Get list of artifacts - artifactTypes = new ArrayList<>(); - if (modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_ARTIFACT_TYPES) != null) { - String[] artTypeList = modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_ARTIFACT_TYPES).split(","); - for (String artType : artTypeList) { + // Get list of artifact types + String types = get(PROP_ML_DISTRIBUTION_ARTIFACT_TYPES); + if (types != null) { + for (String artType : types.split(",")) { artifactTypes.add(artType); } } // Get list of message bus addresses - msgBusAddrs = new ArrayList<>(); - if (modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_MSG_BUS_ADDRESSES) != null) { - String[] msgBusList = modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_MSG_BUS_ADDRESSES).split(","); - for (String addr : msgBusList) { + String addresses = get(PROP_ML_DISTRIBUTION_MSG_BUS_ADDRESSES); + if (addresses != null) { + for (String addr : addresses.split(",")) { msgBusAddrs.add(addr); } } @@ -146,53 +147,63 @@ public class ModelLoaderConfig implements IConfiguration { @Override public boolean activateServerTLSAuth() { - String value = modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_ACTIVE_SERVER_TLS_AUTH); + String value = get(PROP_ML_DISTRIBUTION_ACTIVE_SERVER_TLS_AUTH); return value != null && Boolean.parseBoolean(value); } @Override public String getAsdcAddress() { - return modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_ASDC_ADDRESS); + return get(PROP_ML_DISTRIBUTION_ASDC_ADDRESS); + } + + @Override + public Boolean isUseHttpsWithSDC() { + /* if PROP_ML_DISTRIBUTION_ASDC_USE_HTTPS is null, https will be used, as before */ + String value = get(PROP_ML_DISTRIBUTION_ASDC_USE_HTTPS); + if (value == null) { + return true; + } + return Boolean.parseBoolean(value); } @Override public String getConsumerGroup() { - return modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_CONSUMER_GROUP); + return get(PROP_ML_DISTRIBUTION_CONSUMER_GROUP); } @Override public String getConsumerID() { - return modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_CONSUMER_ID); + return get(PROP_ML_DISTRIBUTION_CONSUMER_ID); } @Override public String getEnvironmentName() { - return modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_ENVIRONMENT_NAME); + return get(PROP_ML_DISTRIBUTION_ENVIRONMENT_NAME); } @Override public String getKeyStorePassword() { - return getDeobfuscatedValue(modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD)); + return getDeobfuscatedValue(get(PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD)); } @Override public String getKeyStorePath() { - return certLocation + modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_KEYSTORE_FILE); + return certLocation + get(PROP_ML_DISTRIBUTION_KEYSTORE_FILE); } @Override public String getPassword() { - return getDeobfuscatedValue(modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_PASSWORD)); + return getDeobfuscatedValue(get(PROP_ML_DISTRIBUTION_PASSWORD)); } @Override public int getPollingInterval() { - return Integer.parseInt(modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_POLLING_INTERVAL)); + return Integer.parseInt(get(PROP_ML_DISTRIBUTION_POLLING_INTERVAL)); } @Override public int getPollingTimeout() { - return Integer.parseInt(modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_POLLING_TIMEOUT)); + return Integer.parseInt(get(PROP_ML_DISTRIBUTION_POLLING_TIMEOUT)); } @Override @@ -202,7 +213,7 @@ public class ModelLoaderConfig implements IConfiguration { @Override public String getUser() { - return modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_USER); + return get(PROP_ML_DISTRIBUTION_USER); } @Override @@ -212,7 +223,7 @@ public class ModelLoaderConfig implements IConfiguration { @Override public Boolean isUseHttpsWithDmaap() { - String useHTTPS = modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_HTTPS_WITH_DMAAP); + String useHTTPS = get(PROP_ML_DISTRIBUTION_HTTPS_WITH_DMAAP); return useHTTPS != null && Boolean.valueOf(useHTTPS); } @@ -226,7 +237,7 @@ public class ModelLoaderConfig implements IConfiguration { } public String getBabelKeyStorePath() { - String filename = modelLoaderProperties.getProperty(PROP_BABEL_KEYSTORE_FILE); + String filename = get(PROP_BABEL_KEYSTORE_FILE); if (filename == null) { return null; } else { @@ -235,15 +246,15 @@ public class ModelLoaderConfig implements IConfiguration { } public String getAaiKeyStorePassword() { - return getDeobfuscatedValue(modelLoaderProperties.getProperty(PROP_AAI_KEYSTORE_PASSWORD)); + return getDeobfuscatedValue(get(PROP_AAI_KEYSTORE_PASSWORD)); } public String getBabelKeyStorePassword() { - return getDeobfuscatedValue(modelLoaderProperties.getProperty(PROP_BABEL_KEYSTORE_PASSWORD)); + return getDeobfuscatedValue(get(PROP_BABEL_KEYSTORE_PASSWORD)); } public String getBabelTrustStorePath() { - String filename = modelLoaderProperties.getProperty(PROP_BABEL_TRUSTSTORE_FILE); + String filename = get(PROP_BABEL_TRUSTSTORE_FILE); if (filename == null) { return null; } else { @@ -252,36 +263,36 @@ public class ModelLoaderConfig implements IConfiguration { } public String getBabelTrustStorePassword() { - return getDeobfuscatedValue(modelLoaderProperties.getProperty(PROP_BABEL_TRUSTSTORE_PASSWORD)); + return getDeobfuscatedValue(get(PROP_BABEL_TRUSTSTORE_PASSWORD)); } public String getAaiBaseUrl() { - return modelLoaderProperties.getProperty(PROP_AAI_BASE_URL); + return get(PROP_AAI_BASE_URL); } public String getBabelBaseUrl() { - return modelLoaderProperties.getProperty(PROP_BABEL_BASE_URL); + return get(PROP_BABEL_BASE_URL); } public String getBabelGenerateArtifactsUrl() { - return modelLoaderProperties.getProperty(PROP_BABEL_GENERATE_RESOURCE_URL); + return get(PROP_BABEL_GENERATE_RESOURCE_URL); } public String getAaiModelUrl(String version) { setModelVersion(version); - return updatePropertyOXMVersion(modelLoaderProperties, PROP_AAI_MODEL_RESOURCE_URL, version); + return updatePropertyOXMVersion(PROP_AAI_MODEL_RESOURCE_URL, version); } public String getAaiNamedQueryUrl(String version) { - return updatePropertyOXMVersion(modelLoaderProperties, PROP_AAI_NAMED_QUERY_RESOURCE_URL, version); + return updatePropertyOXMVersion(PROP_AAI_NAMED_QUERY_RESOURCE_URL, version); } public String getAaiVnfImageUrl() { - return updatePropertyOXMVersion(modelLoaderProperties, PROP_AAI_VNF_IMAGE_RESOURCE_URL, getModelVersion()); + return updatePropertyOXMVersion(PROP_AAI_VNF_IMAGE_RESOURCE_URL, getModelVersion()); } public String getAaiAuthenticationUser() { - return modelLoaderProperties.getProperty(PROP_AAI_AUTHENTICATION_USER); + return get(PROP_AAI_AUTHENTICATION_USER); } public String getModelVersion() { @@ -293,7 +304,7 @@ public class ModelLoaderConfig implements IConfiguration { } public boolean useGizmo() { - String useGizmo = modelLoaderProperties.getProperty(PROP_AAI_USE_GIZMO); + String useGizmo = get(PROP_AAI_USE_GIZMO); return useGizmo != null && useGizmo.equalsIgnoreCase("true"); } @@ -301,7 +312,7 @@ public class ModelLoaderConfig implements IConfiguration { * @return password for AAI authentication that has been reverse-engineered from its obfuscated form. */ public String getAaiAuthenticationPassword() { - String password = getDeobfuscatedValue(modelLoaderProperties.getProperty(PROP_AAI_AUTHENTICATION_PASSWORD)); + String password = getDeobfuscatedValue(get(PROP_AAI_AUTHENTICATION_PASSWORD)); if (password != null && password.isEmpty()) { password = null; @@ -314,35 +325,48 @@ public class ModelLoaderConfig implements IConfiguration { * @return a boolean value indicating whether the simulator is enabled. */ public boolean getIngestSimulatorEnabled() { - String propValue = modelLoaderProperties.getProperty(PROP_DEBUG_INGEST_SIMULATOR); + String propValue = get(PROP_DEBUG_INGEST_SIMULATOR); return propValue != null && "enabled".equalsIgnoreCase(propValue); } /** - * @return a String value of the defined property with the oxm version + * Read the value of the property and replace any wildcard OXM version "v*" with the supplied default OXM version + * + * @param propertyName + * the name of the property storing the OXM version (possibly containing v*) + * @param version + * the default OXM version + * @return the String value of the defined property (with any wildcard OXM version defaulted) */ - private String updatePropertyOXMVersion(Properties modelLoaderProperties, String propertyName, String version) { - if (version != null) - return modelLoaderProperties.getProperty(propertyName).replace("v*", version); - else - return modelLoaderProperties.getProperty(propertyName); + private String updatePropertyOXMVersion(String propertyName, String version) { + String value = get(propertyName); + if (version != null && value != null) { + value = value.replace("v*", version); + } + return value; } /** * @return a boolean value indicating whether model loader is connected to ASDC. */ public boolean getASDCConnectionDisabled() { - String propValue = modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_ASDC_CONNECTION_DISABLED); + String propValue = get(PROP_ML_DISTRIBUTION_ASDC_CONNECTION_DISABLED); return propValue != null && "true".equalsIgnoreCase(propValue); - } private String getDeobfuscatedValue(String property) { - if (property.startsWith("OBF:")) { + if (property != null && property.startsWith("OBF:")) { return Password.deobfuscate(property); } - - // Property is not obfuscated return property; } + + private String get(String key) { + String value = modelLoaderProperties.getProperty(key); + + if (value != null && value.startsWith("ENV:")) { + value = System.getenv(StringUtils.removeStart(value, "ENV:")); + } + return value; + } }