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_ML_DISTRIBUTION_SASL_JAAS_CONFIG = PREFIX_DISTRIBUTION_CLIENT + "SASL_JAAS_CONFIG";
81 protected static final String PROP_ML_DISTRIBUTION_SASL_MECHANISM = PREFIX_DISTRIBUTION_CLIENT + "SASL_MECHANISM";
82 protected static final String PROP_ML_DISTRIBUTION_SECURITY_PROTOCOL = PREFIX_DISTRIBUTION_CLIENT + "SECURITY_PROTOCOL";
83 protected static final String PROP_AAI_BASE_URL = PREFIX_AAI + "BASE_URL";
84 protected static final String PROP_AAI_KEYSTORE_FILE = PREFIX_AAI + SUFFIX_KEYSTORE_FILE;
85 protected static final String PROP_AAI_KEYSTORE_PASSWORD = PREFIX_AAI + SUFFIX_KEYSTORE_PASS;
86 protected static final String PROP_AAI_MODEL_RESOURCE_URL = PREFIX_AAI + "MODEL_URL";
87 protected static final String PROP_AAI_NAMED_QUERY_RESOURCE_URL = PREFIX_AAI + "NAMED_QUERY_URL";
88 protected static final String PROP_AAI_VNF_IMAGE_RESOURCE_URL = PREFIX_AAI + "VNF_IMAGE_URL";
89 protected static final String PROP_AAI_AUTHENTICATION_USER = PREFIX_AAI + "AUTH_USER";
90 protected static final String PROP_AAI_AUTHENTICATION_PASSWORD = PREFIX_AAI + "AUTH_PASSWORD";
91 protected static final String PROP_AAI_USE_GIZMO = PREFIX_AAI + "USE_GIZMO";
92 protected static final String PROP_AAI_USE_HTTPS = PREFIX_AAI + "USE_HTTPS";
93 protected static final String PROP_BABEL_BASE_URL = PREFIX_BABEL + "BASE_URL";
94 protected static final String PROP_BABEL_KEYSTORE_FILE = PREFIX_BABEL + SUFFIX_KEYSTORE_FILE;
95 protected static final String PROP_BABEL_KEYSTORE_PASSWORD = PREFIX_BABEL + SUFFIX_KEYSTORE_PASS;
96 protected static final String PROP_BABEL_TRUSTSTORE_FILE = PREFIX_BABEL + SUFFIX_TRUSTSTORE_FILE;
97 protected static final String PROP_BABEL_TRUSTSTORE_PASSWORD = PREFIX_BABEL + SUFFIX_TRUSTSTORE_PASS;
98 protected static final String PROP_BABEL_GENERATE_RESOURCE_URL = PREFIX_BABEL + "GENERATE_ARTIFACTS_URL";
99 protected static final String PROP_BABEL_USE_HTTPS = PREFIX_BABEL + "USE_HTTPS";
100 protected static final String PROP_DEBUG_INGEST_SIMULATOR = PREFIX_DEBUG + "INGEST_SIMULATOR";
101 protected static final String FILESEP =
102 (System.getProperty("file.separator") == null) ? "/" : System.getProperty("file.separator");
103 protected static final String PROP_AAI_CLIENT_CONNECT_TIMEOUT_MS = PREFIX_AAI + "RESTCLIENT_CONNECT_TIMEOUT";
104 protected static final String PROP_AAI_CLIENT_READ_TIMEOUT_MS = PREFIX_AAI + "RESTCLIENT_READ_TIMEOUT";
106 private static String configHome;
107 private Properties modelLoaderProperties = null;
108 private String certLocation = ".";
109 private final List<String> artifactTypes = new ArrayList<>();
110 private String modelVersion = null;
112 public ModelLoaderConfig(Properties configProperties) {
113 this(configProperties, ModelLoaderConfig.configHome + FILESEP + "auth" + FILESEP);
117 * Original constructor
119 * @param modelLoaderProperties
120 * properties needed to be configured for the model loader
121 * @param certLocation
122 * location of the certificate
124 public ModelLoaderConfig(Properties modelLoaderProperties, String certLocation) {
125 this.modelLoaderProperties = modelLoaderProperties;
126 this.certLocation = certLocation;
128 // Get list of artifact types
129 String types = get(PROP_ML_DISTRIBUTION_ARTIFACT_TYPES);
131 artifactTypes.addAll(Arrays.asList(types.split(",")));
135 public static void setConfigHome(String configHome) {
136 ModelLoaderConfig.configHome = configHome;
139 public static Path propertiesFile() {
140 return Paths.get(configHome, "model-loader.properties");
144 public boolean activateServerTLSAuth() {
145 String value = get(PROP_ML_DISTRIBUTION_ACTIVE_SERVER_TLS_AUTH);
146 return Boolean.parseBoolean(value);
150 public String getSdcAddress() {
151 return get(PROP_ML_DISTRIBUTION_ASDC_ADDRESS);
155 public Boolean isUseHttpsWithSDC() {
156 /* if PROP_ML_DISTRIBUTION_ASDC_USE_HTTPS is null, https will be used, as before */
157 String value = get(PROP_ML_DISTRIBUTION_ASDC_USE_HTTPS);
161 return Boolean.parseBoolean(value);
165 public String getConsumerGroup() {
166 return get(PROP_ML_DISTRIBUTION_CONSUMER_GROUP);
170 public String getConsumerID() {
171 return get(PROP_ML_DISTRIBUTION_CONSUMER_ID);
175 public String getEnvironmentName() {
176 return get(PROP_ML_DISTRIBUTION_ENVIRONMENT_NAME);
180 public String getKeyStorePassword() {
181 return getDeobfuscatedValue(get(PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD));
185 public String getKeyStorePath() {
186 return certLocation + get(PROP_ML_DISTRIBUTION_KEYSTORE_FILE);
190 public String getPassword() {
191 return getDeobfuscatedValue(get(PROP_ML_DISTRIBUTION_PASSWORD));
195 public int getPollingInterval() {
196 return Integer.parseInt(get(PROP_ML_DISTRIBUTION_POLLING_INTERVAL));
200 public int getPollingTimeout() {
201 return Integer.parseInt(get(PROP_ML_DISTRIBUTION_POLLING_TIMEOUT));
205 public List<String> getRelevantArtifactTypes() {
206 return artifactTypes;
210 public String getUser() {
211 return get(PROP_ML_DISTRIBUTION_USER);
215 public boolean isFilterInEmptyResources() {
220 public String getHttpProxyHost() {
221 return getPropertyOrNull(PROP_ML_DISTRIBUTION_HTTP_PROXY_HOST);
225 public int getHttpProxyPort() {
226 return getIntegerPropertyOrZero(PROP_ML_DISTRIBUTION_HTTP_PROXY_PORT);
230 public String getHttpsProxyHost() {
231 return getPropertyOrNull(PROP_ML_DISTRIBUTION_HTTPS_PROXY_HOST);
235 public int getHttpsProxyPort() {
236 return getIntegerPropertyOrZero(PROP_ML_DISTRIBUTION_HTTPS_PROXY_PORT);
239 public String getAaiKeyStorePath() {
240 return certLocation + File.separator + modelLoaderProperties.getProperty(PROP_AAI_KEYSTORE_FILE);
243 public String getBabelKeyStorePath() {
244 String filename = get(PROP_BABEL_KEYSTORE_FILE);
245 if (filename == null) {
248 return certLocation + File.separator + filename;
252 public String getAaiKeyStorePassword() {
253 return getDeobfuscatedValue(get(PROP_AAI_KEYSTORE_PASSWORD));
256 public String getBabelKeyStorePassword() {
257 return getDeobfuscatedValue(get(PROP_BABEL_KEYSTORE_PASSWORD));
260 public String getBabelTrustStorePath() {
261 String filename = get(PROP_BABEL_TRUSTSTORE_FILE);
262 if (filename == null) {
265 return certLocation + File.separator + filename;
269 public String getBabelTrustStorePassword() {
270 return getDeobfuscatedValue(get(PROP_BABEL_TRUSTSTORE_PASSWORD));
273 public String getAaiBaseUrl() {
274 return get(PROP_AAI_BASE_URL);
277 public String getBabelBaseUrl() {
278 return get(PROP_BABEL_BASE_URL);
281 public String getBabelGenerateArtifactsUrl() {
282 return get(PROP_BABEL_GENERATE_RESOURCE_URL);
285 public String getAaiModelUrl(String version) {
286 setModelVersion(version);
287 return updatePropertyOXMVersion(PROP_AAI_MODEL_RESOURCE_URL, version);
290 public String getAaiNamedQueryUrl(String version) {
291 return updatePropertyOXMVersion(PROP_AAI_NAMED_QUERY_RESOURCE_URL, version);
294 public String getAaiVnfImageUrl() {
295 return updatePropertyOXMVersion(PROP_AAI_VNF_IMAGE_RESOURCE_URL, getModelVersion());
298 public String getAaiAuthenticationUser() {
299 return get(PROP_AAI_AUTHENTICATION_USER);
302 public String getModelVersion() {
306 public void setModelVersion(String modelVersion) {
307 this.modelVersion = modelVersion;
310 public boolean useGizmo() {
311 String useGizmo = get(PROP_AAI_USE_GIZMO);
312 return useGizmo != null && useGizmo.equalsIgnoreCase("true");
315 public boolean useHttpsWithAAI() {
316 String useHttps = get(PROP_AAI_USE_HTTPS);
317 return useHttps != null && useHttps.equalsIgnoreCase("true");
320 public boolean useHttpsWithBabel() {
321 String useHttps = get(PROP_BABEL_USE_HTTPS);
322 return useHttps != null && useHttps.equalsIgnoreCase("true");
326 * @return password for AAI authentication that has been reverse-engineered from its obfuscated form.
328 public String getAaiAuthenticationPassword() {
329 String password = getDeobfuscatedValue(get(PROP_AAI_AUTHENTICATION_PASSWORD));
331 if (password != null && password.isEmpty()) {
339 * @return a boolean value indicating whether the simulator is enabled.
341 public boolean getIngestSimulatorEnabled() {
342 String propValue = get(PROP_DEBUG_INGEST_SIMULATOR);
343 return propValue != null && "enabled".equalsIgnoreCase(propValue);
347 * Read the value of the property and replace any wildcard OXM version "v*" with the supplied default OXM version
349 * @param propertyName
350 * the name of the property storing the OXM version (possibly containing v*)
352 * the default OXM version
353 * @return the String value of the defined property (with any wildcard OXM version defaulted)
355 private String updatePropertyOXMVersion(String propertyName, String version) {
356 String value = get(propertyName);
357 if (version != null && value != null) {
358 value = value.replace("v*", version);
364 * @return a boolean value indicating whether model loader is connected to ASDC.
366 public boolean getASDCConnectionDisabled() {
367 String propValue = get(PROP_ML_DISTRIBUTION_ASDC_CONNECTION_DISABLED);
368 return propValue != null && "true".equalsIgnoreCase(propValue);
371 private String getDeobfuscatedValue(String property) {
372 if (property != null && property.startsWith("OBF:")) {
373 return Password.deobfuscate(property);
378 private String get(String key) {
379 String value = modelLoaderProperties.getProperty(key);
381 if (value != null && value.startsWith("ENV:")) {
382 value = System.getenv(StringUtils.removeStart(value, "ENV:"));
387 public String getPropertyOrNull(String propertyName) {
388 String value = modelLoaderProperties.getProperty(propertyName);
389 if (value == null || "NULL".equals(value) || value.isEmpty()) {
396 public int getIntegerPropertyOrZero(String propertyName) {
397 String property = modelLoaderProperties.getProperty(propertyName);
398 if (property == null || "NULL".equals(property) || property.isEmpty()) {
402 return Integer.parseInt(property);
403 } catch (NumberFormatException e) {
409 public int getClientConnectTimeoutMs() {
410 String connectTimeout = Optional.ofNullable(get(PROP_AAI_CLIENT_CONNECT_TIMEOUT_MS)).orElse("120000");
411 return Integer.parseInt(connectTimeout);
414 public int getClientReadTimeoutMs() {
415 String connectTimeout = Optional.ofNullable(get(PROP_AAI_CLIENT_READ_TIMEOUT_MS)).orElse("120000");
416 return Integer.parseInt(connectTimeout);
420 public String getKafkaSaslJaasConfig() {
421 String saslJaasConfFromEnv = System.getenv("SASL_JAAS_CONFIG");
422 if(saslJaasConfFromEnv != null) {
423 return saslJaasConfFromEnv;
425 if(get(PROP_ML_DISTRIBUTION_SASL_JAAS_CONFIG) != null) {
426 return get(PROP_ML_DISTRIBUTION_SASL_JAAS_CONFIG);
432 public String getKafkaSaslMechanism() {
433 if(get(PROP_ML_DISTRIBUTION_SASL_MECHANISM) != null) {
434 return get(PROP_ML_DISTRIBUTION_SASL_MECHANISM);
436 return System.getenv().getOrDefault("SASL_MECHANISM", "SCRAM-SHA-512");
440 * One of PLAINTEXT, SSL, SASL_PLAINTEXT, SASL_SSL
443 public String getKafkaSecurityProtocolConfig() {
444 if(get(PROP_ML_DISTRIBUTION_SECURITY_PROTOCOL) != null) {
445 return get(PROP_ML_DISTRIBUTION_SECURITY_PROTOCOL);
447 return System.getenv().getOrDefault("SECURITY_PROTOCOL", "SASL_PLAINTEXT");