41ab8a7cbd543cd187c473ed6b6b8d248c6c3fa5
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2022 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18 package org.onap.ccsdk.features.sdnr.wt.mountpointregistrar.config;
19
20 import org.onap.ccsdk.features.sdnr.wt.common.configuration.Configuration;
21 import org.onap.ccsdk.features.sdnr.wt.common.configuration.ConfigurationFileRepresentation;
22
23 /*
24  * [strimzi-kafka]
25  * bootstrapServers=abc:9092,def:9092
26  * securityProtocol=PLAINTEXT #OTHER POSSIBLE VALUES - SSL, SASL_PLAINTEXT, SASL_SSL
27  * saslMechanism=PLAIN #Need to understand more
28  * saslJaasConfig=
29  * consumerGroup=
30  * consumerID=
31  */
32 public class StrimziKafkaConfig implements Configuration {
33
34     private static final String SECTION_MARKER = "strimzi-kafka";
35
36     private static final String PROPERTY_KEY_ENABLED = "strimziEnabled";
37
38     private static final String PROPERTY_KEY_BOOTSTRAPSERVERS = "bootstrapServers";
39     private static final String DEFAULT_VALUE_BOOTSTRAPSERVERS = "onap-strimzi-kafka-0:9094,onap-strimzi-kafka-1:9094";
40
41     private static final String PROPERTY_KEY_SECURITYPROTOCOL = "securityProtocol";
42     private static final String DEFAULT_VALUE_SECURITYPROTOCOL = "PLAINTEXT";
43
44     private static final String PROPERTY_KEY_SASLMECHANISM = "saslMechanism";
45     private static final String DEFAULT_VALUE_SASLMECHANISM = "PLAIN";
46
47     private static final String PROPERTY_KEY_SASLJAASCONFIG = "saslJaasConfig";
48     private static final String DEFAULT_VALUE_SASLJAASCONFIG = "PLAIN"; // TBD
49
50     private ConfigurationFileRepresentation configuration;
51
52     public StrimziKafkaConfig(ConfigurationFileRepresentation configuration) {
53         this.configuration = configuration;
54         configuration.addSection(SECTION_MARKER);
55         defaults();
56     }
57
58     public Boolean getEnabled() {
59         return configuration.getPropertyBoolean(SECTION_MARKER, PROPERTY_KEY_ENABLED);
60     }
61
62     public String getBootstrapServers() {
63         return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_BOOTSTRAPSERVERS);
64     }
65
66     public String getSecurityProtocol() {
67         return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_SECURITYPROTOCOL);
68     }
69
70     public String getSaslMechanism() {
71         return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_SASLMECHANISM);
72     }
73
74     public String getSaslJaasConfig() {
75         return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_SASLJAASCONFIG);
76     }
77
78     @Override
79     public String getSectionName() {
80         return SECTION_MARKER;
81     }
82
83     @Override
84     public void defaults() {
85         // The default value should be "false" given that SDNR can be run in
86         // environments where Strimzi is not used
87         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_ENABLED, Boolean.FALSE);
88         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_BOOTSTRAPSERVERS,
89                 DEFAULT_VALUE_BOOTSTRAPSERVERS);
90         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_SECURITYPROTOCOL,
91                 DEFAULT_VALUE_SECURITYPROTOCOL);
92         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_SASLMECHANISM,
93                 DEFAULT_VALUE_SASLMECHANISM);
94         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_SASLJAASCONFIG,
95                 DEFAULT_VALUE_SASLJAASCONFIG);
96     }
97
98 }