2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.modelloader.config;
23 import org.eclipse.jetty.util.security.Password;
24 import org.openecomp.sdc.api.consumer.IConfiguration;
28 import java.util.ArrayList;
29 import java.util.List;
30 import java.util.Properties;
32 public class ModelLoaderConfig implements IConfiguration {
34 // Configuration file structure
35 public static final String PREFIX_MODEL_LOADER_CONFIG = "ml";
36 public static final String PREFIX_DISTRIBUTION_CLIENT =
37 PREFIX_MODEL_LOADER_CONFIG + ".distribution.";
38 public static final String PREFIX_AAI = PREFIX_MODEL_LOADER_CONFIG + ".aai.";
39 public static final String PREFIX_DEBUG = PREFIX_MODEL_LOADER_CONFIG + ".debug.";
41 // Configuration file properties
42 protected static final String PROP_ML_DISTRIBUTION_ACTIVE_SERVER_TLS_AUTH =
43 PREFIX_DISTRIBUTION_CLIENT + "ACTIVE_SERVER_TLS_AUTH";
44 protected static final String PROP_ML_DISTRIBUTION_ASDC_ADDRESS = PREFIX_DISTRIBUTION_CLIENT
46 protected static final String PROP_ML_DISTRIBUTION_CONSUMER_GROUP = PREFIX_DISTRIBUTION_CLIENT
48 protected static final String PROP_ML_DISTRIBUTION_CONSUMER_ID = PREFIX_DISTRIBUTION_CLIENT
50 protected static final String PROP_ML_DISTRIBUTION_ENVIRONMENT_NAME = PREFIX_DISTRIBUTION_CLIENT
52 protected static final String PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD = PREFIX_DISTRIBUTION_CLIENT
53 + "KEYSTORE_PASSWORD";
54 protected static final String PROP_ML_DISTRIBUTION_KEYSTORE_FILE = PREFIX_DISTRIBUTION_CLIENT
56 protected static final String PROP_ML_DISTRIBUTION_PASSWORD = PREFIX_DISTRIBUTION_CLIENT
58 protected static final String PROP_ML_DISTRIBUTION_POLLING_INTERVAL = PREFIX_DISTRIBUTION_CLIENT
60 protected static final String PROP_ML_DISTRIBUTION_POLLING_TIMEOUT = PREFIX_DISTRIBUTION_CLIENT
62 protected static final String PROP_ML_DISTRIBUTION_USER = PREFIX_DISTRIBUTION_CLIENT + "USER";
63 protected static final String PROP_ML_DISTRIBUTION_ARTIFACT_TYPES = PREFIX_DISTRIBUTION_CLIENT
66 protected static final String PROP_AAI_BASE_URL = PREFIX_AAI + "BASE_URL";
67 protected static final String PROP_AAI_KEYSTORE_FILE = PREFIX_AAI + "KEYSTORE_FILE";
68 protected static final String PROP_AAI_KEYSTORE_PASSWORD = PREFIX_AAI + "KEYSTORE_PASSWORD";
69 protected static final String PROP_AAI_MODEL_RESOURCE_URL = PREFIX_AAI + "MODEL_URL";
70 protected static final String PROP_AAI_NAMED_QUERY_RESOURCE_URL = PREFIX_AAI + "NAMED_QUERY_URL";
71 protected static final String PROP_AAI_VNF_IMAGE_RESOURCE_URL = PREFIX_AAI + "VNF_IMAGE_URL";
72 protected static final String PROP_AAI_AUTHENTICATION_USER = PREFIX_AAI + "AUTH_USER";
73 protected static final String PROP_AAI_AUTHENTICATION_PASSWORD = PREFIX_AAI + "AUTH_PASSWORD";
75 protected static final String PROP_DEBUG_INGEST_SIMULATOR = PREFIX_DEBUG + "INGEST_SIMULATOR";
77 private Properties modelLoaderProperties = null;
79 private String certLocation = ".";
81 private List<String> artifactTypes = null;
84 * This is the class constructor.
86 * @param modelLoaderProperties properties needed to be configured for the model loader
87 * @param certLocation location of the certificate
89 public ModelLoaderConfig(Properties modelLoaderProperties) {
90 this.modelLoaderProperties = modelLoaderProperties;
92 String aaiKeystoreFile = modelLoaderProperties.getProperty(PROP_AAI_KEYSTORE_FILE);
93 if(aaiKeystoreFile != null){
94 URL keystoreURL = this.getClass().getClassLoader().getResource(aaiKeystoreFile);
95 if(keystoreURL != null){
96 File fKeystoreLocation = new File(keystoreURL.getPath());
97 this.certLocation = fKeystoreLocation.getParent();
101 // Get list of artifacts
102 artifactTypes = new ArrayList<String>();
103 if (modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_ARTIFACT_TYPES) != null) {
104 String[] artTypeList = modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_ARTIFACT_TYPES)
106 for (String artType : artTypeList) {
107 artifactTypes.add(artType);
113 public boolean activateServerTLSAuth() {
114 String value = modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_ACTIVE_SERVER_TLS_AUTH);
115 return value == null ? false : Boolean.parseBoolean(value);
119 public String getAsdcAddress() {
120 return modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_ASDC_ADDRESS);
124 public String getConsumerGroup() {
125 return modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_CONSUMER_GROUP);
129 public String getConsumerID() {
130 return modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_CONSUMER_ID);
134 public String getEnvironmentName() {
135 return modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_ENVIRONMENT_NAME);
139 public String getKeyStorePassword() {
141 .deobfuscate(modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD));
145 public String getKeyStorePath() {
146 return certLocation + modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_KEYSTORE_FILE);
150 public String getPassword() {
151 return Password.deobfuscate(modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_PASSWORD));
155 public int getPollingInterval() {
157 .parseInt(modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_POLLING_INTERVAL));
161 public int getPollingTimeout() {
163 .parseInt(modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_POLLING_TIMEOUT));
167 public List<String> getRelevantArtifactTypes() {
168 return artifactTypes;
172 public String getUser() {
173 return modelLoaderProperties.getProperty(PROP_ML_DISTRIBUTION_USER);
176 public String getAaiKeyStorePath() {
177 return certLocation + "/" + modelLoaderProperties.getProperty(PROP_AAI_KEYSTORE_FILE);
180 public String getAaiKeyStorePassword() {
181 return Password.deobfuscate(modelLoaderProperties.getProperty(PROP_AAI_KEYSTORE_PASSWORD));
184 public String getAaiBaseUrl() {
185 return modelLoaderProperties.getProperty(PROP_AAI_BASE_URL);
188 public String getAaiModelUrl() {
189 return modelLoaderProperties.getProperty(PROP_AAI_MODEL_RESOURCE_URL);
192 public String getAaiNamedQueryUrl() {
193 return modelLoaderProperties.getProperty(PROP_AAI_NAMED_QUERY_RESOURCE_URL);
196 public String getAaiVnfImageUrl() {
197 return modelLoaderProperties.getProperty(PROP_AAI_VNF_IMAGE_RESOURCE_URL);
200 public String getAaiAuthenticationUser() {
201 return modelLoaderProperties.getProperty(PROP_AAI_AUTHENTICATION_USER);
205 * @return password for AAI authentication that has been reverse-engineered
206 * from its obfuscated form.
208 public String getAaiAuthenticationPassword() {
209 String password = Password
210 .deobfuscate(modelLoaderProperties.getProperty(PROP_AAI_AUTHENTICATION_PASSWORD));
212 if ((password != null) && (password.equals(""))) {
220 * @return a boolean value indicating whether the simulator is enabled.
222 public boolean getIngestSimulatorEnabled() {
223 String propValue = modelLoaderProperties.getProperty(PROP_DEBUG_INGEST_SIMULATOR);
225 if (propValue == null) {
229 if (propValue.compareToIgnoreCase("enabled") == 0) {