add DISABLE_STATIC_AUTH env var

This commit is contained in:
Simon
2025-02-07 22:30:16 +07:00
parent 6275e06db2
commit e351880d48
2 changed files with 16 additions and 4 deletions

View File

@@ -25,6 +25,7 @@ class EnvironmentSettings:
HOST_UID: int = int(environ.get("HOST_UID", False)) HOST_UID: int = int(environ.get("HOST_UID", False))
HOST_GID: int = int(environ.get("HOST_GID", False)) HOST_GID: int = int(environ.get("HOST_GID", False))
ENABLE_CAST: bool = bool(environ.get("ENABLE_CAST")) ENABLE_CAST: bool = bool(environ.get("ENABLE_CAST"))
DISABLE_STATIC_AUTH: bool = bool(environ.get("DISABLE_STATIC_AUTH"))
TZ: str = str(environ.get("TZ", "UTC")) TZ: str = str(environ.get("TZ", "UTC"))
TA_PORT: int = int(environ.get("TA_PORT", False)) TA_PORT: int = int(environ.get("TA_PORT", False))
TA_BACKEND_PORT: int = int(environ.get("TA_BACKEND_PORT", False)) TA_BACKEND_PORT: int = int(environ.get("TA_BACKEND_PORT", False))
@@ -73,6 +74,7 @@ class EnvironmentSettings:
HOST_GID: {self.HOST_GID} HOST_GID: {self.HOST_GID}
TZ: {self.TZ} TZ: {self.TZ}
ENABLE_CAST: {self.ENABLE_CAST} ENABLE_CAST: {self.ENABLE_CAST}
DISABLE_STATIC_AUTH: {self.DISABLE_STATIC_AUTH}
TA_PORT: {self.TA_PORT} TA_PORT: {self.TA_PORT}
TA_BACKEND_PORT: {self.TA_BACKEND_PORT} TA_BACKEND_PORT: {self.TA_BACKEND_PORT}
TA_USERNAME: {self.TA_USERNAME} TA_USERNAME: {self.TA_USERNAME}

View File

@@ -168,25 +168,35 @@ class Command(BaseCommand):
self.stdout.write(self.style.SUCCESS(message)) self.stdout.write(self.style.SUCCESS(message))
def _enable_cast_overwrite(self): def _enable_cast_overwrite(self):
"""cast workaround, remove auth for static files in nginx""" """enable cast env var"""
self.stdout.write("[6] check ENABLE_CAST overwrite") self.stdout.write("[6] check ENABLE_CAST overwrite")
overwrite = EnvironmentSettings.ENABLE_CAST overwrite = EnvironmentSettings.ENABLE_CAST
if not overwrite: if not overwrite:
self.stdout.write(self.style.SUCCESS(" ENABLE_CAST is not set")) self.stdout.write(self.style.SUCCESS(" ENABLE_CAST is not set"))
return return
def _disable_static_auth(self):
"""cast workaround, remove auth for static files in nginx"""
self.stdout.write("[7] check DISABLE_STATIC_AUTH overwrite")
overwrite = EnvironmentSettings.DISABLE_STATIC_AUTH
if not overwrite:
self.stdout.write(
self.style.SUCCESS(" DISABLE_STATIC_AUTH is not set")
)
return
regex = re.compile(r"[^\S\r\n]*auth_request /api/ping/;\n") regex = re.compile(r"[^\S\r\n]*auth_request /api/ping/;\n")
changed = file_overwrite(NGINX, regex, "") changed = file_overwrite(NGINX, regex, "")
if changed: if changed:
message = " ✓ process nginx to enable Cast" message = " ✓ process nginx to disable static auth"
else: else:
message = "Cast is already enabled in nginx" message = " ✓ static auth is already disabled in nginx"
self.stdout.write(self.style.SUCCESS(message)) self.stdout.write(self.style.SUCCESS(message))
def _create_superuser(self): def _create_superuser(self):
"""create superuser if not exist""" """create superuser if not exist"""
self.stdout.write("[7] create superuser") self.stdout.write("[8] create superuser")
is_created = Account.objects.filter(is_superuser=True) is_created = Account.objects.filter(is_superuser=True)
if is_created: if is_created:
message = " superuser already created" message = " superuser already created"