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;
24 import java.nio.file.Path;
25 import java.nio.file.Paths;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.List;
29 import java.util.Properties;
31 import org.apache.commons.lang3.StringUtils;
32 import org.eclipse.jetty.util.security.Password;
33 import org.onap.sdc.api.consumer.IConfiguration;
35 * Properties for the Model Loader
38 public class ModelLoaderConfig implements IConfiguration {
40 // Configuration file structure
41 public static final String PREFIX_MODEL_LOADER_CONFIG = "ml";
42 public static final String PREFIX_DISTRIBUTION_CLIENT = PREFIX_MODEL_LOADER_CONFIG + ".distribution.";
43 public static final String PREFIX_DEBUG = PREFIX_MODEL_LOADER_CONFIG + ".debug.";
45 private static final String SUFFIX_KEYSTORE_FILE = "KEYSTORE_FILE";
46 private static final String SUFFIX_KEYSTORE_PASS = "KEYSTORE_PASSWORD";
48 // Configuration file properties
49 protected static final String PROP_ML_DISTRIBUTION_ACTIVE_SERVER_TLS_AUTH =
50 PREFIX_DISTRIBUTION_CLIENT + "ACTIVE_SERVER_TLS_AUTH";
51 protected static final String PROP_ML_DISTRIBUTION_ASDC_CONNECTION_DISABLED =
52 PREFIX_DISTRIBUTION_CLIENT + "ASDC_CONNECTION_DISABLE";
53 protected static final String PROP_ML_DISTRIBUTION_ASDC_ADDRESS = PREFIX_DISTRIBUTION_CLIENT + "ASDC_ADDRESS";
54 protected static final String PROP_ML_DISTRIBUTION_ASDC_USE_HTTPS = PREFIX_DISTRIBUTION_CLIENT + "ASDC_USE_HTTPS";
55 protected static final String PROP_ML_DISTRIBUTION_CONSUMER_GROUP = PREFIX_DISTRIBUTION_CLIENT + "CONSUMER_GROUP";
56 protected static final String PROP_ML_DISTRIBUTION_CONSUMER_ID = PREFIX_DISTRIBUTION_CLIENT + "CONSUMER_ID";
57 protected static final String PROP_ML_DISTRIBUTION_ENVIRONMENT_NAME =
58 PREFIX_DISTRIBUTION_CLIENT + "ENVIRONMENT_NAME";
59 protected static final String PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD =
60 PREFIX_DISTRIBUTION_CLIENT + SUFFIX_KEYSTORE_PASS;
61 protected static final String PROP_ML_DISTRIBUTION_KEYSTORE_FILE =
62 PREFIX_DISTRIBUTION_CLIENT + SUFFIX_KEYSTORE_FILE;
63 protected static final String PROP_ML_DISTRIBUTION_PASSWORD = PREFIX_DISTRIBUTION_CLIENT + "PASSWORD";
64 protected static final String PROP_ML_DISTRIBUTION_POLLING_INTERVAL =
65 PREFIX_DISTRIBUTION_CLIENT + "POLLING_INTERVAL";
66 protected static final String PROP_ML_DISTRIBUTION_POLLING_TIMEOUT = PREFIX_DISTRIBUTION_CLIENT + "POLLING_TIMEOUT";
67 protected static final String PROP_ML_DISTRIBUTION_USER = PREFIX_DISTRIBUTION_CLIENT + "USER";
68 protected static final String PROP_ML_DISTRIBUTION_ARTIFACT_TYPES = PREFIX_DISTRIBUTION_CLIENT + "ARTIFACT_TYPES";
69 protected static final String PROP_ML_DISTRIBUTION_HTTP_PROXY_HOST = PREFIX_DISTRIBUTION_CLIENT + "HTTP_PROXY_HOST";
70 protected static final String PROP_ML_DISTRIBUTION_HTTP_PROXY_PORT = PREFIX_DISTRIBUTION_CLIENT + "HTTP_PROXY_PORT";
71 protected static final String PROP_ML_DISTRIBUTION_HTTPS_PROXY_HOST = PREFIX_DISTRIBUTION_CLIENT + "HTTPS_PROXY_HOST";
72 protected static final String PROP_ML_DISTRIBUTION_HTTPS_PROXY_PORT = PREFIX_DISTRIBUTION_CLIENT + "HTTPS_PROXY_PORT";
73 protected static final String PROP_ML_DISTRIBUTION_SASL_JAAS_CONFIG = PREFIX_DISTRIBUTION_CLIENT + "SASL_JAAS_CONFIG";
74 protected static final String PROP_ML_DISTRIBUTION_SASL_MECHANISM = PREFIX_DISTRIBUTION_CLIENT + "SASL_MECHANISM";
75 protected static final String PROP_ML_DISTRIBUTION_SECURITY_PROTOCOL = PREFIX_DISTRIBUTION_CLIENT + "SECURITY_PROTOCOL";
76 protected static final String PROP_DEBUG_INGEST_SIMULATOR = PREFIX_DEBUG + "INGEST_SIMULATOR";
77 protected static final String FILESEP =
78 (System.getProperty("file.separator") == null) ? "/" : System.getProperty("file.separator");
79 private static String configHome;
80 private Properties modelLoaderProperties = null;
81 private String certLocation = ".";
82 private final List<String> artifactTypes = new ArrayList<>();
83 private String modelVersion = null;
85 public ModelLoaderConfig(Properties configProperties) {
86 this(configProperties, ModelLoaderConfig.configHome + FILESEP + "auth" + FILESEP);
90 * Original constructor
92 * @param modelLoaderProperties
93 * properties needed to be configured for the model loader
95 * location of the certificate
97 public ModelLoaderConfig(Properties modelLoaderProperties, String certLocation) {
98 this.modelLoaderProperties = modelLoaderProperties;
99 this.certLocation = certLocation;
101 // Get list of artifact types
102 String types = get(PROP_ML_DISTRIBUTION_ARTIFACT_TYPES);
104 artifactTypes.addAll(Arrays.asList(types.split(",")));
108 public static void setConfigHome(String configHome) {
109 ModelLoaderConfig.configHome = configHome;
112 public static Path propertiesFile() {
113 return Paths.get(configHome, "model-loader.properties");
117 public boolean activateServerTLSAuth() {
118 String value = get(PROP_ML_DISTRIBUTION_ACTIVE_SERVER_TLS_AUTH);
119 return Boolean.parseBoolean(value);
123 public String getSdcAddress() {
124 return get(PROP_ML_DISTRIBUTION_ASDC_ADDRESS);
128 public Boolean isUseHttpsWithSDC() {
129 /* if PROP_ML_DISTRIBUTION_ASDC_USE_HTTPS is null, https will be used, as before */
130 String value = get(PROP_ML_DISTRIBUTION_ASDC_USE_HTTPS);
134 return Boolean.parseBoolean(value);
138 public String getConsumerGroup() {
139 return get(PROP_ML_DISTRIBUTION_CONSUMER_GROUP);
143 public String getConsumerID() {
144 return get(PROP_ML_DISTRIBUTION_CONSUMER_ID);
148 public String getEnvironmentName() {
149 return get(PROP_ML_DISTRIBUTION_ENVIRONMENT_NAME);
153 public String getKeyStorePassword() {
154 return getDeobfuscatedValue(get(PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD));
158 public String getKeyStorePath() {
159 return certLocation + get(PROP_ML_DISTRIBUTION_KEYSTORE_FILE);
163 public String getPassword() {
164 return getDeobfuscatedValue(get(PROP_ML_DISTRIBUTION_PASSWORD));
168 public int getPollingInterval() {
169 return Integer.parseInt(get(PROP_ML_DISTRIBUTION_POLLING_INTERVAL));
173 public int getPollingTimeout() {
174 return Integer.parseInt(get(PROP_ML_DISTRIBUTION_POLLING_TIMEOUT));
178 public List<String> getRelevantArtifactTypes() {
179 return artifactTypes;
183 public String getUser() {
184 return get(PROP_ML_DISTRIBUTION_USER);
188 public boolean isFilterInEmptyResources() {
193 public String getHttpProxyHost() {
194 return getPropertyOrNull(PROP_ML_DISTRIBUTION_HTTP_PROXY_HOST);
198 public int getHttpProxyPort() {
199 return getIntegerPropertyOrZero(PROP_ML_DISTRIBUTION_HTTP_PROXY_PORT);
203 public String getHttpsProxyHost() {
204 return getPropertyOrNull(PROP_ML_DISTRIBUTION_HTTPS_PROXY_HOST);
208 public int getHttpsProxyPort() {
209 return getIntegerPropertyOrZero(PROP_ML_DISTRIBUTION_HTTPS_PROXY_PORT);
213 public String getModelVersion() {
217 public void setModelVersion(String modelVersion) {
218 this.modelVersion = modelVersion;
222 * @return a boolean value indicating whether the simulator is enabled.
224 public boolean getIngestSimulatorEnabled() {
225 String propValue = get(PROP_DEBUG_INGEST_SIMULATOR);
226 return propValue != null && "enabled".equalsIgnoreCase(propValue);
230 * @return a boolean value indicating whether model loader is connected to ASDC.
232 public boolean getASDCConnectionDisabled() {
233 String propValue = get(PROP_ML_DISTRIBUTION_ASDC_CONNECTION_DISABLED);
234 return propValue != null && "true".equalsIgnoreCase(propValue);
237 private String getDeobfuscatedValue(String property) {
238 if (property != null && property.startsWith("OBF:")) {
239 return Password.deobfuscate(property);
244 private String get(String key) {
245 String value = modelLoaderProperties.getProperty(key);
247 if (value != null && value.startsWith("ENV:")) {
248 value = System.getenv(StringUtils.removeStart(value, "ENV:"));
253 public String getPropertyOrNull(String propertyName) {
254 String value = modelLoaderProperties.getProperty(propertyName);
255 if (value == null || "NULL".equals(value) || value.isEmpty()) {
262 public int getIntegerPropertyOrZero(String propertyName) {
263 String property = modelLoaderProperties.getProperty(propertyName);
264 if (property == null || "NULL".equals(property) || property.isEmpty()) {
268 return Integer.parseInt(property);
269 } catch (NumberFormatException e) {
276 public String getKafkaSaslJaasConfig() {
277 String saslJaasConfFromEnv = System.getenv("SASL_JAAS_CONFIG");
278 if(saslJaasConfFromEnv != null) {
279 return saslJaasConfFromEnv;
281 if(get(PROP_ML_DISTRIBUTION_SASL_JAAS_CONFIG) != null) {
282 return get(PROP_ML_DISTRIBUTION_SASL_JAAS_CONFIG);
288 public String getKafkaSaslMechanism() {
289 if(get(PROP_ML_DISTRIBUTION_SASL_MECHANISM) != null) {
290 return get(PROP_ML_DISTRIBUTION_SASL_MECHANISM);
292 return System.getenv().getOrDefault("SASL_MECHANISM", "SCRAM-SHA-512");
296 * One of PLAINTEXT, SSL, SASL_PLAINTEXT, SASL_SSL
299 public String getKafkaSecurityProtocolConfig() {
300 if(get(PROP_ML_DISTRIBUTION_SECURITY_PROTOCOL) != null) {
301 return get(PROP_ML_DISTRIBUTION_SECURITY_PROTOCOL);
303 return System.getenv().getOrDefault("SECURITY_PROTOCOL", "SASL_PLAINTEXT");