"""SDB interface
"""
import json
import os.path as osp
from ecpi.common import add_path_root_eclairs
ECLAIRS_CONFIG_FILE = add_path_root_eclairs(osp.join("server", "envtest",
"with_messagering", "eclairs-conf.json"))
AVAILABLE_SERVICES = ['nats', 'sdb', 'caldb']
[docs]class ExternalConfiguration(object):
"""Container for external configuration
"""
def __init__(self, service, cfg_file=None):
"""**constructor**
Instanciate configuration for external services (messaging, SDB and CALDB).
:param service: name of the service for the url/port infos to be stored.
Service name must be in AVAILABLE_SERVICES
:type service: str
:param cfg_file: path to external services config file. Default is None.
:type cfg_file: str
"""
assert service in AVAILABLE_SERVICES
if cfg_file is None:
json_content = loadjson(ECLAIRS_CONFIG_FILE)
else:
json_content = loadjson(cfg_file)
self.infos = json_content['services'][service]
[docs]def loadjson(json_filename):
"""Load any .json file content in memory.
:param json_filename: file name of the .json file to be loaded
:type json_filename: str
:return: infos contained in .json file
:rtype: dict
"""
with open(json_filename, 'r') as f:
data = f.read()
return json.loads(data)