2 * ========================LICENSE_START=================================
5 * Copyright (C) 2023 Nordix Foundation
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.oran.pmproducer.configuration;
23 import java.lang.invoke.MethodHandles;
24 import java.nio.charset.Charset;
25 import java.nio.file.Files;
26 import java.nio.file.Path;
27 import java.util.Collection;
28 import java.util.Collections;
32 import lombok.ToString;
34 import org.oran.pmproducer.configuration.WebClientConfig.HttpProxyConfig;
35 import org.oran.pmproducer.repository.InfoType;
36 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory;
38 import org.springframework.beans.factory.annotation.Value;
39 import org.springframework.boot.context.properties.EnableConfigurationProperties;
41 @EnableConfigurationProperties
43 public class ApplicationConfig {
45 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
48 @Value("${app.configuration-filepath}")
49 private String localConfigurationFilePath;
51 @Value("${server.ssl.key-store-type}")
52 private String sslKeyStoreType = "";
54 @Value("${server.ssl.key-store-password}")
55 private String sslKeyStorePassword = "";
57 @Value("${server.ssl.key-store}")
58 private String sslKeyStore = "";
60 @Value("${server.ssl.key-password}")
61 private String sslKeyPassword = "";
63 @Value("${app.webclient.trust-store-used}")
64 private boolean sslTrustStoreUsed = false;
66 @Value("${app.webclient.trust-store-password}")
67 private String sslTrustStorePassword = "";
69 @Value("${app.webclient.trust-store}")
70 private String sslTrustStore = "";
72 @Value("${app.webclient.http.proxy-host:}")
73 private String httpProxyHost = "";
75 @Value("${app.webclient.http.proxy-port:0}")
76 private int httpProxyPort = 0;
80 @Value("${server.port}")
81 private int localServerHttpPort;
84 @Value("${app.ics-base-url}")
85 private String icsBaseUrl;
88 @Value("${app.pm_producer-base-url}")
89 private String selfUrl;
92 @Value("${app.dmaap-base-url}")
93 private String dmaapBaseUrl;
96 @Value("${app.kafka.bootstrap-servers:}")
97 private String kafkaBootStrapServers;
100 @Value("${app.kafka.max-poll-records:300}")
101 private int kafkaMaxPollRecords;
104 @Value("${app.pm-files-path:}")
105 private String pmFilesPath;
108 @Value("${app.s3.endpointOverride:}")
109 private String s3EndpointOverride;
112 @Value("${app.s3.accessKeyId:}")
113 private String s3AccessKeyId;
116 @Value("${app.s3.secretAccessKey:}")
117 private String s3SecretAccessKey;
120 @Value("${app.s3.locksBucket:}")
121 private String s3LocksBucket;
124 @Value("${app.s3.bucket:}")
125 private String s3Bucket;
129 @Value("${app.zip-output:}")
130 private boolean zipOutput;
132 private WebClientConfig webClientConfig = null;
134 public WebClientConfig getWebClientConfig() {
135 if (this.webClientConfig == null) {
136 HttpProxyConfig httpProxyConfig = HttpProxyConfig.builder() //
137 .httpProxyHost(this.httpProxyHost) //
138 .httpProxyPort(this.httpProxyPort) //
141 this.webClientConfig = WebClientConfig.builder() //
142 .keyStoreType(this.sslKeyStoreType) //
143 .keyStorePassword(this.sslKeyStorePassword) //
144 .keyStore(this.sslKeyStore) //
145 .keyPassword(this.sslKeyPassword) //
146 .isTrustStoreUsed(this.sslTrustStoreUsed) //
147 .trustStore(this.sslTrustStore) //
148 .trustStorePassword(this.sslTrustStorePassword) //
149 .httpProxyConfig(httpProxyConfig) //
152 return this.webClientConfig;
155 public boolean isS3Enabled() {
156 return !(s3EndpointOverride.isBlank() || s3Bucket.isBlank());
159 // Adapter to parse the json format of the configuration file.
160 static class ConfigFile {
161 Collection<InfoType> types;
164 public Collection<InfoType> getTypes() {
165 com.google.gson.Gson gson = new com.google.gson.GsonBuilder().disableHtmlEscaping().create();
167 String configJson = Files.readString(Path.of(getLocalConfigurationFilePath()), Charset.defaultCharset());
168 ConfigFile configData = gson.fromJson(configJson, ConfigFile.class);
169 return configData.types;
170 } catch (Exception e) {
171 logger.error("Could not load configuration file {}", getLocalConfigurationFilePath());
172 return Collections.emptyList();