config.py 1.39 KB
Newer Older
1
import json
2 3
import logging
import os
Christophe Benz's avatar
Christophe Benz committed
4
import sys
Pierre Dittgen's avatar
Pierre Dittgen committed
5
from pathlib import Path
6 7 8 9 10 11 12 13 14

import requests
import toml
from dotenv import load_dotenv

log = logging.getLogger(__name__)

load_dotenv()

Christophe Benz's avatar
Christophe Benz committed
15 16 17 18 19 20 21 22 23
LOG_LEVEL = os.environ.get("LOG_LEVEL", "INFO")
numeric_log_level = getattr(logging, LOG_LEVEL.upper(), None)
if not isinstance(numeric_log_level, int):
    log.error('Invalid log level: {}'.format(LOG_LEVEL))
logging.basicConfig(
    format="%(levelname)s:%(name)s:%(message)s",
    level=numeric_log_level,
    stream=sys.stderr,  # script outputs data
)
24 25 26

SECRET_KEY = os.environ.get("SECRET_KEY") or None

Pierre Dittgen's avatar
wip  
Pierre Dittgen committed
27 28
API_VALIDATE_ENDPOINT = os.environ.get("API_VALIDATE_ENDPOINT") or None
if API_VALIDATE_ENDPOINT is None:
29
    raise ValueError("API_VALIDATE_ENDPOINT environment variable required")
30 31

SHIELDS_IO_BASE_URL = os.environ.get("SHIELDS_IO_BASE_URL") or None
32
if SHIELDS_IO_BASE_URL and not SHIELDS_IO_BASE_URL.endswith('/'):
33
    SHIELDS_IO_BASE_URL += '/'
Pierre Dittgen's avatar
Pierre Dittgen committed
34

35 36 37 38 39 40
HOMEPAGE_CONFIG_FILE = os.environ.get("HOMEPAGE_CONFIG_FILE") or None
HOMEPAGE_CONFIG = None
if HOMEPAGE_CONFIG_FILE:
    HOMEPAGE_CONFIG_FILE = Path(HOMEPAGE_CONFIG_FILE)
    with HOMEPAGE_CONFIG_FILE.open() as fd:
        HOMEPAGE_CONFIG = json.load(fd)
Christophe Benz's avatar
Christophe Benz committed
41 42 43 44 45 46

MATOMO_AUTH_TOKEN = os.getenv("MATOMO_AUTH_TOKEN") or None
MATOMO_BASE_URL = os.getenv("MATOMO_BASE_URL") or None
MATOMO_SITE_ID = os.getenv("MATOMO_SITE_ID") or None
if MATOMO_SITE_ID:
    MATOMO_SITE_ID = int(MATOMO_SITE_ID)