2 * ========================LICENSE_START=================================
5 * Copyright (C) 2021 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.dmaapadapter.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 org.oran.dmaapadapter.configuration.WebClientConfig.HttpProxyConfig;
33 import org.oran.dmaapadapter.repository.InfoType;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 import org.springframework.beans.factory.annotation.Value;
37 import org.springframework.boot.context.properties.EnableConfigurationProperties;
39 @EnableConfigurationProperties
40 public class ApplicationConfig {
42 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
45 @Value("${app.configuration-filepath}")
46 private String localConfigurationFilePath;
48 @Value("${server.ssl.key-store-type}")
49 private String sslKeyStoreType = "";
51 @Value("${server.ssl.key-store-password}")
52 private String sslKeyStorePassword = "";
54 @Value("${server.ssl.key-store}")
55 private String sslKeyStore = "";
57 @Value("${server.ssl.key-password}")
58 private String sslKeyPassword = "";
60 @Value("${app.webclient.trust-store-used}")
61 private boolean sslTrustStoreUsed = false;
63 @Value("${app.webclient.trust-store-password}")
64 private String sslTrustStorePassword = "";
66 @Value("${app.webclient.trust-store}")
67 private String sslTrustStore = "";
69 @Value("${app.webclient.http.proxy-host:\"\"}")
70 private String httpProxyHost = "";
72 @Value("${app.webclient.http.proxy-port:0}")
73 private int httpProxyPort = 0;
76 @Value("${server.port}")
77 private int localServerHttpPort;
80 @Value("${app.ecs-base-url}")
81 private String ecsBaseUrl;
84 @Value("${app.dmaap-adapter-base-url}")
85 private String selfUrl;
88 @Value("${app.dmaap-base-url}")
89 private String dmaapBaseUrl;
91 private WebClientConfig webClientConfig = null;
93 public WebClientConfig getWebClientConfig() {
94 if (this.webClientConfig == null) {
95 HttpProxyConfig httpProxyConfig = ImmutableHttpProxyConfig.builder() //
96 .httpProxyHost(this.httpProxyHost) //
97 .httpProxyPort(this.httpProxyPort) //
100 this.webClientConfig = ImmutableWebClientConfig.builder() //
101 .keyStoreType(this.sslKeyStoreType) //
102 .keyStorePassword(this.sslKeyStorePassword) //
103 .keyStore(this.sslKeyStore) //
104 .keyPassword(this.sslKeyPassword) //
105 .isTrustStoreUsed(this.sslTrustStoreUsed) //
106 .trustStore(this.sslTrustStore) //
107 .trustStorePassword(this.sslTrustStorePassword) //
108 .httpProxyConfig(httpProxyConfig) //
111 return this.webClientConfig;
114 // Adapter to parse the json format of the configuration file.
115 static class ConfigFile {
116 Collection<InfoType> types;
119 public Collection<InfoType> getTypes() {
120 com.google.gson.Gson gson = new com.google.gson.GsonBuilder().create();
123 String configJson = Files.readString(Path.of(getLocalConfigurationFilePath()), Charset.defaultCharset());
124 ConfigFile configData = gson.fromJson(configJson, ConfigFile.class);
125 return configData.types;
126 } catch (Exception e) {
127 logger.error("Could not load configuration file {}", getLocalConfigurationFilePath());
128 return Collections.emptyList();