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;
25 import java.security.GeneralSecurityException;
26 import java.util.Arrays;
27 import java.util.Collections;
28 import java.util.List;
29 import org.onap.sdc.api.consumer.IConfiguration;
30 import org.onap.so.utils.CryptoUtils;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.beans.factory.annotation.Value;
35 import org.springframework.core.env.Environment;
36 import org.springframework.stereotype.Component;
39 public class ASDCConfiguration implements IConfiguration {
41 // SHell command to obtain the same encryption, 128 bits key, key must be HEX
42 // echo -n "This is a test string" | openssl aes-128-ecb -e -K 546573746F736973546573746F736973
45 private static Logger logger = LoggerFactory.getLogger(ASDCConfiguration.class);
47 private String asdcControllerName;
49 public static final String HEAT = "HEAT";
50 public static final String HEAT_ARTIFACT = "HEAT_ARTIFACT";
51 public static final String HEAT_ENV = "HEAT_ENV";
52 public static final String HEAT_NESTED = "HEAT_NESTED";
53 public static final String HEAT_NET = "HEAT_NET";
54 public static final String HEAT_VOL = "HEAT_VOL";
55 public static final String OTHER = "OTHER";
56 public static final String TOSCA_CSAR = "TOSCA_CSAR";
57 public static final String WORKFLOW = "WORKFLOW";
58 public static final String VF_MODULES_METADATA = "VF_MODULES_METADATA";
59 public static final String CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT = "CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT";
60 public static final String HELM = "HELM";
63 private static final String[] SUPPORTED_ARTIFACT_TYPES = {HEAT, HEAT_ARTIFACT, HEAT_ENV, HEAT_NESTED, HEAT_NET,
64 HEAT_VOL, OTHER, TOSCA_CSAR, VF_MODULES_METADATA, WORKFLOW, CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT, HELM};
67 public static final List<String> SUPPORTED_ARTIFACT_TYPES_LIST =
68 Collections.unmodifiableList(Arrays.asList(SUPPORTED_ARTIFACT_TYPES));
71 private Environment env;
73 @Value("${mso.asdc.config.key}")
74 private String configKey;
76 @Value("${mso.asdc-connections.asdc-controller1.messageBusAddress}")
77 private String[] messageBusAddress;
79 public void setAsdcControllerName(String asdcControllerName) {
80 this.asdcControllerName = asdcControllerName;
84 public java.lang.Boolean isUseHttpsWithDmaap() {
85 return getBooleanPropertyWithDefault("mso.asdc-connections.asdc-controller1.useHttpsWithDmaap", true);
89 public java.lang.Boolean isUseHttpsWithSDC() {
90 return getBooleanPropertyWithDefault("mso.asdc-connections.asdc-controller1.useHttpsWithSdc", true);
94 public boolean isConsumeProduceStatusTopic() {
99 public List<String> getMsgBusAddress() {
100 if (messageBusAddress.length > 0) {
101 return Arrays.asList(messageBusAddress);
103 return Collections.emptyList();
107 public String getAsdcControllerName() {
108 return asdcControllerName;
112 public String getConsumerGroup() {
113 return getPropertyOrNull("mso.asdc-connections.asdc-controller1.consumerGroup");
116 public int getWatchDogTimeout() {
117 return getIntegerPropertyOrZero("mso.asdc-connections.asdc-controller1.watchDogTimeout");
122 public String getConsumerID() {
123 return getPropertyOrNull("mso.asdc-connections.asdc-controller1.consumerId");
126 public int getIntegerPropertyOrZero(String propertyName) {
127 String property = env.getProperty(propertyName);
128 if (property == null || "NULL".equals(property) || property.isEmpty()) {
132 return Integer.parseInt(property);
133 } catch (NumberFormatException e) {
139 public String getPropertyOrNull(String propertyName) {
140 String config = env.getProperty(propertyName);
141 if (config == null || "NULL".equals(config) || config.isEmpty()) {
148 public String getEncryptedPropertyOrNull(String propertyName) {
150 String config = env.getProperty(propertyName);
152 if (config == null || "NULL".equals(config) || config.isEmpty()) {
157 decryptedKey = CryptoUtils.decrypt(config, this.configKey);
158 } catch (GeneralSecurityException e) {
159 logger.debug("Exception while decrypting property: {}", propertyName, e);
163 if (decryptedKey.isEmpty()) {
170 public boolean getBooleanPropertyWithDefault(String propertyName, boolean defaultValue) {
171 String config = env.getProperty(propertyName);
172 if (config == null || "NULL".equals(config) || config.isEmpty()) {
176 return Boolean.valueOf(config);
177 } catch (Exception e) {
178 logger.warn("Exception while getting boolean property with default property", e);
185 public String getEnvironmentName() {
186 return getPropertyOrNull("mso.asdc-connections.asdc-controller1.environmentName");
190 public String getPassword() {
191 return getEncryptedPropertyOrNull("mso.asdc-connections.asdc-controller1.password");
195 public int getPollingInterval() {
196 return getIntegerPropertyOrZero("mso.asdc-connections.asdc-controller1.pollingInterval");
200 public List<String> getRelevantArtifactTypes() {
201 // DO not return the Static List SUPPORTED_ARTIFACT_TYPES_LIST because the ASDC Client will
202 // try to modify it !!!
203 return Arrays.asList(SUPPORTED_ARTIFACT_TYPES);
207 public String getUser() {
208 return getPropertyOrNull("mso.asdc-connections.asdc-controller1.user");
212 public String getAsdcAddress() {
213 return getPropertyOrNull("mso.asdc-connections.asdc-controller1.asdcAddress");
217 public int getPollingTimeout() {
218 return getIntegerPropertyOrZero("mso.asdc-connections.asdc-controller1.pollingTimeout");
222 public boolean activateServerTLSAuth() {
223 return getBooleanPropertyWithDefault("mso.asdc-connections.asdc-controller1.activateServerTLSAuth", true);
227 public String getKeyStorePassword() {
228 return getPropertyOrNull("mso.asdc-connections.asdc-controller1.keyStorePassword");
232 public String getKeyStorePath() {
233 return getPropertyOrNull("mso.asdc-connections.asdc-controller1.keyStorePath");
237 * The flag allows the client to receive metadata for all resources of the service regardless of the artifacts
238 * associated to them. Setting the flag to false will preserve legacy behavior.
241 public boolean isFilterInEmptyResources() {
242 return getBooleanPropertyWithDefault("mso.asdc-connections.asdc-controller1.isFilterInEmptyResources", true);