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

import requests
import toml
from dotenv import load_dotenv

log = logging.getLogger(__name__)

load_dotenv()


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

Pierre Dittgen's avatar
Pierre Dittgen committed
17 18 19
API_VALIDATE_ENDPOINT = os.environ.get("API_VALIDATE_ENDPOINT") or None
if API_VALIDATE_ENDPOINT is None:
    log.error("API_VALIDATE_ENDPOINT environment variable is not set, validation is not possible")
20 21 22 23 24 25 26 27 28 29 30 31 32 33

BADGE_CONFIG_URL = os.environ.get("BADGE_CONFIG_URL") or None
BADGE_CONFIG = None
if BADGE_CONFIG_URL is None:
    log.warning("BADGE_CONFIG_URL environment variable is not set, disable badge feature")
else:
    response = requests.get(BADGE_CONFIG_URL)
    if not response.ok:
        log.warning("Can't retrieve badge config from [%s], disable badge feature", BADGE_CONFIG_URL)
    else:
        BADGE_CONFIG = toml.loads(response.text)


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

37 38 39 40 41 42
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)