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.List;
28 import org.onap.sdc.api.consumer.IConfiguration;
29 import org.onap.so.utils.CryptoUtils;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.beans.factory.annotation.Value;
34 import org.springframework.core.env.Environment;
35 import org.springframework.stereotype.Component;
38 public class ASDCConfiguration implements IConfiguration {
40 // SHell command to obtain the same encryption, 128 bits key, key must be HEX
41 // echo -n "This is a test string" | openssl aes-128-ecb -e -K 546573746F736973546573746F736973
44 private static final Logger logger = LoggerFactory.getLogger(ASDCConfiguration.class);
46 private String asdcControllerName;
48 public static final String HEAT = "HEAT";
49 public static final String HEAT_ARTIFACT = "HEAT_ARTIFACT";
50 public static final String HEAT_ENV = "HEAT_ENV";
51 public static final String HEAT_NESTED = "HEAT_NESTED";
52 public static final String HEAT_NET = "HEAT_NET";
53 public static final String HEAT_VOL = "HEAT_VOL";
54 public static final String OTHER = "OTHER";
55 public static final String TOSCA_CSAR = "TOSCA_CSAR";
56 public static final String WORKFLOW = "WORKFLOW";
57 public static final String VF_MODULES_METADATA = "VF_MODULES_METADATA";
58 public static final String CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT = "CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT";
59 public static final String HELM = "HELM";
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, WORKFLOW, CLOUD_TECHNOLOGY_SPECIFIC_ARTIFACT, HELM};
66 public static final List<String> SUPPORTED_ARTIFACT_TYPES_LIST = List.of(SUPPORTED_ARTIFACT_TYPES);
69 private Environment env;
71 @Value("${mso.asdc.config.key}")
72 private String configKey;
74 public void setAsdcControllerName(String asdcControllerName) {
75 this.asdcControllerName = asdcControllerName;
79 public Boolean isUseHttpsWithSDC() {
80 return getBooleanPropertyWithDefault("mso.asdc-connections.asdc-controller1.useHttpsWithSdc", true);
84 public boolean isConsumeProduceStatusTopic() {
88 public String getAsdcControllerName() {
89 return asdcControllerName;
93 public String getConsumerGroup() {
94 return getPropertyOrNull("mso.asdc-connections.asdc-controller1.consumerGroup");
97 public int getWatchDogTimeout() {
98 return getIntegerPropertyOrZero("mso.asdc-connections.asdc-controller1.watchDogTimeout");
103 public String getConsumerID() {
104 return getPropertyOrNull("mso.asdc-connections.asdc-controller1.consumerId");
107 public int getIntegerPropertyOrZero(String propertyName) {
108 String property = env.getProperty(propertyName);
109 if (property == null || "NULL".equals(property) || property.isEmpty()) {
113 return Integer.parseInt(property);
114 } catch (NumberFormatException e) {
120 public String getPropertyOrNull(String propertyName) {
121 String config = env.getProperty(propertyName);
122 if (config == null || "NULL".equals(config) || config.isEmpty()) {
129 public String getEncryptedPropertyOrNull(String propertyName) {
131 String config = env.getProperty(propertyName);
133 if (config == null || "NULL".equals(config) || config.isEmpty()) {
138 decryptedKey = CryptoUtils.decrypt(config, this.configKey);
139 } catch (GeneralSecurityException e) {
140 logger.debug("Exception while decrypting property: {}", propertyName, e);
144 if (decryptedKey.isEmpty()) {
151 public boolean getBooleanPropertyWithDefault(String propertyName, boolean defaultValue) {
152 String config = env.getProperty(propertyName);
153 if (config == null || "NULL".equals(config) || config.isEmpty()) {
157 return Boolean.parseBoolean(config);
158 } catch (Exception e) {
159 logger.warn("Exception while getting boolean property with default property", e);
166 public String getEnvironmentName() {
167 return getPropertyOrNull("mso.asdc-connections.asdc-controller1.environmentName");
171 public String getPassword() {
172 return getEncryptedPropertyOrNull("mso.asdc-connections.asdc-controller1.password");
176 public int getPollingInterval() {
177 return getIntegerPropertyOrZero("mso.asdc-connections.asdc-controller1.pollingInterval");
181 public List<String> getRelevantArtifactTypes() {
182 // DO not return the Static List SUPPORTED_ARTIFACT_TYPES_LIST because the ASDC Client will
183 // try to modify it !!!
184 return Arrays.asList(SUPPORTED_ARTIFACT_TYPES);
188 public String getUser() {
189 return getPropertyOrNull("mso.asdc-connections.asdc-controller1.user");
193 public String getSdcAddress() {
194 return getPropertyOrNull("mso.asdc-connections.asdc-controller1.sdcAddress");
198 public int getPollingTimeout() {
199 return getIntegerPropertyOrZero("mso.asdc-connections.asdc-controller1.pollingTimeout");
203 public boolean activateServerTLSAuth() {
204 return getBooleanPropertyWithDefault("mso.asdc-connections.asdc-controller1.activateServerTLSAuth", true);
208 public String getKeyStorePassword() {
209 return getPropertyOrNull("mso.asdc-connections.asdc-controller1.keyStorePassword");
213 public String getKeyStorePath() {
214 return getPropertyOrNull("mso.asdc-connections.asdc-controller1.keyStorePath");
218 * The flag allows the client to receive metadata for all resources of the service regardless of the artifacts
219 * associated to them. Setting the flag to false will preserve legacy behavior.
222 public boolean isFilterInEmptyResources() {
223 return getBooleanPropertyWithDefault("mso.asdc-connections.asdc-controller1.isFilterInEmptyResources", true);
227 public String getHttpProxyHost() {
228 return getPropertyOrNull("mso.asdc-connections.asdc-controller1.httpProxyHost");
232 public int getHttpProxyPort() {
233 return getIntegerPropertyOrZero("mso.asdc-connections.asdc-controller1.httpProxyPort");
237 public String getHttpsProxyHost() {
238 return getPropertyOrNull("mso.asdc-connections.asdc-controller1.httpsProxyHost");
242 public int getHttpsProxyPort() {
243 return getIntegerPropertyOrZero("mso.asdc-connections.asdc-controller1.httpsProxyPort");