X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_mon%2Fcore%2Fconfig.py;h=815e66e9f61b9f9cd90d7ce54e3c33becd708439;hb=c5bf83e7c59366e0ca0afe94d24f71bcdc123cfc;hp=c4c39729c2f0fdebf8d4f35d9fe4d0661fb8ea44;hpb=5ac7c081ca13495185ecf6bdf302c16c25a4b759;p=osm%2FMON.git diff --git a/osm_mon/core/config.py b/osm_mon/core/config.py index c4c3972..815e66e 100644 --- a/osm_mon/core/config.py +++ b/osm_mon/core/config.py @@ -33,14 +33,14 @@ logger = logging.getLogger(__name__) class Config: - def __init__(self, config_file: str = ''): + def __init__(self, config_file: str = ""): self.conf = {} self._read_config_file(config_file) self._read_env() def _read_config_file(self, config_file): if not config_file: - path = 'mon.yaml' + path = "mon.yaml" config_file = pkg_resources.resource_filename(__name__, path) with open(config_file) as f: self.conf = yaml.load(f) @@ -48,7 +48,7 @@ class Config: def get(self, section, field=None): if not field: return self.conf[section] - return self.conf[section][field] + return self.conf[section].get(field) def set(self, section, field, value): if section not in self.conf: @@ -63,10 +63,12 @@ class Config: if len(elements) < 3: logger.warning( "Environment variable %s=%s does not comply with required format. Section and/or field missing.", - env, os.getenv(env)) + env, + os.getenv(env), + ) continue section = elements[1] - field = '_'.join(elements[2:]) + field = "_".join(elements[2:]) value = os.getenv(env) if section not in self.conf: self.conf[section] = {}