diff --git a/ara/server/configs/integration.cfg b/ara/server/configs/integration.cfg index bf449e8..1458f0a 100644 --- a/ara/server/configs/integration.cfg +++ b/ara/server/configs/integration.cfg @@ -2,4 +2,4 @@ debug = true log_level = DEBUG secret_key = integration -allowed_hosts = testserver +allowed_hosts = localhost diff --git a/ara/server/settings.py b/ara/server/settings.py index 15fc11c..d349121 100644 --- a/ara/server/settings.py +++ b/ara/server/settings.py @@ -11,7 +11,7 @@ SECRET_KEY = env("SECRET_KEY") DEBUG = env.bool("DEBUG", default=False) -ALLOWED_HOSTS = env("ALLOWED_HOSTS", cast=list, default=[]) +ALLOWED_HOSTS = env.list("ALLOWED_HOSTS", default=[]) ADMINS = () diff --git a/ara/server/utils.py b/ara/server/utils.py index d625811..1603162 100644 --- a/ara/server/utils.py +++ b/ara/server/utils.py @@ -1,12 +1,47 @@ import os import environ +from configobj import ConfigObj from everett import ConfigurationError -from everett.manager import ConfigEnvFileEnv, ConfigIniEnv, ConfigManager, ConfigOSEnv +from everett.manager import ConfigEnvFileEnv, ConfigIniEnv, ConfigManager, ConfigOSEnv, listify __all__ = ["EverettEnviron"] +class DumbConfigIniEnv(ConfigIniEnv): + """Simple ConfigIniEnv with disabled list parsing that actually aborts after the first file.""" + + # TODO: Remove once upstream is fixed (https://github.com/willkg/everett/pull/71) + + def __init__(self, possible_paths): + self.cfg = {} + possible_paths = listify(possible_paths) + + for path in possible_paths: + if not path: + continue + + path = os.path.abspath(os.path.expanduser(path.strip())) + if path and os.path.isfile(path): + self.cfg = self.parse_ini_file(path) + break + + def parse_ini_file(cls, path): + cfgobj = ConfigObj(path, list_values=False) + + def extract_section(namespace, d): + cfg = {} + for key, val in d.items(): + if isinstance(d[key], dict): + cfg.update(extract_section(namespace + [key], d[key])) + else: + cfg["_".join(namespace + [key]).upper()] = val + + return cfg + + return extract_section([], cfgobj.dict()) + + class EnvironProxy: def __init__(self, cfg): self.cfg = cfg @@ -20,7 +55,7 @@ class EnvironProxy: def __getitem__(self, key): try: - return self.cfg(key) + return self.cfg(key, raw_value=True) except ConfigurationError as err: raise KeyError("Missing key %r" % key) from err @@ -34,7 +69,7 @@ class EverettEnviron(environ.Env): [ ConfigOSEnv(), ConfigEnvFileEnv(".env"), - ConfigIniEnv([os.environ.get("ARA_CFG"), "~/.config/ara/server.cfg", "/etc/ara/server.cfg"]), + DumbConfigIniEnv([os.environ.get("ARA_CFG"), "~/.config/ara/server.cfg", "/etc/ara/server.cfg"]), ] ).with_namespace("ara") )