2021-08-03 19:19:33 -04:00
|
|
|
from configparser import ConfigParser
|
|
|
|
import os
|
|
|
|
from typing import Union
|
|
|
|
|
2021-07-19 01:47:39 -04:00
|
|
|
from zope.interface import implementer
|
|
|
|
|
|
|
|
from ceo_common.interfaces import IConfig
|
|
|
|
|
|
|
|
|
|
|
|
@implementer(IConfig)
|
|
|
|
class Config:
|
2021-08-03 19:19:33 -04:00
|
|
|
def __init__(self, config_file: Union[str, None] = None):
|
|
|
|
if config_file is None:
|
|
|
|
config_file = os.environ.get('CEOD_CONFIG', '/etc/csc/ceod.ini')
|
|
|
|
self.config = ConfigParser()
|
|
|
|
self.config.read(config_file)
|
2021-07-19 01:47:39 -04:00
|
|
|
|
|
|
|
def get(self, key: str) -> str:
|
2021-08-03 19:19:33 -04:00
|
|
|
section, subkey = key.split('_', 1)
|
|
|
|
if section in self.config:
|
|
|
|
return self.config[section][subkey]
|
|
|
|
return self.config['DEFAULT'][key]
|