025768762da66a8355d056365f2b9e2309f2db6c
[sdnc/apps.git] /
1 /*
2  * ============LICENSE_START===================================================
3  * Copyright (c) 2018 Amdocs
4  * ============================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ============LICENSE_END=====================================================
17  */
18 package org.onap.sdnc.apps.pomba.networkdiscovery;
19
20 import java.util.HashMap;
21 import java.util.Map;
22 import java.util.StringTokenizer;
23 import org.onap.aai.restclient.client.RestClient;
24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.beans.factory.annotation.Value;
26 import org.springframework.context.annotation.Bean;
27 import org.springframework.context.annotation.Configuration;
28 import org.springframework.core.env.Environment;
29 import com.google.common.base.Splitter;
30
31 @Configuration
32 public class EnricherConfiguration {
33     @Autowired
34     private Environment env;
35
36     @Value("${enricher.url}")
37     private String url;
38
39     @Value("${enricher.keyStorePath}")
40     private String keyStorePath;
41
42     @Value("${enricher.keyStorePassword:OBF:1i9a1u2a1unz1lr61wn51wn11lss1unz1u301i6o}")
43     private String keyStorePassword;
44
45     @Value("${enricher.connectionTimeout:5000}")
46     private int connectionTimeout;
47
48     @Value("${enricher.readTimeout:60000}")
49     private int readTimeout;
50
51     @Bean(name = "enricherClient")
52     public RestClient restClient() {
53         return new RestClient().validateServerHostname(false)
54                         .validateServerCertChain(false)
55                         .connectTimeoutMs(this.connectionTimeout)
56                         .readTimeoutMs(this.readTimeout)
57                         .clientCertFile(this.keyStorePath)
58                         .clientCertPassword(org.eclipse.jetty.util.security.Password.deobfuscate(
59                                         this.keyStorePassword));
60     }
61
62     @Bean(name = "enricherBaseUrl")
63     public String getURL() {
64         return this.url;
65     }
66
67     @Bean(name = "enricherTypeURLs")
68     public Map<String, String> enricherTypeURLs() {
69
70         Map<String, String> result = new HashMap<>();
71         String types = this.env.getProperty("enricher.types");
72         if (types == null) {
73             return result;
74         }
75
76         StringTokenizer tokenizer = new StringTokenizer(types, ", ");
77         while (tokenizer.hasMoreTokens()) {
78             String type = tokenizer.nextToken();
79             String enricherUrl = this.env.getProperty("enricher.type." + type + ".url");
80             result.put(type, enricherUrl);
81         }
82
83         return result;
84     }
85
86     @Value("${enricher.attributeNameMappingList}")
87     private String enricherAttributeNameMappingList;
88
89     @Bean(name = "enricherAttributeNameMapping")
90     public Map<String, String> getAttributeNameMap() {
91         String noWhiteSpaceString = enricherAttributeNameMappingList.replaceAll("\\s", "");
92         return (Splitter.on(";").withKeyValueSeparator(":").split(noWhiteSpaceString));
93     }
94 }