fix: replace url script was too rigid
This commit is contained in:
@@ -9,15 +9,20 @@ ROOT = pathlib.Path(__file__).resolve().parents[1]
|
|||||||
|
|
||||||
|
|
||||||
def env(name: str, default: str = "") -> str:
|
def env(name: str, default: str = "") -> str:
|
||||||
value = os.getenv(name, default).strip()
|
return os.getenv(name, default).strip().rstrip("/")
|
||||||
if not value:
|
|
||||||
raise SystemExit(f"missing env: {name}")
|
def infer_base_url(kind: str) -> str:
|
||||||
return value.rstrip("/")
|
hosts = env("DJANGO_ALLOWED_HOSTS") or env("CIE_AUTH_ALLOWED_HOSTS")
|
||||||
|
items = [host.strip() for host in hosts.split(",") if host.strip() and host.strip() != "*"]
|
||||||
|
for host in items:
|
||||||
|
if kind in host:
|
||||||
|
return f"https://{host}"
|
||||||
|
raise SystemExit(f"missing env for {kind}: set explicit base URL or include hostname in allowed hosts")
|
||||||
|
|
||||||
|
|
||||||
TA = env("DJANGO_TRUST_ANCHOR")
|
TA = env("DJANGO_TRUST_ANCHOR") or infer_base_url("fa")
|
||||||
PROVIDER_ISSUER = env("DJANGO_PROVIDER_ISSUER")
|
PROVIDER_ISSUER = env("DJANGO_PROVIDER_ISSUER") or f"{infer_base_url('provider')}/oidc/op"
|
||||||
RP_BASE = env("DJANGO_RP_BASE_URL")
|
RP_BASE = env("DJANGO_RP_BASE_URL") or infer_base_url("rp")
|
||||||
RP_ISSUER = f"{RP_BASE}/oidc/rp"
|
RP_ISSUER = f"{RP_BASE}/oidc/rp"
|
||||||
PROVIDER_BASE = PROVIDER_ISSUER.removesuffix("/oidc/op")
|
PROVIDER_BASE = PROVIDER_ISSUER.removesuffix("/oidc/op")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user