2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright (c) 2017-2019 European Software Marketing Ltd.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.aai.modelloader.config;
25 import java.nio.file.Path;
26 import java.nio.file.Paths;
27 import java.util.ArrayList;
28 import java.util.Arrays;
29 import java.util.List;
30 import java.util.Optional;
31 import java.util.Properties;
33 import org.apache.commons.lang3.StringUtils;
34 import org.eclipse.jetty.util.security.Password;
35 import org.onap.sdc.api.consumer.IConfiguration;
37 * Properties for the Model Loader
40 public class ModelLoaderConfig implements IConfiguration {
42 // Configuration file structure
43 public static final String PREFIX_MODEL_LOADER_CONFIG = "ml";
44 public static final String PREFIX_DISTRIBUTION_CLIENT = PREFIX_MODEL_LOADER_CONFIG + ".distribution.";
45 public static final String PREFIX_AAI = PREFIX_MODEL_LOADER_CONFIG + ".aai.";
46 public static final String PREFIX_BABEL = PREFIX_MODEL_LOADER_CONFIG + ".babel.";
47 public static final String PREFIX_DEBUG = PREFIX_MODEL_LOADER_CONFIG + ".debug.";
49 private static final String SUFFIX_KEYSTORE_FILE = "KEYSTORE_FILE";
50 private static final String SUFFIX_KEYSTORE_PASS = "KEYSTORE_PASSWORD";
52 private static final String SUFFIX_TRUSTSTORE_FILE = "TRUSTSTORE_FILE";
53 private static final String SUFFIX_TRUSTSTORE_PASS = "TRUSTSTORE_PASSWORD";
55 // Configuration file properties
56 protected static final String PROP_ML_DISTRIBUTION_ACTIVE_SERVER_TLS_AUTH =
57 PREFIX_DISTRIBUTION_CLIENT + "ACTIVE_SERVER_TLS_AUTH";
58 protected static final String PROP_ML_DISTRIBUTION_ASDC_CONNECTION_DISABLED =
59 PREFIX_DISTRIBUTION_CLIENT + "ASDC_CONNECTION_DISABLE";
60 protected static final String PROP_ML_DISTRIBUTION_ASDC_ADDRESS = PREFIX_DISTRIBUTION_CLIENT + "ASDC_ADDRESS";
61 protected static final String PROP_ML_DISTRIBUTION_ASDC_USE_HTTPS = PREFIX_DISTRIBUTION_CLIENT + "ASDC_USE_HTTPS";
62 protected static final String PROP_ML_DISTRIBUTION_CONSUMER_GROUP = PREFIX_DISTRIBUTION_CLIENT + "CONSUMER_GROUP";
63 protected static final String PROP_ML_DISTRIBUTION_CONSUMER_ID = PREFIX_DISTRIBUTION_CLIENT + "CONSUMER_ID";
64 protected static final String PROP_ML_DISTRIBUTION_ENVIRONMENT_NAME =
65 PREFIX_DISTRIBUTION_CLIENT + "ENVIRONMENT_NAME";
66 protected static final String PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD =
67 PREFIX_DISTRIBUTION_CLIENT + SUFFIX_KEYSTORE_PASS;
68 protected static final String PROP_ML_DISTRIBUTION_KEYSTORE_FILE =
69 PREFIX_DISTRIBUTION_CLIENT + SUFFIX_KEYSTORE_FILE;
70 protected static final String PROP_ML_DISTRIBUTION_PASSWORD = PREFIX_DISTRIBUTION_CLIENT + "PASSWORD";
71 protected static final String PROP_ML_DISTRIBUTION_POLLING_INTERVAL =
72 PREFIX_DISTRIBUTION_CLIENT + "POLLING_INTERVAL";
73 protected static final String PROP_ML_DISTRIBUTION_POLLING_TIMEOUT = PREFIX_DISTRIBUTION_CLIENT + "POLLING_TIMEOUT";
74 protected static final String PROP_ML_DISTRIBUTION_USER = PREFIX_DISTRIBUTION_CLIENT + "USER";
75 protected static final String PROP_ML_DISTRIBUTION_ARTIFACT_TYPES = PREFIX_DISTRIBUTION_CLIENT + "ARTIFACT_TYPES";
76 protected static final String PROP_ML_DISTRIBUTION_HTTP_PROXY_HOST = PREFIX_DISTRIBUTION_CLIENT + "HTTP_PROXY_HOST";
77 protected static final String PROP_ML_DISTRIBUTION_HTTP_PROXY_PORT = PREFIX_DISTRIBUTION_CLIENT + "HTTP_PROXY_PORT";
78 protected static final String PROP_ML_DISTRIBUTION_HTTPS_PROXY_HOST = PREFIX_DISTRIBUTION_CLIENT + "HTTPS_PROXY_HOST";
79 protected static final String PROP_ML_DISTRIBUTION_HTTPS_PROXY_PORT = PREFIX_DISTRIBUTION_CLIENT + "HTTPS_PROXY_PORT";
80 protected static final String PROP_AAI_BASE_URL = PREFIX_AAI + "BASE_URL";
81 protected static final String PROP_AAI_KEYSTORE_FILE = PREFIX_AAI + SUFFIX_KEYSTORE_FILE;
82 protected static final String PROP_AAI_KEYSTORE_PASSWORD = PREFIX_AAI + SUFFIX_KEYSTORE_PASS;
83 protected static final String PROP_AAI_MODEL_RESOURCE_URL = PREFIX_AAI + "MODEL_URL";
84 protected static final String PROP_AAI_NAMED_QUERY_RESOURCE_URL = PREFIX_AAI + "NAMED_QUERY_URL";
85 protected static final String PROP_AAI_VNF_IMAGE_RESOURCE_URL = PREFIX_AAI + "VNF_IMAGE_URL";
86 protected static final String PROP_AAI_AUTHENTICATION_USER = PREFIX_AAI + "AUTH_USER";
87 protected static final String PROP_AAI_AUTHENTICATION_PASSWORD = PREFIX_AAI + "AUTH_PASSWORD";
88 protected static final String PROP_AAI_USE_GIZMO = PREFIX_AAI + "USE_GIZMO";
89 protected static final String PROP_AAI_USE_HTTPS = PREFIX_AAI + "USE_HTTPS";
90 protected static final String PROP_BABEL_BASE_URL = PREFIX_BABEL + "BASE_URL";
91 protected static final String PROP_BABEL_KEYSTORE_FILE = PREFIX_BABEL + SUFFIX_KEYSTORE_FILE;
92 protected static final String PROP_BABEL_KEYSTORE_PASSWORD = PREFIX_BABEL + SUFFIX_KEYSTORE_PASS;
93 protected static final String PROP_BABEL_TRUSTSTORE_FILE = PREFIX_BABEL + SUFFIX_TRUSTSTORE_FILE;
94 protected static final String PROP_BABEL_TRUSTSTORE_PASSWORD = PREFIX_BABEL + SUFFIX_TRUSTSTORE_PASS;
95 protected static final String PROP_BABEL_GENERATE_RESOURCE_URL = PREFIX_BABEL + "GENERATE_ARTIFACTS_URL";
96 protected static final String PROP_BABEL_USE_HTTPS = PREFIX_BABEL + "USE_HTTPS";
97 protected static final String PROP_DEBUG_INGEST_SIMULATOR = PREFIX_DEBUG + "INGEST_SIMULATOR";
98 protected static final String FILESEP =
99 (System.getProperty("file.separator") == null) ? "/" : System.getProperty("file.separator");
100 protected static final String PROP_AAI_CLIENT_CONNECT_TIMEOUT_MS = PREFIX_AAI + "RESTCLIENT_CONNECT_TIMEOUT";
101 protected static final String PROP_AAI_CLIENT_READ_TIMEOUT_MS = PREFIX_AAI + "RESTCLIENT_READ_TIMEOUT";
103 private static String configHome;
104 private Properties modelLoaderProperties = null;
105 private String certLocation = ".";
106 private final List<String> artifactTypes = new ArrayList<>();
107 private String modelVersion = null;
109 public ModelLoaderConfig(Properties configProperties) {
110 this(configProperties, ModelLoaderConfig.configHome + FILESEP + "auth" + FILESEP);
114 * Original constructor
116 * @param modelLoaderProperties
117 * properties needed to be configured for the model loader
118 * @param certLocation
119 * location of the certificate
121 public ModelLoaderConfig(Properties modelLoaderProperties, String certLocation) {
122 this.modelLoaderProperties = modelLoaderProperties;
123 this.certLocation = certLocation;
125 // Get list of artifact types
126 String types = get(PROP_ML_DISTRIBUTION_ARTIFACT_TYPES);
128 artifactTypes.addAll(Arrays.asList(types.split(",")));
132 public static void setConfigHome(String configHome) {
133 ModelLoaderConfig.configHome = configHome;
136 public static Path propertiesFile() {
137 return Paths.get(configHome, "model-loader.properties");
141 public boolean activateServerTLSAuth() {
142 String value = get(PROP_ML_DISTRIBUTION_ACTIVE_SERVER_TLS_AUTH);
143 return Boolean.parseBoolean(value);
147 public String getSdcAddress() {
148 return get(PROP_ML_DISTRIBUTION_ASDC_ADDRESS);
152 public Boolean isUseHttpsWithSDC() {
153 /* if PROP_ML_DISTRIBUTION_ASDC_USE_HTTPS is null, https will be used, as before */
154 String value = get(PROP_ML_DISTRIBUTION_ASDC_USE_HTTPS);
158 return Boolean.parseBoolean(value);
162 public String getConsumerGroup() {
163 return get(PROP_ML_DISTRIBUTION_CONSUMER_GROUP);
167 public String getConsumerID() {
168 return get(PROP_ML_DISTRIBUTION_CONSUMER_ID);
172 public String getEnvironmentName() {
173 return get(PROP_ML_DISTRIBUTION_ENVIRONMENT_NAME);
177 public String getKeyStorePassword() {
178 return getDeobfuscatedValue(get(PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD));
182 public String getKeyStorePath() {
183 return certLocation + get(PROP_ML_DISTRIBUTION_KEYSTORE_FILE);
187 public String getPassword() {
188 return getDeobfuscatedValue(get(PROP_ML_DISTRIBUTION_PASSWORD));
192 public int getPollingInterval() {
193 return Integer.parseInt(get(PROP_ML_DISTRIBUTION_POLLING_INTERVAL));
197 public int getPollingTimeout() {
198 return Integer.parseInt(get(PROP_ML_DISTRIBUTION_POLLING_TIMEOUT));
202 public List<String> getRelevantArtifactTypes() {
203 return artifactTypes;
207 public String getUser() {
208 return get(PROP_ML_DISTRIBUTION_USER);
212 public boolean isFilterInEmptyResources() {
217 public String getHttpProxyHost() {
218 return getPropertyOrNull(PROP_ML_DISTRIBUTION_HTTP_PROXY_HOST);
222 public int getHttpProxyPort() {
223 return getIntegerPropertyOrZero(PROP_ML_DISTRIBUTION_HTTP_PROXY_PORT);
227 public String getHttpsProxyHost() {
228 return getPropertyOrNull(PROP_ML_DISTRIBUTION_HTTPS_PROXY_HOST);
232 public int getHttpsProxyPort() {
233 return getIntegerPropertyOrZero(PROP_ML_DISTRIBUTION_HTTPS_PROXY_PORT);
236 public String getAaiKeyStorePath() {
237 return certLocation + File.separator + modelLoaderProperties.getProperty(PROP_AAI_KEYSTORE_FILE);
240 public String getBabelKeyStorePath() {
241 String filename = get(PROP_BABEL_KEYSTORE_FILE);
242 if (filename == null) {
245 return certLocation + File.separator + filename;
249 public String getAaiKeyStorePassword() {
250 return getDeobfuscatedValue(get(PROP_AAI_KEYSTORE_PASSWORD));
253 public String getBabelKeyStorePassword() {
254 return getDeobfuscatedValue(get(PROP_BABEL_KEYSTORE_PASSWORD));
257 public String getBabelTrustStorePath() {
258 String filename = get(PROP_BABEL_TRUSTSTORE_FILE);
259 if (filename == null) {
262 return certLocation + File.separator + filename;
266 public String getBabelTrustStorePassword() {
267 return getDeobfuscatedValue(get(PROP_BABEL_TRUSTSTORE_PASSWORD));
270 public String getAaiBaseUrl() {
271 return get(PROP_AAI_BASE_URL);
274 public String getBabelBaseUrl() {
275 return get(PROP_BABEL_BASE_URL);
278 public String getBabelGenerateArtifactsUrl() {
279 return get(PROP_BABEL_GENERATE_RESOURCE_URL);
282 public String getAaiModelUrl(String version) {
283 setModelVersion(version);
284 return updatePropertyOXMVersion(PROP_AAI_MODEL_RESOURCE_URL, version);
287 public String getAaiNamedQueryUrl(String version) {
288 return updatePropertyOXMVersion(PROP_AAI_NAMED_QUERY_RESOURCE_URL, version);
291 public String getAaiVnfImageUrl() {
292 return updatePropertyOXMVersion(PROP_AAI_VNF_IMAGE_RESOURCE_URL, getModelVersion());
295 public String getAaiAuthenticationUser() {
296 return get(PROP_AAI_AUTHENTICATION_USER);
299 public String getModelVersion() {
303 public void setModelVersion(String modelVersion) {
304 this.modelVersion = modelVersion;
307 public boolean useGizmo() {
308 String useGizmo = get(PROP_AAI_USE_GIZMO);
309 return useGizmo != null && useGizmo.equalsIgnoreCase("true");
312 public boolean useHttpsWithAAI() {
313 String useHttps = get(PROP_AAI_USE_HTTPS);
314 return useHttps != null && useHttps.equalsIgnoreCase("true");
317 public boolean useHttpsWithBabel() {
318 String useHttps = get(PROP_BABEL_USE_HTTPS);
319 return useHttps != null && useHttps.equalsIgnoreCase("true");
323 * @return password for AAI authentication that has been reverse-engineered from its obfuscated form.
325 public String getAaiAuthenticationPassword() {
326 String password = getDeobfuscatedValue(get(PROP_AAI_AUTHENTICATION_PASSWORD));
328 if (password != null && password.isEmpty()) {
336 * @return a boolean value indicating whether the simulator is enabled.
338 public boolean getIngestSimulatorEnabled() {
339 String propValue = get(PROP_DEBUG_INGEST_SIMULATOR);
340 return propValue != null && "enabled".equalsIgnoreCase(propValue);
344 * Read the value of the property and replace any wildcard OXM version "v*" with the supplied default OXM version
346 * @param propertyName
347 * the name of the property storing the OXM version (possibly containing v*)
349 * the default OXM version
350 * @return the String value of the defined property (with any wildcard OXM version defaulted)
352 private String updatePropertyOXMVersion(String propertyName, String version) {
353 String value = get(propertyName);
354 if (version != null && value != null) {
355 value = value.replace("v*", version);
361 * @return a boolean value indicating whether model loader is connected to ASDC.
363 public boolean getASDCConnectionDisabled() {
364 String propValue = get(PROP_ML_DISTRIBUTION_ASDC_CONNECTION_DISABLED);
365 return propValue != null && "true".equalsIgnoreCase(propValue);
368 private String getDeobfuscatedValue(String property) {
369 if (property != null && property.startsWith("OBF:")) {
370 return Password.deobfuscate(property);
375 private String get(String key) {
376 String value = modelLoaderProperties.getProperty(key);
378 if (value != null && value.startsWith("ENV:")) {
379 value = System.getenv(StringUtils.removeStart(value, "ENV:"));
384 public String getPropertyOrNull(String propertyName) {
385 String value = modelLoaderProperties.getProperty(propertyName);
386 if (value == null || "NULL".equals(value) || value.isEmpty()) {
393 public int getIntegerPropertyOrZero(String propertyName) {
394 String property = modelLoaderProperties.getProperty(propertyName);
395 if (property == null || "NULL".equals(property) || property.isEmpty()) {
399 return Integer.parseInt(property);
400 } catch (NumberFormatException e) {
406 public int getClientConnectTimeoutMs() {
407 String connectTimeout = Optional.ofNullable(get(PROP_AAI_CLIENT_CONNECT_TIMEOUT_MS)).orElse("120000");
408 return Integer.parseInt(connectTimeout);
411 public int getClientReadTimeoutMs() {
412 String connectTimeout = Optional.ofNullable(get(PROP_AAI_CLIENT_READ_TIMEOUT_MS)).orElse("120000");
413 return Integer.parseInt(connectTimeout);