2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.asdc.client;
26 import java.security.GeneralSecurityException;
27 import java.util.Arrays;
28 import java.util.Collections;
29 import java.util.List;
30 import org.onap.sdc.api.consumer.IConfiguration;
31 import org.onap.so.utils.CryptoUtils;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.beans.factory.annotation.Value;
36 import org.springframework.core.env.Environment;
37 import org.springframework.stereotype.Component;
40 public class ASDCConfiguration implements IConfiguration {
42 // SHell command to obtain the same encryption, 128 bits key, key must be HEX
43 // echo -n "This is a test string" | openssl aes-128-ecb -e -K 546573746F736973546573746F736973 -nosalt | xxd
45 private static Logger logger = LoggerFactory.getLogger(ASDCConfiguration.class);
48 private String asdcControllerName;
50 public static final String HEAT = "HEAT";
51 public static final String HEAT_ARTIFACT = "HEAT_ARTIFACT";
52 public static final String HEAT_ENV = "HEAT_ENV";
53 public static final String HEAT_NESTED = "HEAT_NESTED";
54 public static final String HEAT_NET = "HEAT_NET";
55 public static final String HEAT_VOL = "HEAT_VOL";
56 public static final String OTHER = "OTHER";
57 public static final String TOSCA_CSAR = "TOSCA_CSAR";
58 public static final String WORKFLOW = "WORKFLOW";
59 public static final String VF_MODULES_METADATA = "VF_MODULES_METADATA";
60 public static final String CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT = "CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT";
62 private static final String[] SUPPORTED_ARTIFACT_TYPES = {HEAT, HEAT_ARTIFACT, HEAT_ENV, HEAT_NESTED, HEAT_NET,
63 HEAT_VOL, OTHER, TOSCA_CSAR, VF_MODULES_METADATA, CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT, WORKFLOW};
65 public static final List<String> SUPPORTED_ARTIFACT_TYPES_LIST =
66 Collections.unmodifiableList(Arrays.asList(SUPPORTED_ARTIFACT_TYPES));
69 private Environment env;
71 @Value("${mso.asdc.config.key}")
72 private String configKey;
74 @Value("${mso.asdc-connections.asdc-controller1.messageBusAddress}")
75 private String[] messageBusAddress;
78 public void setAsdcControllerName(String asdcControllerName) {
79 this.asdcControllerName = asdcControllerName;
83 public java.lang.Boolean isUseHttpsWithDmaap() {
84 return getBooleanPropertyWithDefault("mso.asdc-connections.asdc-controller1.useHttpsWithDmaap", true);
88 public boolean isConsumeProduceStatusTopic() {
93 public List<String> getMsgBusAddress() {
94 if (messageBusAddress.length > 0) {
95 return Arrays.asList(messageBusAddress);
97 return Collections.emptyList();
103 public String getAsdcControllerName() {
104 return asdcControllerName;
109 public String getConsumerGroup() {
110 return getPropertyOrNull("mso.asdc-connections.asdc-controller1.consumerGroup");
113 public int getWatchDogTimeout() {
114 return getIntegerPropertyOrZero("mso.asdc-connections.asdc-controller1.watchDogTimeout");
119 public String getConsumerID() {
120 return getPropertyOrNull("mso.asdc-connections.asdc-controller1.consumerId");
123 public int getIntegerPropertyOrZero(String propertyName) {
124 String property = env.getProperty(propertyName);
125 if (property == null || "NULL".equals(property) || property.isEmpty()) {
129 return Integer.parseInt(property);
130 } catch (NumberFormatException e) {
136 public String getPropertyOrNull(String propertyName) {
137 String config = env.getProperty(propertyName);
138 if (config == null || "NULL".equals(config) || config.isEmpty()) {
145 public String getEncryptedPropertyOrNull(String propertyName) {
147 String config = env.getProperty(propertyName);
149 if (config == null || "NULL".equals(config) || config.isEmpty()) {
154 decryptedKey = CryptoUtils.decrypt(config, this.configKey);
155 } catch (GeneralSecurityException e) {
156 logger.debug("Exception while decrypting property: {}", propertyName, e);
160 if (decryptedKey.isEmpty()) {
167 public boolean getBooleanPropertyWithDefault(String propertyName, boolean defaultValue) {
168 String config = env.getProperty(propertyName);
169 if (config == null || "NULL".equals(config) || config.isEmpty()) {
173 return Boolean.valueOf(config);
174 } catch (Exception e) {
181 public String getEnvironmentName() {
182 return getPropertyOrNull("mso.asdc-connections.asdc-controller1.environmentName");
186 public String getPassword() {
187 return getEncryptedPropertyOrNull("mso.asdc-connections.asdc-controller1.password");
191 public int getPollingInterval() {
192 return getIntegerPropertyOrZero("mso.asdc-connections.asdc-controller1.pollingInterval");
196 public List<String> getRelevantArtifactTypes() {
197 // DO not return the Static List SUPPORTED_ARTIFACT_TYPES_LIST because the ASDC Client will try to modify it !!!
198 return Arrays.asList(SUPPORTED_ARTIFACT_TYPES);
202 public String getUser() {
203 return getPropertyOrNull("mso.asdc-connections.asdc-controller1.user");
207 public String getAsdcAddress() {
208 return getPropertyOrNull("mso.asdc-connections.asdc-controller1.asdcAddress");
212 public int getPollingTimeout() {
213 return getIntegerPropertyOrZero("mso.asdc-connections.asdc-controller1.pollingTimeout");
217 public boolean activateServerTLSAuth() {
218 return getBooleanPropertyWithDefault("mso.asdc-connections.asdc-controller1.activateServerTLSAuth", true);
222 public String getKeyStorePassword() {
223 return getPropertyOrNull("mso.asdc-connections.asdc-controller1.keyStorePassword");
227 public String getKeyStorePath() {
228 return getPropertyOrNull("mso.asdc-connections.asdc-controller1.keyStorePath");
232 * The flag allows the client to receive metadata for all resources of the service regardless of the artifacts
233 * associated to them. Setting the flag to false will preserve legacy behavior.
236 public boolean isFilterInEmptyResources() {
237 return getBooleanPropertyWithDefault("mso.asdc-connections.asdc-controller1.isFilterInEmptyResources", true);