feat: update environment configuration and add script for rewriting dump URLs
This commit is contained in:
+10
-8
@@ -1,8 +1,10 @@
|
|||||||
CIE_AUTH_ALLOWED_HOSTS=cie-auth.example.it,auth.example.it
|
CIE_AUTH_ALLOWED_HOSTS=fa-cie.visionebari.it,provider-cie.visionebari.it,rp-cie.visionebari.it
|
||||||
DJANGO_TRUST_ANCHOR=https://federation-authority.example.it
|
DJANGO_TRUST_ANCHOR=https://fa-cie.visionebari.it
|
||||||
DJANGO_PROVIDER_ISSUER=https://provider.example.it/oidc/op
|
DJANGO_PROVIDER_ISSUER=https://provider-cie.visionebari.it/oidc/op
|
||||||
DJANGO_RP_BACKEND_EXCHANGE_URL=https://visione-backend.example.it/api/v1/auth/cie/exchange
|
DJANGO_RP_DEFAULT_PROVIDER=https://provider-cie.visionebari.it/oidc/op
|
||||||
DJANGO_RP_SHARED_SECRET=change-me
|
DJANGO_RP_BASE_URL=https://rp-cie.visionebari.it
|
||||||
FEDERATION_AUTHORITY_SECRET_KEY=change-me
|
DJANGO_RP_BACKEND_EXCHANGE_URL=https://api.visionebari.it/api/v1/auth/cie/exchange
|
||||||
PROVIDER_SECRET_KEY=change-me
|
DJANGO_RP_SHARED_SECRET=change_me_with_a_secure_random_string
|
||||||
RELYING_PARTY_SECRET_KEY=change-me
|
FEDERATION_AUTHORITY_SECRET_KEY=change_me_with_a_secure_random_string
|
||||||
|
PROVIDER_SECRET_KEY=change_me_with_a_secure_random_string
|
||||||
|
RELYING_PARTY_SECRET_KEY=change_me_with_a_secure_random_string
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ RUN pip install --no-cache-dir --upgrade pip \
|
|||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY entrypoint.sh /entrypoint.sh
|
COPY entrypoint.sh /entrypoint.sh
|
||||||
|
COPY scripts /app/scripts
|
||||||
RUN chmod +x /entrypoint.sh
|
RUN chmod +x /entrypoint.sh
|
||||||
|
|
||||||
ENTRYPOINT ["/entrypoint.sh"]
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ services:
|
|||||||
DJANGO_RP_BACKEND_EXCHANGE_URL: ${DJANGO_RP_BACKEND_EXCHANGE_URL:-http://visione-backend:5555/api/v1/auth/cie/exchange}
|
DJANGO_RP_BACKEND_EXCHANGE_URL: ${DJANGO_RP_BACKEND_EXCHANGE_URL:-http://visione-backend:5555/api/v1/auth/cie/exchange}
|
||||||
DJANGO_RP_SHARED_SECRET: ${DJANGO_RP_SHARED_SECRET:-change-me-for-local-dev}
|
DJANGO_RP_SHARED_SECRET: ${DJANGO_RP_SHARED_SECRET:-change-me-for-local-dev}
|
||||||
DJANGO_RP_DEFAULT_PROVIDER: ${DJANGO_RP_DEFAULT_PROVIDER:-http://provider:8002/oidc/op}
|
DJANGO_RP_DEFAULT_PROVIDER: ${DJANGO_RP_DEFAULT_PROVIDER:-http://provider:8002/oidc/op}
|
||||||
|
DJANGO_RP_BASE_URL: ${DJANGO_RP_BASE_URL:-http://relying-party:8001}
|
||||||
LOAD_FIXTURE_ON_EMPTY_DB: ${RELYING_PARTY_LOAD_FIXTURE_ON_EMPTY_DB:-true}
|
LOAD_FIXTURE_ON_EMPTY_DB: ${RELYING_PARTY_LOAD_FIXTURE_ON_EMPTY_DB:-true}
|
||||||
expose:
|
expose:
|
||||||
- "8001"
|
- "8001"
|
||||||
|
|||||||
+9
-1
@@ -9,8 +9,11 @@ cd "$APP_DIR"
|
|||||||
mkdir -p logs static
|
mkdir -p logs static
|
||||||
|
|
||||||
if [ ! -f "$APP_DIR/db.sqlite3" ] && [ "${LOAD_FIXTURE_ON_EMPTY_DB:-true}" = "true" ]; then
|
if [ ! -f "$APP_DIR/db.sqlite3" ] && [ "${LOAD_FIXTURE_ON_EMPTY_DB:-true}" = "true" ]; then
|
||||||
|
TMP_DUMP="$(mktemp)"
|
||||||
|
python /app/scripts/rewrite_dumps.py dumps/example.json "$TMP_DUMP"
|
||||||
python manage.py migrate
|
python manage.py migrate
|
||||||
python manage.py loaddata dumps/example.json
|
python manage.py loaddata "$TMP_DUMP"
|
||||||
|
rm -f "$TMP_DUMP"
|
||||||
else
|
else
|
||||||
python manage.py migrate
|
python manage.py migrate
|
||||||
fi
|
fi
|
||||||
@@ -19,4 +22,9 @@ fi
|
|||||||
# Collect them into STATIC_ROOT so the explicit /static/ URL can serve them.
|
# Collect them into STATIC_ROOT so the explicit /static/ URL can serve them.
|
||||||
python manage.py collectstatic --noinput
|
python manage.py collectstatic --noinput
|
||||||
|
|
||||||
|
if grep -aEq '127\.0\.0\.1|provider:8002' "$APP_DIR/db.sqlite3"; then
|
||||||
|
echo "Refusing to start: bootstrap data still contains internal/local URLs" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
exec python manage.py runserver 0.0.0.0:"$PORT"
|
exec python manage.py runserver 0.0.0.0:"$PORT"
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import pathlib
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
ROOT = pathlib.Path(__file__).resolve().parents[1]
|
||||||
|
|
||||||
|
|
||||||
|
def env(name: str, default: str = "") -> str:
|
||||||
|
value = os.getenv(name, default).strip()
|
||||||
|
if not value:
|
||||||
|
raise SystemExit(f"missing env: {name}")
|
||||||
|
return value.rstrip("/")
|
||||||
|
|
||||||
|
|
||||||
|
TA = env("DJANGO_TRUST_ANCHOR")
|
||||||
|
PROVIDER_ISSUER = env("DJANGO_PROVIDER_ISSUER")
|
||||||
|
RP_BASE = env("DJANGO_RP_BASE_URL")
|
||||||
|
RP_ISSUER = f"{RP_BASE}/oidc/rp"
|
||||||
|
PROVIDER_BASE = PROVIDER_ISSUER.removesuffix("/oidc/op")
|
||||||
|
|
||||||
|
|
||||||
|
def deep_replace(value):
|
||||||
|
if isinstance(value, dict):
|
||||||
|
return {k: deep_replace(v) for k, v in value.items()}
|
||||||
|
if isinstance(value, list):
|
||||||
|
return [deep_replace(v) for v in value]
|
||||||
|
if isinstance(value, str):
|
||||||
|
return (
|
||||||
|
value.replace("http://127.0.0.1:8000/oidc/op", TA + "/oidc/op")
|
||||||
|
.replace("http://127.0.0.1:8001/oidc/rp", RP_ISSUER)
|
||||||
|
.replace("http://127.0.0.1:8002/oidc/op", PROVIDER_ISSUER)
|
||||||
|
.replace("http://127.0.0.1:8000", TA)
|
||||||
|
.replace("http://127.0.0.1:8001", RP_BASE)
|
||||||
|
.replace("http://127.0.0.1:8002", PROVIDER_BASE)
|
||||||
|
.replace("http://provider:8002/oidc/op", PROVIDER_ISSUER)
|
||||||
|
.replace("http://provider:8002", PROVIDER_BASE)
|
||||||
|
)
|
||||||
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
if len(sys.argv) != 3:
|
||||||
|
raise SystemExit("usage: rewrite_dumps.py <input_dump> <output_dump>")
|
||||||
|
|
||||||
|
src = pathlib.Path(sys.argv[1])
|
||||||
|
dst = pathlib.Path(sys.argv[2])
|
||||||
|
data = json.loads(src.read_text())
|
||||||
|
dst.write_text(json.dumps(deep_replace(data), indent=2, ensure_ascii=False) + "\n")
|
||||||
Reference in New Issue
Block a user