X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fonap%2Faai%2Fmodelloader%2Fconfig%2FModelLoaderConfig.java;h=77693bc7919ce3c82507413b318d4b3afd9fb382;hb=117237ac7b65395e0f29b6cead9f6ffec2e7dc0f;hp=b9cd19332a34ef2c608117d83587d22960ccac8f;hpb=8ad5aa365b9da241ea1ead2300078b2e39da78c8;p=aai%2Fmodel-loader.git 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 b9cd193..77693bc 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,18 +18,20 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.modelloader.config; import java.io.File; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Arrays; 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; +import org.springframework.core.env.Environment; /** * Properties for the Model Loader @@ -56,6 +58,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 = @@ -70,11 +73,10 @@ public class ModelLoaderConfig implements IConfiguration { protected static final String PROP_ML_DISTRIBUTION_POLLING_TIMEOUT = PREFIX_DISTRIBUTION_CLIENT + "POLLING_TIMEOUT"; protected static final String PROP_ML_DISTRIBUTION_USER = PREFIX_DISTRIBUTION_CLIENT + "USER"; protected static final String PROP_ML_DISTRIBUTION_ARTIFACT_TYPES = PREFIX_DISTRIBUTION_CLIENT + "ARTIFACT_TYPES"; - protected static final String PROP_ML_DISTRIBUTION_MSG_BUS_ADDRESSES = - PREFIX_DISTRIBUTION_CLIENT + "MSG_BUS_ADDRESSES"; - protected static final String PROP_ML_DISTRIBUTION_HTTPS_WITH_DMAAP = - PREFIX_DISTRIBUTION_CLIENT + "USE_HTTPS_WITH_DMAAP"; - + protected static final String PROP_ML_DISTRIBUTION_HTTP_PROXY_HOST = PREFIX_DISTRIBUTION_CLIENT + "HTTP_PROXY_HOST"; + protected static final String PROP_ML_DISTRIBUTION_HTTP_PROXY_PORT = PREFIX_DISTRIBUTION_CLIENT + "HTTP_PROXY_PORT"; + protected static final String PROP_ML_DISTRIBUTION_HTTPS_PROXY_HOST = PREFIX_DISTRIBUTION_CLIENT + "HTTPS_PROXY_HOST"; + protected static final String PROP_ML_DISTRIBUTION_HTTPS_PROXY_PORT = PREFIX_DISTRIBUTION_CLIENT + "HTTPS_PROXY_PORT"; protected static final String PROP_AAI_BASE_URL = PREFIX_AAI + "BASE_URL"; protected static final String PROP_AAI_KEYSTORE_FILE = PREFIX_AAI + SUFFIX_KEYSTORE_FILE; protected static final String PROP_AAI_KEYSTORE_PASSWORD = PREFIX_AAI + SUFFIX_KEYSTORE_PASS; @@ -84,14 +86,14 @@ public class ModelLoaderConfig implements IConfiguration { protected static final String PROP_AAI_AUTHENTICATION_USER = PREFIX_AAI + "AUTH_USER"; protected static final String PROP_AAI_AUTHENTICATION_PASSWORD = PREFIX_AAI + "AUTH_PASSWORD"; protected static final String PROP_AAI_USE_GIZMO = PREFIX_AAI + "USE_GIZMO"; - + protected static final String PROP_AAI_USE_HTTPS = PREFIX_AAI + "USE_HTTPS"; protected static final String PROP_BABEL_BASE_URL = PREFIX_BABEL + "BASE_URL"; protected static final String PROP_BABEL_KEYSTORE_FILE = PREFIX_BABEL + SUFFIX_KEYSTORE_FILE; protected static final String PROP_BABEL_KEYSTORE_PASSWORD = PREFIX_BABEL + SUFFIX_KEYSTORE_PASS; protected static final String PROP_BABEL_TRUSTSTORE_FILE = PREFIX_BABEL + SUFFIX_TRUSTSTORE_FILE; protected static final String PROP_BABEL_TRUSTSTORE_PASSWORD = PREFIX_BABEL + SUFFIX_TRUSTSTORE_PASS; protected static final String PROP_BABEL_GENERATE_RESOURCE_URL = PREFIX_BABEL + "GENERATE_ARTIFACTS_URL"; - + protected static final String PROP_BABEL_USE_HTTPS = PREFIX_BABEL + "USE_HTTPS"; protected static final String PROP_DEBUG_INGEST_SIMULATOR = PREFIX_DEBUG + "INGEST_SIMULATOR"; protected static final String FILESEP = (System.getProperty("file.separator") == null) ? "/" : System.getProperty("file.separator"); @@ -99,8 +101,7 @@ 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 final List artifactTypes = new ArrayList<>(); private String modelVersion = null; public ModelLoaderConfig(Properties configProperties) { @@ -111,30 +112,18 @@ 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 (get(PROP_ML_DISTRIBUTION_ARTIFACT_TYPES) != null) { - String[] artTypeList = get(PROP_ML_DISTRIBUTION_ARTIFACT_TYPES).split(","); - for (String artType : artTypeList) { - artifactTypes.add(artType); - } - } - - // Get list of message bus addresses - msgBusAddrs = new ArrayList<>(); - if (get(PROP_ML_DISTRIBUTION_MSG_BUS_ADDRESSES) != null) { - String[] msgBusList = get(PROP_ML_DISTRIBUTION_MSG_BUS_ADDRESSES).split(","); - for (String addr : msgBusList) { - msgBusAddrs.add(addr); - } + // Get list of artifact types + String types = get(PROP_ML_DISTRIBUTION_ARTIFACT_TYPES); + if (types != null) { + artifactTypes.addAll(Arrays.asList(types.split(","))); } } @@ -149,14 +138,24 @@ public class ModelLoaderConfig implements IConfiguration { @Override public boolean activateServerTLSAuth() { String value = get(PROP_ML_DISTRIBUTION_ACTIVE_SERVER_TLS_AUTH); - return value != null && Boolean.parseBoolean(value); + return Boolean.parseBoolean(value); } @Override - public String getAsdcAddress() { + public String getSdcAddress() { 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 get(PROP_ML_DISTRIBUTION_CONSUMER_GROUP); @@ -213,14 +212,23 @@ public class ModelLoaderConfig implements IConfiguration { } @Override - public Boolean isUseHttpsWithDmaap() { - String useHTTPS = get(PROP_ML_DISTRIBUTION_HTTPS_WITH_DMAAP); - return useHTTPS != null && Boolean.valueOf(useHTTPS); + public String getHttpProxyHost() { + return getPropertyOrNull(PROP_ML_DISTRIBUTION_HTTP_PROXY_HOST); + } + + @Override + public int getHttpProxyPort() { + return getIntegerPropertyOrZero(PROP_ML_DISTRIBUTION_HTTP_PROXY_PORT); } @Override - public List getMsgBusAddress() { - return msgBusAddrs; + public String getHttpsProxyHost() { + return getPropertyOrNull(PROP_ML_DISTRIBUTION_HTTPS_PROXY_HOST); + } + + @Override + public int getHttpsProxyPort() { + return getIntegerPropertyOrZero(PROP_ML_DISTRIBUTION_HTTPS_PROXY_PORT); } public String getAaiKeyStorePath() { @@ -271,15 +279,15 @@ public class ModelLoaderConfig implements IConfiguration { 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() { @@ -299,6 +307,16 @@ public class ModelLoaderConfig implements IConfiguration { return useGizmo != null && useGizmo.equalsIgnoreCase("true"); } + public boolean useHttpsWithAAI() { + String useHttps = get(PROP_AAI_USE_HTTPS); + return useHttps != null && useHttps.equalsIgnoreCase("true"); + } + + public boolean useHttpsWithBabel() { + String useHttps = get(PROP_BABEL_USE_HTTPS); + return useHttps != null && useHttps.equalsIgnoreCase("true"); + } + /** * @return password for AAI authentication that has been reverse-engineered from its obfuscated form. */ @@ -321,13 +339,20 @@ public class ModelLoaderConfig implements IConfiguration { } /** - * @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 get(propertyName).replace("v*", version); - else - return get(propertyName); + private String updatePropertyOXMVersion(String propertyName, String version) { + String value = get(propertyName); + if (version != null && value != null) { + value = value.replace("v*", version); + } + return value; } /** @@ -336,24 +361,44 @@ public class ModelLoaderConfig implements IConfiguration { public boolean getASDCConnectionDisabled() { 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:")) { + if (value != null && value.startsWith("ENV:")) { value = System.getenv(StringUtils.removeStart(value, "ENV:")); } return value; } + + public String getPropertyOrNull(String propertyName) { + String value = modelLoaderProperties.getProperty(propertyName); + if (value == null || "NULL".equals(value) || value.isEmpty()) { + return null; + } else { + return value; + } + } + + public int getIntegerPropertyOrZero(String propertyName) { + String property = modelLoaderProperties.getProperty(propertyName); + if (property == null || "NULL".equals(property) || property.isEmpty()) { + return 0; + } else { + try { + return Integer.parseInt(property); + } catch (NumberFormatException e) { + return 0; + } + } + } + }