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)
+ self.conf = yaml.safe_load(f)
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:
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] = {}