elaborate TA_HOST parsed, #441
This commit is contained in:
parent
a924d648d6
commit
a98a30cc85
|
@ -18,6 +18,7 @@ import ldap
|
||||||
from corsheaders.defaults import default_headers
|
from corsheaders.defaults import default_headers
|
||||||
from django_auth_ldap.config import LDAPSearch
|
from django_auth_ldap.config import LDAPSearch
|
||||||
from home.src.ta.config import AppConfig
|
from home.src.ta.config import AppConfig
|
||||||
|
from home.src.ta.helper import ta_host_parser
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
BASE_DIR = Path(__file__).resolve().parent.parent
|
||||||
|
@ -32,17 +33,7 @@ SECRET_KEY = PW_HASH.hexdigest()
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = bool(environ.get("DJANGO_DEBUG"))
|
DEBUG = bool(environ.get("DJANGO_DEBUG"))
|
||||||
|
|
||||||
ALLOWED_HOSTS = []
|
ALLOWED_HOSTS, CSRF_TRUSTED_ORIGINS = ta_host_parser(environ["TA_HOST"])
|
||||||
if environ.get("TA_HOST"):
|
|
||||||
ALLOWED_HOSTS = [i.strip() for i in environ.get("TA_HOST").split()]
|
|
||||||
|
|
||||||
CSRF_TRUSTED_ORIGINS = []
|
|
||||||
for host in ALLOWED_HOSTS:
|
|
||||||
if host.startswith("http://") or host.startswith("https://"):
|
|
||||||
CSRF_TRUSTED_ORIGINS.append(host)
|
|
||||||
else:
|
|
||||||
CSRF_TRUSTED_ORIGINS.append(f"http://{host}")
|
|
||||||
|
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ import string
|
||||||
import subprocess
|
import subprocess
|
||||||
import unicodedata
|
import unicodedata
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
@ -148,6 +149,22 @@ def is_shorts(youtube_id):
|
||||||
return response.status_code == 200
|
return response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
|
def ta_host_parser(ta_host):
|
||||||
|
"""parse ta_host env var for ALLOWED_HOSTS and CSRF_TRUSTED_ORIGINS"""
|
||||||
|
allowed_hosts = []
|
||||||
|
csrf_trusted_origins = []
|
||||||
|
for host in ta_host.split():
|
||||||
|
host_clean = host.strip()
|
||||||
|
if not host_clean.startswith("http"):
|
||||||
|
host_clean = f"http://{host}"
|
||||||
|
|
||||||
|
parsed = urlparse(host_clean)
|
||||||
|
allowed_hosts.append(f"{parsed.hostname}")
|
||||||
|
csrf_trusted_origins.append(f"{parsed.scheme}://{parsed.hostname}")
|
||||||
|
|
||||||
|
return allowed_hosts, csrf_trusted_origins
|
||||||
|
|
||||||
|
|
||||||
class DurationConverter:
|
class DurationConverter:
|
||||||
"""
|
"""
|
||||||
using ffmpeg to get and parse duration from filepath
|
using ffmpeg to get and parse duration from filepath
|
||||||
|
|
Loading…
Reference in New Issue