Skip to content
Snippets Groups Projects
Verified Commit a2f77ab9 authored by Ernesto Rico Schmidt's avatar Ernesto Rico Schmidt
Browse files

feat: read CORS_ALLOWED_ORIGINS, SITE_URL & LOGGING_JSON from the env

parent 94438c48
No related branches found
No related tags found
No related merge requests found
Pipeline #8415 passed
import json
import os
import sys
from pathlib import Path
......@@ -26,7 +27,10 @@ SITE_ID = 1
# Must be set if DEBUG is False
ALLOWED_HOSTS = os.getenv("ALLOWED_HOSTS", default="127.0.0.1,localhost").split(",")
CORS_ALLOWED_ORIGINS = ["http://localhost:8080", "http://localhost:8040"]
CORS_ALLOWED_ORIGINS = os.getenv(
"CORS_ALLOWED_ORIGINS",
default="http://localhost:8080,http://localhost:8040",
).split(",")
CORS_ALLOW_CREDENTIALS = True
CORS_ALLOW_HEADERS = list(default_headers) + [
"content-disposition",
......@@ -206,7 +210,10 @@ AURA_PROTO = os.getenv("AURA_PROTO", default="http")
AURA_HOST = os.getenv("AURA_HOST", default="localhost")
# SITE_URL is used by django-oidc-provider and openid-configuration will break if not set correctly
SITE_URL = f"{AURA_PROTO}://{AURA_HOST}:{PORT}" if PORT else f"{AURA_PROTO}://{AURA_HOST}"
SITE_URL = os.getenv(
"SITE_URL",
default=f"{AURA_PROTO}://{AURA_HOST}:{PORT}" if PORT else f"{AURA_PROTO}://{AURA_HOST}",
)
if AURA_PROTO == "https":
CSRF_TRUSTED_ORIGINS = [f"{AURA_PROTO}://{AURA_HOST}"]
......@@ -215,31 +222,35 @@ OPERATION_MODE_TYPE = Literal["default", "tests"]
OPERATION_MODE: OPERATION_MODE_TYPE
OPERATION_MODE = cast(OPERATION_MODE_TYPE, os.getenv("OPERATION_MODE", default="default"))
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"django.server": {
"()": "django.utils.log.ServerFormatter",
"format": "[{server_time}] {message}",
"style": "{",
}
},
"handlers": {
"file": {
"class": "logging.FileHandler",
"filename": os.path.abspath(os.path.join(BASE_DIR, "logs", "steering.log")),
"formatter": "django.server",
# TODO: find a better way. This is limited to settings that can be JSON-encoded.
if "LOGGING_JSON" in os.environ:
LOGGING = json.loads(os.getenv("LOGGING_JSON"))
else:
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"django.server": {
"()": "django.utils.log.ServerFormatter",
"format": "[{server_time}] {message}",
"style": "{",
}
},
},
"loggers": {
"django": {
"handlers": ["file"],
"level": os.getenv("STEERING_LOG_LEVEL", "INFO"),
"propagate": True,
"handlers": {
"file": {
"class": "logging.FileHandler",
"filename": os.path.abspath(os.path.join(BASE_DIR, "logs", "steering.log")),
"formatter": "django.server",
},
},
},
}
"loggers": {
"django": {
"handlers": ["file"],
"level": os.getenv("STEERING_LOG_LEVEL", "INFO"),
"propagate": True,
},
},
}
# ATTENTION:
# Don’t add any configuration settings after this, so that administrators can override them.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment