Include env vars as defaults
[ccsdk/features.git] / sdnr / wt / mountpoint-registrar / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / mountpointregistrar / config / StrimziKafkaConfig.java
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=PLAIN
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     private static final String DEFAULT_VALUE_KAFKA_ENABLED = "${SDNR_KAFKA_ENABLED}";
38
39     private static final String PROPERTY_KEY_BOOTSTRAPSERVERS = "bootstrapServers";
40     private static final String DEFAULT_VALUE_BOOTSTRAPSERVERS = "${SDNR_KAFKA_BOOTSTRAP_SERVERS}";
41
42     private static final String PROPERTY_KEY_SECURITYPROTOCOL = "securityProtocol";
43     private static final String DEFAULT_VALUE_SECURITYPROTOCOL = "${SDNR_KAFKA_SECURITY_PROTOCOL}";
44
45     private static final String PROPERTY_KEY_SASLMECHANISM = "saslMechanism";
46     private static final String DEFAULT_VALUE_SASLMECHANISM = "${SDNR_KAFKA_SASL_MECHANISM}";
47
48     private static final String PROPERTY_KEY_SASLJAASCONFIG = "saslJaasConfig";
49     private static final String DEFAULT_VALUE_SASLJAASCONFIG = "${SDNR_KAFKA_SASL_JAAS_CONFIG}";
50
51     private ConfigurationFileRepresentation configuration;
52
53     public StrimziKafkaConfig(ConfigurationFileRepresentation configuration) {
54         this.configuration = configuration;
55         configuration.addSection(SECTION_MARKER);
56         defaults();
57     }
58
59     public Boolean getEnabled() {
60         return configuration.getPropertyBoolean(SECTION_MARKER, PROPERTY_KEY_ENABLED);
61     }
62
63     public String getBootstrapServers() {
64         return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_BOOTSTRAPSERVERS);
65     }
66
67     public String getSecurityProtocol() {
68         return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_SECURITYPROTOCOL);
69     }
70
71     public String getSaslMechanism() {
72         return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_SASLMECHANISM);
73     }
74
75     public String getSaslJaasConfig() {
76         return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_SASLJAASCONFIG);
77     }
78
79     @Override
80     public String getSectionName() {
81         return SECTION_MARKER;
82     }
83
84     @Override
85     public void defaults() {
86         // The default value should be "false" given that SDNR can be run in
87         // environments where Strimzi is not used
88         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_ENABLED, DEFAULT_VALUE_KAFKA_ENABLED);
89         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_BOOTSTRAPSERVERS,
90                 DEFAULT_VALUE_BOOTSTRAPSERVERS);
91         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_SECURITYPROTOCOL,
92                 DEFAULT_VALUE_SECURITYPROTOCOL);
93         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_SASLMECHANISM,
94                 DEFAULT_VALUE_SASLMECHANISM);
95         configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_SASLJAASCONFIG,
96                 DEFAULT_VALUE_SASLJAASCONFIG);
97     }
98
99 }