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 os
import sys import sys
from pathlib import Path from pathlib import Path
...@@ -26,7 +27,10 @@ SITE_ID = 1 ...@@ -26,7 +27,10 @@ SITE_ID = 1
# Must be set if DEBUG is False # Must be set if DEBUG is False
ALLOWED_HOSTS = os.getenv("ALLOWED_HOSTS", default="127.0.0.1,localhost").split(",") 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_CREDENTIALS = True
CORS_ALLOW_HEADERS = list(default_headers) + [ CORS_ALLOW_HEADERS = list(default_headers) + [
"content-disposition", "content-disposition",
...@@ -206,7 +210,10 @@ AURA_PROTO = os.getenv("AURA_PROTO", default="http") ...@@ -206,7 +210,10 @@ AURA_PROTO = os.getenv("AURA_PROTO", default="http")
AURA_HOST = os.getenv("AURA_HOST", default="localhost") 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 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": if AURA_PROTO == "https":
CSRF_TRUSTED_ORIGINS = [f"{AURA_PROTO}://{AURA_HOST}"] CSRF_TRUSTED_ORIGINS = [f"{AURA_PROTO}://{AURA_HOST}"]
...@@ -215,31 +222,35 @@ OPERATION_MODE_TYPE = Literal["default", "tests"] ...@@ -215,31 +222,35 @@ OPERATION_MODE_TYPE = Literal["default", "tests"]
OPERATION_MODE: OPERATION_MODE_TYPE OPERATION_MODE: OPERATION_MODE_TYPE
OPERATION_MODE = cast(OPERATION_MODE_TYPE, os.getenv("OPERATION_MODE", default="default")) OPERATION_MODE = cast(OPERATION_MODE_TYPE, os.getenv("OPERATION_MODE", default="default"))
LOGGING = { # TODO: find a better way. This is limited to settings that can be JSON-encoded.
"version": 1, if "LOGGING_JSON" in os.environ:
"disable_existing_loggers": False, LOGGING = json.loads(os.getenv("LOGGING_JSON"))
"formatters": { else:
"django.server": { LOGGING = {
"()": "django.utils.log.ServerFormatter", "version": 1,
"format": "[{server_time}] {message}", "disable_existing_loggers": False,
"style": "{", "formatters": {
} "django.server": {
}, "()": "django.utils.log.ServerFormatter",
"handlers": { "format": "[{server_time}] {message}",
"file": { "style": "{",
"class": "logging.FileHandler", }
"filename": os.path.abspath(os.path.join(BASE_DIR, "logs", "steering.log")),
"formatter": "django.server",
}, },
}, "handlers": {
"loggers": { "file": {
"django": { "class": "logging.FileHandler",
"handlers": ["file"], "filename": os.path.abspath(os.path.join(BASE_DIR, "logs", "steering.log")),
"level": os.getenv("STEERING_LOG_LEVEL", "INFO"), "formatter": "django.server",
"propagate": True, },
}, },
}, "loggers": {
} "django": {
"handlers": ["file"],
"level": os.getenv("STEERING_LOG_LEVEL", "INFO"),
"propagate": True,
},
},
}
# ATTENTION: # ATTENTION:
# Don’t add any configuration settings after this, so that administrators can override them. # 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