ee18397a9231faee7c9c9f7dc9c8fabe4a169841
[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
24 import org.eclipse.jetty.util.security.Password;
25 import org.onap.aai.restclient.client.RestClient;
26 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.beans.factory.annotation.Value;
28 import org.springframework.context.annotation.Bean;
29 import org.springframework.context.annotation.Configuration;
30 import org.springframework.core.env.Environment;
31
32 @Configuration
33 public class OpenstackConfiguration {
34     @Autowired
35     private Environment env;
36
37     @Value("${openstack.identity.url:http://localhost:5000/v3}")
38     private String identityUrl;
39
40     @Value("${openstack.identity.user}")
41     private String identityUser;
42
43     @Value("${openstack.identity.password}")
44     private String identityPassword;
45
46     @Value("${openstack.api.microversion}")
47     private String apiMicroversion;
48
49     @Value("${openstack.identity.keyStorePath:config/auth/client-cert-onap.p12}")
50     private String keyStorePath;
51
52     @Value("${openstack.identity.keyStorePassword:OBF:1y0q1uvc1uum1uvg1pil1pjl1uuq1uvk1uuu1y10}")
53     private String keyStorePassword;
54
55     @Value("${openstack.connectionTimeout:5000}")
56     private int connectionTimeout;
57
58     @Value("${openstack.readTimeout:60000}")
59     private int readTimeout;
60
61     @Bean(name = "openstackClient")
62     public RestClient restClient() {
63         return new RestClient().validateServerHostname(false)
64                         .validateServerCertChain(false)
65                         .connectTimeoutMs(this.connectionTimeout)
66                         .readTimeoutMs(this.readTimeout);
67     }
68
69     @Bean(name = "openstackIdentityUrl")
70     public String getIdentityURL() {
71         return this.identityUrl;
72     }
73
74     @Bean(name = "openstackIdentityUser")
75     public String getIdentityUser() {
76         return this.identityUser;
77     }
78
79     @Bean(name = "openstackIdentityPassword")
80     public String getIdentityPassword() {
81         return Password.deobfuscate(this.identityPassword);
82     }
83
84     @Bean(name = "openstackApiMicroversion")
85     public String getApiMicroversion() {
86         return this.apiMicroversion;
87     }
88
89     @Bean(name = "openstackTypeURLs")
90     public Map<String, String> getOpenstackTypeURLs() {
91
92         Map<String, String> result = new HashMap<>();
93         String types = this.env.getProperty("openstack.types");
94         if (types == null) {
95             return result;
96         }
97
98         StringTokenizer tokenizer = new StringTokenizer(types, ", ");
99         while (tokenizer.hasMoreTokens()) {
100             String type = tokenizer.nextToken();
101             String openstackUrl = this.env.getProperty("openstack.type." + type + ".url");
102             result.put(type, openstackUrl);
103         }
104
105         return result;
106     }
107
108 }