2 * ========================LICENSE_START=================================
4 * ======================================================================
5 * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved.
6 * Modifications Copyright (C) 2023-2025 OpenInfra Foundation Europe.
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.ccsdk.oran.a1policymanagementservice.configuration;
25 import com.google.common.base.Strings;
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.HashMap;
32 import org.onap.ccsdk.oran.a1policymanagementservice.configuration.WebClientConfig.HttpProxyConfig;
33 import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException;
34 import org.springframework.beans.factory.annotation.Value;
35 import org.springframework.boot.context.properties.EnableConfigurationProperties;
36 import reactor.core.publisher.Flux;
37 import reactor.netty.transport.ProxyProvider;
39 @EnableConfigurationProperties
40 public class ApplicationConfig {
43 @Value("${app.filepath:null}")
44 private String localConfigurationFilePath;
47 @Value("${app.config-file-schema-path:null}")
48 private String configurationFileSchemaPath;
51 @Value("${app.vardata-directory:null}")
52 private String vardataDirectory;
55 @Value("${server.ssl.enabled:true}")
56 private boolean sslEnabled;
58 @Value("${server.ssl.key-store-type:null}")
59 private String sslKeyStoreType = "";
61 @Value("${server.ssl.key-store-password:null}")
62 private String sslKeyStorePassword = "";
64 @Value("${server.ssl.key-store:null}")
65 private String sslKeyStore = "";
67 @Value("${server.ssl.key-password:null}")
68 private String sslKeyPassword = "";
70 @Value("${app.webclient.trust-store-used:false}")
71 private boolean sslTrustStoreUsed = false;
73 @Value("${app.webclient.trust-store-password:null}")
74 private String sslTrustStorePassword = "";
76 @Value("${app.webclient.trust-store:null}")
77 private String sslTrustStore = "";
79 @Value("${app.webclient.http.proxy-host:}")
80 private String httpProxyHost = "";
82 @Value("${app.webclient.http.proxy-port:0}")
83 private int httpProxyPort = 0;
85 @Value("${app.webclient.http.proxy-type:HTTP}")
86 private String httpProxyType = "HTTP";
89 @Value("${app.s3.endpointOverride:}")
90 private String s3EndpointOverride;
93 @Value("${app.s3.accessKeyId:}")
94 private String s3AccessKeyId;
97 @Value("${app.s3.secretAccessKey:}")
98 private String s3SecretAccessKey;
101 @Value("${app.s3.bucket:}")
102 private String s3Bucket;
106 @Value("${app.authorization-provider:}")
107 private String authProviderUrl;
111 @Value("${app.database-enabled:}")
112 private boolean databaseEnabled;
114 public enum ValidateSchema {
123 @Value("${app.validate-policy-instance-schema:NONE}")
124 private ValidateSchema validatePolicyInstanceSchema;
126 private Map<String, RicConfig> ricConfigs = new HashMap<>();
128 private WebClientConfig webClientConfig = null;
130 public synchronized Collection<RicConfig> getRicConfigs() {
131 return this.ricConfigs.values();
134 public WebClientConfig getWebClientConfig() {
135 if (this.webClientConfig == null) {
136 HttpProxyConfig httpProxyConfig = HttpProxyConfig.builder() //
137 .httpProxyHost(this.httpProxyHost) //
138 .httpProxyPort(this.httpProxyPort) //
139 .httpProxyType(ProxyProvider.Proxy.valueOf(this.httpProxyType)) //
142 this.webClientConfig = WebClientConfig.builder() //
144 .keyStoreType(this.sslKeyStoreType) //
145 .keyStorePassword(this.sslKeyStorePassword) //
146 .keyStore(this.sslKeyStore) //
147 .keyPassword(this.sslKeyPassword) //
148 .isTrustStoreUsed(this.sslTrustStoreUsed) //
149 .trustStore(this.sslTrustStore) //
150 .trustStorePassword(this.sslTrustStorePassword) //
151 .httpProxyConfig(httpProxyConfig) //
154 this.webClientConfig = WebClientConfig.builder() //
156 .isTrustStoreUsed(false)
157 .httpProxyConfig(httpProxyConfig) //
162 return this.webClientConfig;
165 public synchronized RicConfig getRic(String ricId) throws ServiceException {
166 RicConfig ricConfig = this.ricConfigs.get(ricId);
167 if (ricConfig == null) {
168 throw new ServiceException("Could not find ric configuration: " + ricId);
173 public static class RicConfigUpdate {
175 ADDED, CHANGED, REMOVED
179 private final RicConfig ricConfig;
181 private final Type type;
183 public RicConfigUpdate(RicConfig config, Type event) {
184 this.ricConfig = config;
189 public synchronized Flux<RicConfigUpdate> setConfiguration(
190 ApplicationConfigParser.ConfigParserResult parserResult) {
192 Collection<RicConfigUpdate> modifications = new ArrayList<>();
194 Map<String, RicConfig> newRicConfigs = new HashMap<>();
195 for (RicConfig newConfig : parserResult.getRicConfigs()) {
196 RicConfig oldConfig = this.ricConfigs.get(newConfig.getRicId());
197 this.ricConfigs.remove(newConfig.getRicId());
198 if (oldConfig == null) {
199 newRicConfigs.put(newConfig.getRicId(), newConfig);
200 modifications.add(new RicConfigUpdate(newConfig, RicConfigUpdate.Type.ADDED));
201 } else if (!newConfig.equals(oldConfig)) {
202 modifications.add(new RicConfigUpdate(newConfig, RicConfigUpdate.Type.CHANGED));
203 newRicConfigs.put(newConfig.getRicId(), newConfig);
205 newRicConfigs.put(oldConfig.getRicId(), oldConfig);
208 for (RicConfig deletedConfig : this.ricConfigs.values()) {
209 modifications.add(new RicConfigUpdate(deletedConfig, RicConfigUpdate.Type.REMOVED));
211 this.ricConfigs = newRicConfigs;
213 return Flux.fromIterable(modifications);
216 public boolean isS3Enabled() {
217 return !(Strings.isNullOrEmpty(s3EndpointOverride) || Strings.isNullOrEmpty(s3Bucket));
220 public boolean isDatabaseEnabled() {
221 return databaseEnabled;