2 * ========================LICENSE_START=================================
4 * ======================================================================
5 * Copyright (C) 2019-2020 Nordix Foundation. 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.onap.ccsdk.oran.a1policymanagementservice.configuration;
23 import com.google.common.base.Strings;
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.HashMap;
33 import org.onap.ccsdk.oran.a1policymanagementservice.configuration.WebClientConfig.HttpProxyConfig;
34 import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException;
35 import org.springframework.beans.factory.annotation.Value;
36 import org.springframework.boot.context.properties.EnableConfigurationProperties;
38 import reactor.core.publisher.Flux;
39 import reactor.netty.transport.ProxyProvider;
41 @EnableConfigurationProperties
42 public class ApplicationConfig {
45 @Value("${app.filepath}")
46 private String localConfigurationFilePath;
49 @Value("${app.config-file-schema-path:}")
50 private String configurationFileSchemaPath;
53 @Value("${app.vardata-directory:null}")
54 private String vardataDirectory;
56 @Value("${server.ssl.key-store-type}")
57 private String sslKeyStoreType = "";
59 @Value("${server.ssl.key-store-password}")
60 private String sslKeyStorePassword = "";
62 @Value("${server.ssl.key-store}")
63 private String sslKeyStore = "";
65 @Value("${server.ssl.key-password}")
66 private String sslKeyPassword = "";
68 @Value("${app.webclient.trust-store-used}")
69 private boolean sslTrustStoreUsed = false;
71 @Value("${app.webclient.trust-store-password}")
72 private String sslTrustStorePassword = "";
74 @Value("${app.webclient.trust-store}")
75 private String sslTrustStore = "";
77 @Value("${app.webclient.http.proxy-host:}")
78 private String httpProxyHost = "";
80 @Value("${app.webclient.http.proxy-port:0}")
81 private int httpProxyPort = 0;
83 @Value("${app.webclient.http.proxy-type:HTTP}")
84 private String httpProxyType = "HTTP";
87 @Value("${app.s3.endpointOverride:}")
88 private String s3EndpointOverride;
91 @Value("${app.s3.accessKeyId:}")
92 private String s3AccessKeyId;
95 @Value("${app.s3.secretAccessKey:}")
96 private String s3SecretAccessKey;
99 @Value("${app.s3.bucket:}")
100 private String s3Bucket;
104 @Value("${app.authorization-provider:}")
105 private String authProviderUrl;
107 private Map<String, RicConfig> ricConfigs = new HashMap<>();
109 private WebClientConfig webClientConfig = null;
111 public synchronized Collection<RicConfig> getRicConfigs() {
112 return this.ricConfigs.values();
115 public WebClientConfig getWebClientConfig() {
116 if (this.webClientConfig == null) {
117 HttpProxyConfig httpProxyConfig = HttpProxyConfig.builder() //
118 .httpProxyHost(this.httpProxyHost) //
119 .httpProxyPort(this.httpProxyPort) //
120 .httpProxyType(ProxyProvider.Proxy.valueOf(this.httpProxyType)) //
123 this.webClientConfig = WebClientConfig.builder() //
124 .keyStoreType(this.sslKeyStoreType) //
125 .keyStorePassword(this.sslKeyStorePassword) //
126 .keyStore(this.sslKeyStore) //
127 .keyPassword(this.sslKeyPassword) //
128 .isTrustStoreUsed(this.sslTrustStoreUsed) //
129 .trustStore(this.sslTrustStore) //
130 .trustStorePassword(this.sslTrustStorePassword) //
131 .httpProxyConfig(httpProxyConfig) //
134 return this.webClientConfig;
137 public synchronized RicConfig getRic(String ricId) throws ServiceException {
138 RicConfig ricConfig = this.ricConfigs.get(ricId);
139 if (ricConfig == null) {
140 throw new ServiceException("Could not find ric configuration: " + ricId);
145 public static class RicConfigUpdate {
147 ADDED, CHANGED, REMOVED
151 private final RicConfig ricConfig;
153 private final Type type;
155 public RicConfigUpdate(RicConfig config, Type event) {
156 this.ricConfig = config;
161 public synchronized Flux<RicConfigUpdate> setConfiguration(
162 ApplicationConfigParser.ConfigParserResult parserResult) {
164 Collection<RicConfigUpdate> modifications = new ArrayList<>();
166 Map<String, RicConfig> newRicConfigs = new HashMap<>();
167 for (RicConfig newConfig : parserResult.getRicConfigs()) {
168 RicConfig oldConfig = this.ricConfigs.get(newConfig.getRicId());
169 this.ricConfigs.remove(newConfig.getRicId());
170 if (oldConfig == null) {
171 newRicConfigs.put(newConfig.getRicId(), newConfig);
172 modifications.add(new RicConfigUpdate(newConfig, RicConfigUpdate.Type.ADDED));
173 } else if (!newConfig.equals(oldConfig)) {
174 modifications.add(new RicConfigUpdate(newConfig, RicConfigUpdate.Type.CHANGED));
175 newRicConfigs.put(newConfig.getRicId(), newConfig);
177 newRicConfigs.put(oldConfig.getRicId(), oldConfig);
180 for (RicConfig deletedConfig : this.ricConfigs.values()) {
181 modifications.add(new RicConfigUpdate(deletedConfig, RicConfigUpdate.Type.REMOVED));
183 this.ricConfigs = newRicConfigs;
185 return Flux.fromIterable(modifications);
188 public boolean isS3Enabled() {
189 return !(Strings.isNullOrEmpty(s3EndpointOverride) || Strings.isNullOrEmpty(s3Bucket));