39d688ba265d4aa9d934c34bd98cce7008ffb8e2
[ccsdk/features.git] /
1 /*******************************************************************************
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 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.impl;
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  * Configuration of mountpoint-registrar, general section<br>
25  * - dmaapEnabled : Boolean disable/enable service depending on whether DMaaP is running or not
26  * Generates default Configuration properties if none exist or exist partially
27  * Generates Consumer properties only for TransportType=HTTPNOAUTH. Other TransportTypes like HTTP, AUTH_KEY and DME2 have additional properties and are not 
28  * generated by default. For a list of applicable properties for the different TranportType values, please see - https://wiki.onap.org/display/DW/Feature+configuration+requirements  
29  */
30 public class GeneralConfig implements Configuration {
31
32     private static final String SECTION_MARKER = "general";
33
34     private static final String PROPERTY_KEY_ENABLED = "dmaapEnabled" ; //"enabled";
35     
36     private static final String PROPERTY_KEY_USER = "sdnrUser";
37     private static final String DEFAULT_VALUE_USER = "admin";
38     
39     private static final String PROPERTY_KEY_USERPASSWD = "sdnrPasswd";
40     private static final String DEFAULT_VALUE_USERPASSWD = "admin";
41     
42     private static final String PROPERTY_KEY_BASEURL = "baseUrl";
43     private static final String DEFAULT_VALUE_BASEURL = "http://localhost:8181";
44    
45
46         private static ConfigurationFileRepresentation configuration;
47
48         public GeneralConfig(ConfigurationFileRepresentation configuration) {
49                 GeneralConfig.configuration = configuration;
50         GeneralConfig.configuration.addSection(SECTION_MARKER);
51                 defaults();
52         }
53
54         public Boolean getEnabled() {
55                 Boolean enabled = configuration.getPropertyBoolean(SECTION_MARKER, PROPERTY_KEY_ENABLED);
56                 return enabled;
57         }
58         
59         public static String getBaseUrl() {
60                 return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_BASEURL);
61         }
62         
63         public static String getSDNRUser() {
64                 return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_USER);
65         }
66         
67         public static String getSDNRPasswd() {
68                 return configuration.getProperty(SECTION_MARKER, PROPERTY_KEY_USERPASSWD);
69         }
70         
71         @Override
72         public String getSectionName() {
73                 return SECTION_MARKER;
74         }
75
76         @Override
77         public void defaults() {
78                 // The default value should be "false" given that SDNR can be run in environments where DMaaP is not used
79                 configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_ENABLED, Boolean.FALSE);
80                 configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_BASEURL, DEFAULT_VALUE_BASEURL);
81                 configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_USER, DEFAULT_VALUE_USER);
82                 configuration.setPropertyIfNotAvailable(SECTION_MARKER, PROPERTY_KEY_USERPASSWD, DEFAULT_VALUE_USERPASSWD);
83         }
84         
85         
86
87 }