feat: export state corp exchange sections
This commit is contained in:
@@ -17,12 +17,21 @@ def _require_env(name: str) -> str:
|
||||
return value
|
||||
|
||||
|
||||
def _parse_allowed_hosts(raw_value: str) -> list[str]:
|
||||
def _is_truthy_env(name: str) -> bool:
|
||||
return os.getenv(name, "false").strip().lower() in {"1", "true", "yes", "on"}
|
||||
|
||||
|
||||
def _parse_allowed_hosts(raw_value: str, *, allow_any_host: bool = False) -> list[str]:
|
||||
hosts = [host.strip() for host in raw_value.split(",") if host.strip()]
|
||||
if not hosts:
|
||||
raise ImproperlyConfigured("ALLOWED_HOSTS must contain at least one host")
|
||||
if "*" in hosts:
|
||||
raise ImproperlyConfigured("ALLOWED_HOSTS must not contain '*' in production")
|
||||
if allow_any_host:
|
||||
return ["*"]
|
||||
raise ImproperlyConfigured(
|
||||
"ALLOWED_HOSTS must not contain '*' in production unless "
|
||||
"ALLOW_ANY_HOSTS=true is set"
|
||||
)
|
||||
return hosts
|
||||
|
||||
|
||||
@@ -30,7 +39,10 @@ SECRET_KEY = _require_env("SECRET_KEY")
|
||||
DEBUG = os.getenv("DEBUG", "false").strip().lower() == "true"
|
||||
if DEBUG:
|
||||
raise ImproperlyConfigured("DEBUG must be False in production")
|
||||
ALLOWED_HOSTS = _parse_allowed_hosts(_require_env("ALLOWED_HOSTS"))
|
||||
ALLOWED_HOSTS = _parse_allowed_hosts(
|
||||
_require_env("ALLOWED_HOSTS"),
|
||||
allow_any_host=_is_truthy_env("ALLOW_ANY_HOSTS"),
|
||||
)
|
||||
|
||||
# JWT
|
||||
SIMPLE_JWT["SIGNING_KEY"] = SECRET_KEY
|
||||
|
||||
Reference in New Issue
Block a user