import logging import os import yaml LOG = logging.getLogger(__name__) CONFIG_NAME = 'cis-collector.yml' CONFIG_LOCATIONS = [ '/etc/{conf}'.format(conf=CONFIG_NAME), '{home}/{conf}'.format(home=os.environ.get('HOME'), conf=CONFIG_NAME), '{cwd}/{conf}'.format(cwd=os.getcwd(), conf=CONFIG_NAME), ] def read_config(paths): """Read configuration from all relevant config files.""" current_config = dict() for config_path in paths: try: with open(config_path) as config: current_config.update(yaml.safe_load(config)) except FileNotFoundError: LOG.debug('No config file at %s, skipping...', config_path) LOG.info('Loaded config from %s', config_path) return current_config CONFIG = read_config(CONFIG_LOCATIONS)