b05c0324ff74b4c99fcda9a1d0d84b71f14e5c62
[dcaegen2/services/prh.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * PNF-REGISTRATION-HANDLER
4  * ================================================================================
5  * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
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.onap.dcaegen2.services.prh.configuration;
22
23 import com.google.gson.JsonObject;
24 import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration;
25 import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.ImmutableAaiClientConfiguration;
26 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration;
27 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration;
28 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapConsumerConfiguration;
29 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.ImmutableDmaapPublisherConfiguration;
30
31 /**
32  * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 8/21/18
33  */
34 class ConsulConfigurationParser {
35     private static final String SECURITY_TRUST_STORE_PATH = "security.trustStorePath";
36     private static final String SECURITY_TRUST_STORE_PASS_PATH = "security.trustStorePasswordPath";
37     private static final String SECURITY_KEY_STORE_PATH = "security.keyStorePath";
38     private static final String SECURITY_KEY_STORE_PASS_PATH = "security.keyStorePasswordPath";
39     private static final String CONFIG = "config";
40     private final JsonObject jsonObject;
41
42     ConsulConfigurationParser(JsonObject jsonObject) {
43         this.jsonObject = jsonObject.getAsJsonObject(CONFIG);
44     }
45
46     DmaapPublisherConfiguration getDmaapPublisherConfig() {
47         return new ImmutableDmaapPublisherConfiguration.Builder()
48             .dmaapTopicName(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapTopicName").getAsString())
49             .dmaapUserPassword(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapUserPassword").getAsString())
50             .dmaapPortNumber(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapPortNumber").getAsInt())
51             .dmaapProtocol(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapProtocol").getAsString())
52             .dmaapContentType(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapContentType").getAsString())
53             .dmaapHostName(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapHostName").getAsString())
54             .dmaapUserName(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapUserName").getAsString())
55             .dmaapUserPassword(jsonObject.get("dmaap.dmaapProducerConfiguration.dmaapUserPassword").getAsString())
56             .trustStorePath(jsonObject.get(SECURITY_TRUST_STORE_PATH).getAsString())
57             .trustStorePasswordPath(jsonObject.get(SECURITY_TRUST_STORE_PASS_PATH).getAsString())
58             .keyStorePath(jsonObject.get(SECURITY_KEY_STORE_PATH).getAsString())
59             .keyStorePasswordPath(jsonObject.get(SECURITY_KEY_STORE_PASS_PATH).getAsString())
60             .enableDmaapCertAuth(jsonObject.get("security.enableDmaapCertAuth").getAsBoolean())
61             .build();
62     }
63
64     DmaapPublisherConfiguration getDmaapUpdatePublisherConfig() {
65         return new ImmutableDmaapPublisherConfiguration.Builder()
66              .dmaapTopicName(jsonObject.get("dmaap.dmaapUpdateProducerConfiguration.dmaapTopicName").getAsString())
67             .dmaapUserPassword(jsonObject.get("dmaap.dmaapUpdateProducerConfiguration.dmaapUserPassword").getAsString())
68             .dmaapPortNumber(jsonObject.get("dmaap.dmaapUpdateProducerConfiguration.dmaapPortNumber").getAsInt())
69             .dmaapProtocol(jsonObject.get("dmaap.dmaapUpdateProducerConfiguration.dmaapProtocol").getAsString())
70             .dmaapContentType(jsonObject.get("dmaap.dmaapUpdateProducerConfiguration.dmaapContentType").getAsString())
71             .dmaapHostName(jsonObject.get("dmaap.dmaapUpdateProducerConfiguration.dmaapHostName").getAsString())
72             .dmaapUserName(jsonObject.get("dmaap.dmaapUpdateProducerConfiguration.dmaapUserName").getAsString())
73             .dmaapUserPassword(jsonObject.get("dmaap.dmaapUpdateProducerConfiguration.dmaapUserPassword").getAsString())
74             .trustStorePath(jsonObject.get(SECURITY_TRUST_STORE_PATH).getAsString())
75             .trustStorePasswordPath(jsonObject.get(SECURITY_TRUST_STORE_PASS_PATH).getAsString())
76             .keyStorePath(jsonObject.get(SECURITY_KEY_STORE_PATH).getAsString())
77             .keyStorePasswordPath(jsonObject.get(SECURITY_KEY_STORE_PASS_PATH).getAsString())
78             .enableDmaapCertAuth(jsonObject.get("security.enableDmaapCertAuth").getAsBoolean())
79             .build();
80     }
81
82     AaiClientConfiguration getAaiClientConfig() {
83         return new ImmutableAaiClientConfiguration.Builder()
84             .pnfUrl(jsonObject.get("aai.aaiClientConfiguration.pnfUrl").getAsString())
85             .aaiHost(jsonObject.get("aai.aaiClientConfiguration.aaiHost").getAsString())
86             .aaiPort(jsonObject.get("aai.aaiClientConfiguration.aaiHostPortNumber").getAsInt())
87             .aaiUserName(jsonObject.get("aai.aaiClientConfiguration.aaiUserName").getAsString())
88             .aaiPnfPath(jsonObject.get("aai.aaiClientConfiguration.aaiPnfPath").getAsString())
89             .aaiServiceInstancePath(jsonObject.get("aai.aaiClientConfiguration.aaiServiceInstancePath").getAsString())
90             .aaiIgnoreSslCertificateErrors(
91                 jsonObject.get("aai.aaiClientConfiguration.aaiIgnoreSslCertificateErrors").getAsBoolean())
92             .aaiUserPassword(jsonObject.get("aai.aaiClientConfiguration.aaiUserPassword").getAsString())
93             .aaiProtocol(jsonObject.get("aai.aaiClientConfiguration.aaiProtocol").getAsString())
94             .aaiBasePath(jsonObject.get("aai.aaiClientConfiguration.aaiBasePath").getAsString())
95             .trustStorePath(jsonObject.get(SECURITY_TRUST_STORE_PATH).getAsString())
96             .trustStorePasswordPath(jsonObject.get(SECURITY_TRUST_STORE_PASS_PATH).getAsString())
97             .keyStorePath(jsonObject.get(SECURITY_KEY_STORE_PATH).getAsString())
98             .keyStorePasswordPath(jsonObject.get(SECURITY_KEY_STORE_PASS_PATH).getAsString())
99             .enableAaiCertAuth(jsonObject.get("security.enableAaiCertAuth").getAsBoolean())
100             .build();
101     }
102
103     DmaapConsumerConfiguration getDmaapConsumerConfig() {
104         return new ImmutableDmaapConsumerConfiguration.Builder()
105             .timeoutMs(jsonObject.get("dmaap.dmaapConsumerConfiguration.timeoutMs").getAsInt())
106             .dmaapHostName(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapHostName").getAsString())
107             .dmaapUserName(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapUserName").getAsString())
108             .dmaapUserPassword(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapUserPassword").getAsString())
109             .dmaapTopicName(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapTopicName").getAsString())
110             .dmaapPortNumber(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapPortNumber").getAsInt())
111             .dmaapContentType(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapContentType").getAsString())
112             .messageLimit(jsonObject.get("dmaap.dmaapConsumerConfiguration.messageLimit").getAsInt())
113             .dmaapProtocol(jsonObject.get("dmaap.dmaapConsumerConfiguration.dmaapProtocol").getAsString())
114             .consumerId(jsonObject.get("dmaap.dmaapConsumerConfiguration.consumerId").getAsString())
115             .consumerGroup(jsonObject.get("dmaap.dmaapConsumerConfiguration.consumerGroup").getAsString())
116             .trustStorePath(jsonObject.get(SECURITY_TRUST_STORE_PATH).getAsString())
117             .trustStorePasswordPath(jsonObject.get(SECURITY_TRUST_STORE_PASS_PATH).getAsString())
118             .keyStorePath(jsonObject.get(SECURITY_KEY_STORE_PATH).getAsString())
119             .keyStorePasswordPath(jsonObject.get(SECURITY_KEY_STORE_PASS_PATH).getAsString())
120             .enableDmaapCertAuth(jsonObject.get("security.enableDmaapCertAuth").getAsBoolean())
121             .build();
122     }
123 }