2 * ========================LICENSE_START=================================
4 * ======================================================================
5 * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved.
6 * Copyright (C) 2023-2024 OpenInfra Foundation Europe. All rights reserved.
7 * ======================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ========================LICENSE_END===================================
22 package org.onap.ccsdk.oran.a1policymanagementservice.configuration;
24 import com.google.common.base.Strings;
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.HashMap;
34 import org.onap.ccsdk.oran.a1policymanagementservice.configuration.WebClientConfig.HttpProxyConfig;
35 import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException;
36 import org.springframework.beans.factory.annotation.Value;
37 import org.springframework.boot.context.properties.EnableConfigurationProperties;
39 import reactor.core.publisher.Flux;
40 import reactor.netty.transport.ProxyProvider;
42 @EnableConfigurationProperties
43 public class ApplicationConfig {
46 @Value("${app.filepath}")
47 private String localConfigurationFilePath;
50 @Value("${app.config-file-schema-path:}")
51 private String configurationFileSchemaPath;
54 @Value("${app.vardata-directory:null}")
55 private String vardataDirectory;
57 @Value("${server.ssl.key-store-type}")
58 private String sslKeyStoreType = "";
60 @Value("${server.ssl.key-store-password}")
61 private String sslKeyStorePassword = "";
63 @Value("${server.ssl.key-store}")
64 private String sslKeyStore = "";
66 @Value("${server.ssl.key-password}")
67 private String sslKeyPassword = "";
69 @Value("${app.webclient.trust-store-used}")
70 private boolean sslTrustStoreUsed = false;
72 @Value("${app.webclient.trust-store-password}")
73 private String sslTrustStorePassword = "";
75 @Value("${app.webclient.trust-store}")
76 private String sslTrustStore = "";
78 @Value("${app.webclient.http.proxy-host:}")
79 private String httpProxyHost = "";
81 @Value("${app.webclient.http.proxy-port:0}")
82 private int httpProxyPort = 0;
84 @Value("${app.webclient.http.proxy-type:HTTP}")
85 private String httpProxyType = "HTTP";
88 @Value("${app.s3.endpointOverride:}")
89 private String s3EndpointOverride;
92 @Value("${app.s3.accessKeyId:}")
93 private String s3AccessKeyId;
96 @Value("${app.s3.secretAccessKey:}")
97 private String s3SecretAccessKey;
100 @Value("${app.s3.bucket:}")
101 private String s3Bucket;
105 @Value("${app.authorization-provider:}")
106 private String authProviderUrl;
110 @Value("${app.database-enabled:}")
111 private boolean databaseEnabled;
113 private Map<String, RicConfig> ricConfigs = new HashMap<>();
115 private WebClientConfig webClientConfig = null;
117 public synchronized Collection<RicConfig> getRicConfigs() {
118 return this.ricConfigs.values();
121 public WebClientConfig getWebClientConfig() {
122 if (this.webClientConfig == null) {
123 HttpProxyConfig httpProxyConfig = HttpProxyConfig.builder() //
124 .httpProxyHost(this.httpProxyHost) //
125 .httpProxyPort(this.httpProxyPort) //
126 .httpProxyType(ProxyProvider.Proxy.valueOf(this.httpProxyType)) //
129 this.webClientConfig = WebClientConfig.builder() //
130 .keyStoreType(this.sslKeyStoreType) //
131 .keyStorePassword(this.sslKeyStorePassword) //
132 .keyStore(this.sslKeyStore) //
133 .keyPassword(this.sslKeyPassword) //
134 .isTrustStoreUsed(this.sslTrustStoreUsed) //
135 .trustStore(this.sslTrustStore) //
136 .trustStorePassword(this.sslTrustStorePassword) //
137 .httpProxyConfig(httpProxyConfig) //
140 return this.webClientConfig;
143 public synchronized RicConfig getRic(String ricId) throws ServiceException {
144 RicConfig ricConfig = this.ricConfigs.get(ricId);
145 if (ricConfig == null) {
146 throw new ServiceException("Could not find ric configuration: " + ricId);
151 public static class RicConfigUpdate {
153 ADDED, CHANGED, REMOVED
157 private final RicConfig ricConfig;
159 private final Type type;
161 public RicConfigUpdate(RicConfig config, Type event) {
162 this.ricConfig = config;
167 public synchronized Flux<RicConfigUpdate> setConfiguration(
168 ApplicationConfigParser.ConfigParserResult parserResult) {
170 Collection<RicConfigUpdate> modifications = new ArrayList<>();
172 Map<String, RicConfig> newRicConfigs = new HashMap<>();
173 for (RicConfig newConfig : parserResult.getRicConfigs()) {
174 RicConfig oldConfig = this.ricConfigs.get(newConfig.getRicId());
175 this.ricConfigs.remove(newConfig.getRicId());
176 if (oldConfig == null) {
177 newRicConfigs.put(newConfig.getRicId(), newConfig);
178 modifications.add(new RicConfigUpdate(newConfig, RicConfigUpdate.Type.ADDED));
179 } else if (!newConfig.equals(oldConfig)) {
180 modifications.add(new RicConfigUpdate(newConfig, RicConfigUpdate.Type.CHANGED));
181 newRicConfigs.put(newConfig.getRicId(), newConfig);
183 newRicConfigs.put(oldConfig.getRicId(), oldConfig);
186 for (RicConfig deletedConfig : this.ricConfigs.values()) {
187 modifications.add(new RicConfigUpdate(deletedConfig, RicConfigUpdate.Type.REMOVED));
189 this.ricConfigs = newRicConfigs;
191 return Flux.fromIterable(modifications);
194 public boolean isS3Enabled() {
195 return !(Strings.isNullOrEmpty(s3EndpointOverride) || Strings.isNullOrEmpty(s3Bucket));
198 public boolean isDatabaseEnabled() {
199 return databaseEnabled;