15759c7210ce6c917217ae12d6160380abd303ef
[ccsdk/sli/adaptors.git] /
1 /*
2  * Copyright (C) 2018 Bell Canada.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.ccsdk.sli.adaptors.netbox.property;
17
18 import java.io.FileInputStream;
19 import java.util.Properties;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 /**
24  * THIS CLASS IS A COPY OF {@link NetboxProperties} WITH REMOVED OSGi DEPENDENCIES
25  */
26 public class NetboxPropertiesLighty {
27
28     private static final Logger LOG = LoggerFactory.getLogger(NetboxPropertiesLighty.class);
29
30     private static final String NETBOX_PROPERTY_FILE_NAME = "netbox.properties";
31     private static final String DEFAULT_PROPERTIES_DIR = "/opt/onap/ccsdk/data/properties";
32     private static final String PROPERTIES_DIR_KEY = "SDNC_CONFIG_DIR";
33
34     private static final String NETBOX_URL_PROP = "org.onap.ccsdk.sli.adaptors.netbox.url";
35     private static final String NETBOX_API_KEY_PROP = "org.onap.ccsdk.sli.adaptors.netbox.apikey";
36
37     private Properties properties;
38
39     public NetboxPropertiesLighty() {
40         loadProps();
41     }
42
43     public String getHost() {
44         return properties.getProperty(NETBOX_URL_PROP);
45     }
46
47     public String getApiKey() {
48         return properties.getProperty(NETBOX_API_KEY_PROP);
49     }
50
51     private void loadProps() {
52         properties = new Properties();
53         // Try to load config from dir
54         final String ccsdkConfigDir =
55             System.getProperty(PROPERTIES_DIR_KEY, DEFAULT_PROPERTIES_DIR) + "/" + NETBOX_PROPERTY_FILE_NAME;
56         LOG.info("Loading properties from file {}", ccsdkConfigDir);
57         try (FileInputStream in = new FileInputStream(ccsdkConfigDir)) {
58             properties.load(in);
59             LOG.info("Loaded {} properties from file {}", properties.size(), ccsdkConfigDir);
60         } catch (Exception e) {
61             LOG.error("Failed to load properties for file: {} " + NETBOX_PROPERTY_FILE_NAME, e);
62         }
63     }
64 }