in otava/config.py [0:0]
def load_config_from(config_file: Path) -> Config:
"""Loads config from the specified location"""
try:
content = expandvars(config_file.read_text(), nounset=True)
yaml = YAML(typ="safe")
config = yaml.load(content)
"""
if Grafana configs not explicitly set in yaml file, default to same as Graphite
server at port 3000
"""
graphite_config = None
grafana_config = None
if "graphite" in config:
if "url" not in config["graphite"]:
raise ValueError("graphite.url")
graphite_config = GraphiteConfig(url=config["graphite"]["url"])
if config.get("grafana") is None:
config["grafana"] = {}
config["grafana"]["url"] = f"{config['graphite']['url'].strip('/')}:3000/"
config["grafana"]["user"] = os.environ.get("GRAFANA_USER", "admin")
config["grafana"]["password"] = os.environ.get("GRAFANA_PASSWORD", "admin")
grafana_config = GrafanaConfig(
url=config["grafana"]["url"],
user=config["grafana"]["user"],
password=config["grafana"]["password"],
)
slack_config = None
if config.get("slack") is not None:
if not config["slack"]["token"]:
raise ValueError("slack.token")
slack_config = SlackConfig(
bot_token=config["slack"]["token"],
)
postgres_config = None
if config.get("postgres") is not None:
if not config["postgres"]["hostname"]:
raise ValueError("postgres.hostname")
if not config["postgres"]["port"]:
raise ValueError("postgres.port")
if not config["postgres"]["username"]:
raise ValueError("postgres.username")
if not config["postgres"]["password"]:
raise ValueError("postgres.password")
if not config["postgres"]["database"]:
raise ValueError("postgres.database")
postgres_config = PostgresConfig(
hostname=config["postgres"]["hostname"],
port=config["postgres"]["port"],
username=config["postgres"]["username"],
password=config["postgres"]["password"],
database=config["postgres"]["database"],
)
bigquery_config = None
if config.get("bigquery") is not None:
bigquery_config = BigQueryConfig(
project_id=config["bigquery"]["project_id"],
dataset=config["bigquery"]["dataset"],
credentials=config["bigquery"]["credentials"],
)
templates = load_templates(config)
tests = load_tests(config, templates)
groups = load_test_groups(config, tests)
return Config(
graphite=graphite_config,
grafana=grafana_config,
slack=slack_config,
postgres=postgres_config,
bigquery=bigquery_config,
tests=tests,
test_groups=groups,
)
except FileNotFoundError as e:
raise ConfigError(f"Configuration file not found: {e.filename}")
except KeyError as e:
raise ConfigError(f"Configuration key not found: {e.args[0]}")
except ValueError as e:
raise ConfigError(f"Value for configuration key not found: {e.args[0]}")