2 * Copyright (C) 2018 Bell Canada.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onap.ccsdk.sli.adaptors.netbox.property;
18 import java.io.FileInputStream;
19 import java.util.Properties;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
24 * THIS CLASS IS A COPY OF {@link NetboxProperties} WITH REMOVED OSGi DEPENDENCIES
26 public class NetboxPropertiesLighty {
28 private static final Logger LOG = LoggerFactory.getLogger(NetboxPropertiesLighty.class);
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";
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";
37 private Properties properties;
39 public NetboxPropertiesLighty() {
43 public String getHost() {
44 return properties.getProperty(NETBOX_URL_PROP);
47 public String getApiKey() {
48 return properties.getProperty(NETBOX_API_KEY_PROP);
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)) {
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);