2 * ========================LICENSE_START=================================
4 * ======================================================================
5 * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved.
6 * Modifications Copyright (C) 2023-2025 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;
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.HashMap;
31 import org.onap.ccsdk.oran.a1policymanagementservice.configuration.WebClientConfig.HttpProxyConfig;
32 import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException;
33 import org.springframework.beans.factory.annotation.Value;
34 import org.springframework.boot.context.properties.EnableConfigurationProperties;
35 import reactor.core.publisher.Flux;
36 import reactor.netty.transport.ProxyProvider;
38 @EnableConfigurationProperties
39 public class ApplicationConfig {
42 @Value("${app.filepath}")
43 private String localConfigurationFilePath;
46 @Value("${app.config-file-schema-path:}")
47 private String configurationFileSchemaPath;
50 @Value("${app.vardata-directory:null}")
51 private String vardataDirectory;
53 @Value("${server.ssl.key-store-type}")
54 private String sslKeyStoreType = "";
56 @Value("${server.ssl.key-store-password}")
57 private String sslKeyStorePassword = "";
59 @Value("${server.ssl.key-store}")
60 private String sslKeyStore = "";
62 @Value("${server.ssl.key-password}")
63 private String sslKeyPassword = "";
65 @Value("${app.webclient.trust-store-used}")
66 private boolean sslTrustStoreUsed = false;
68 @Value("${app.webclient.trust-store-password}")
69 private String sslTrustStorePassword = "";
71 @Value("${app.webclient.trust-store}")
72 private String sslTrustStore = "";
74 @Value("${app.webclient.http.proxy-host:}")
75 private String httpProxyHost = "";
77 @Value("${app.webclient.http.proxy-port:0}")
78 private int httpProxyPort = 0;
80 @Value("${app.webclient.http.proxy-type:HTTP}")
81 private String httpProxyType = "HTTP";
84 @Value("${app.s3.endpointOverride:}")
85 private String s3EndpointOverride;
88 @Value("${app.s3.accessKeyId:}")
89 private String s3AccessKeyId;
92 @Value("${app.s3.secretAccessKey:}")
93 private String s3SecretAccessKey;
96 @Value("${app.s3.bucket:}")
97 private String s3Bucket;
101 @Value("${app.authorization-provider:}")
102 private String authProviderUrl;
106 @Value("${app.database-enabled:}")
107 private boolean databaseEnabled;
109 public enum ValidateSchema {
118 @Value("${app.validate-policy-instance-schema:NONE}")
119 private ValidateSchema validatePolicyInstanceSchema;
121 private Map<String, RicConfig> ricConfigs = new HashMap<>();
123 private WebClientConfig webClientConfig = null;
125 public synchronized Collection<RicConfig> getRicConfigs() {
126 return this.ricConfigs.values();
129 public WebClientConfig getWebClientConfig() {
130 if (this.webClientConfig == null) {
131 HttpProxyConfig httpProxyConfig = HttpProxyConfig.builder() //
132 .httpProxyHost(this.httpProxyHost) //
133 .httpProxyPort(this.httpProxyPort) //
134 .httpProxyType(ProxyProvider.Proxy.valueOf(this.httpProxyType)) //
137 this.webClientConfig = WebClientConfig.builder() //
138 .keyStoreType(this.sslKeyStoreType) //
139 .keyStorePassword(this.sslKeyStorePassword) //
140 .keyStore(this.sslKeyStore) //
141 .keyPassword(this.sslKeyPassword) //
142 .isTrustStoreUsed(this.sslTrustStoreUsed) //
143 .trustStore(this.sslTrustStore) //
144 .trustStorePassword(this.sslTrustStorePassword) //
145 .httpProxyConfig(httpProxyConfig) //
148 return this.webClientConfig;
151 public synchronized RicConfig getRic(String ricId) throws ServiceException {
152 RicConfig ricConfig = this.ricConfigs.get(ricId);
153 if (ricConfig == null) {
154 throw new ServiceException("Could not find ric configuration: " + ricId);
159 public static class RicConfigUpdate {
161 ADDED, CHANGED, REMOVED
165 private final RicConfig ricConfig;
167 private final Type type;
169 public RicConfigUpdate(RicConfig config, Type event) {
170 this.ricConfig = config;
175 public synchronized Flux<RicConfigUpdate> setConfiguration(
176 ApplicationConfigParser.ConfigParserResult parserResult) {
178 Collection<RicConfigUpdate> modifications = new ArrayList<>();
180 Map<String, RicConfig> newRicConfigs = new HashMap<>();
181 for (RicConfig newConfig : parserResult.getRicConfigs()) {
182 RicConfig oldConfig = this.ricConfigs.get(newConfig.getRicId());
183 this.ricConfigs.remove(newConfig.getRicId());
184 if (oldConfig == null) {
185 newRicConfigs.put(newConfig.getRicId(), newConfig);
186 modifications.add(new RicConfigUpdate(newConfig, RicConfigUpdate.Type.ADDED));
187 } else if (!newConfig.equals(oldConfig)) {
188 modifications.add(new RicConfigUpdate(newConfig, RicConfigUpdate.Type.CHANGED));
189 newRicConfigs.put(newConfig.getRicId(), newConfig);
191 newRicConfigs.put(oldConfig.getRicId(), oldConfig);
194 for (RicConfig deletedConfig : this.ricConfigs.values()) {
195 modifications.add(new RicConfigUpdate(deletedConfig, RicConfigUpdate.Type.REMOVED));
197 this.ricConfigs = newRicConfigs;
199 return Flux.fromIterable(modifications);
202 public boolean isS3Enabled() {
203 return !(Strings.isNullOrEmpty(s3EndpointOverride) || Strings.isNullOrEmpty(s3Bucket));
206 public boolean isDatabaseEnabled() {
207 return databaseEnabled;