NONRTRIC - Enrichment Coordinator Service, making type availability subscriptions...
[nonrtric.git] / enrichment-coordinator-service / src / main / java / org / oransc / enrichment / configuration / ApplicationConfig.java
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2020 Nordix Foundation
6  * %%
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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===================================
19  */
20
21 package org.oransc.enrichment.configuration;
22
23 import lombok.Getter;
24
25 import org.oransc.enrichment.configuration.WebClientConfig.HttpProxyConfig;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28 import org.springframework.beans.factory.annotation.Value;
29 import org.springframework.boot.context.properties.ConfigurationProperties;
30 import org.springframework.boot.context.properties.EnableConfigurationProperties;
31
32 @EnableConfigurationProperties
33 @ConfigurationProperties()
34 public class ApplicationConfig {
35
36     private static final Logger logger = LoggerFactory.getLogger(ApplicationConfig.class);
37
38     @Getter
39     @Value("${app.vardata-directory}")
40     private String vardataDirectory;
41
42     @Value("${server.ssl.key-store-type}")
43     private String sslKeyStoreType = "";
44
45     @Value("${server.ssl.key-store-password}")
46     private String sslKeyStorePassword = "";
47
48     @Value("${server.ssl.key-store}")
49     private String sslKeyStore = "";
50
51     @Value("${server.ssl.key-password}")
52     private String sslKeyPassword = "";
53
54     @Value("${app.webclient.trust-store-used}")
55     private boolean sslTrustStoreUsed = false;
56
57     @Value("${app.webclient.trust-store-password}")
58     private String sslTrustStorePassword = "";
59
60     @Value("${app.webclient.trust-store}")
61     private String sslTrustStore = "";
62
63     @Value("${app.webclient.http.proxy-host:\"\"}")
64     private String httpProxyHost = "";
65
66     @Value("${app.webclient.http.proxy-port:0}")
67     private int httpProxyPort = 0;
68
69     private WebClientConfig webClientConfig = null;
70
71     public WebClientConfig getWebClientConfig() {
72         if (this.webClientConfig == null) {
73             if (this.httpProxyPort == 0) {
74                 logger.info("Http proxy is not used");
75             } else {
76                 logger.info("Http proxy is used for RAN access {}:{}", httpProxyHost, httpProxyPort);
77             }
78             HttpProxyConfig httpProxyConfig = ImmutableHttpProxyConfig.builder() //
79                 .httpProxyHost(this.httpProxyHost) //
80                 .httpProxyPort(this.httpProxyPort) //
81                 .build();
82             this.webClientConfig = ImmutableWebClientConfig.builder() //
83                 .keyStoreType(this.sslKeyStoreType) //
84                 .keyStorePassword(this.sslKeyStorePassword) //
85                 .keyStore(this.sslKeyStore) //
86                 .keyPassword(this.sslKeyPassword) //
87                 .isTrustStoreUsed(this.sslTrustStoreUsed) //
88                 .trustStore(this.sslTrustStore) //
89                 .trustStorePassword(this.sslTrustStorePassword) //
90                 .httpProxyConfig(httpProxyConfig) //
91                 .build();
92         }
93         return this.webClientConfig;
94     }
95
96 }