Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make SECRET_KEY configurable from mounted path. #29

Merged
merged 1 commit into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion web/panorama/panorama/settings_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"""

import os
from os import environ as env
from pathlib import Path
import sys


Expand All @@ -15,13 +17,21 @@ def str2bool(s):
return s in TRUTHS


def get_path_variable(env_var, default=""):
"""Utility function to get a secret from the filesystem."""
path = env.get(env_var)
if path is None:
return default
return Path(path).read_text()


# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# SECURITY WARNING: keep the secret key used in production secret!
insecure_key = "insecure"
SECRET_KEY = os.getenv("SECRET_KEY", insecure_key)
SECRET_KEY = get_path_variable("SECRET_KEY_PATH", env.get('SECRET_KEY', insecure_key))

#
MINIMAL_HEALTH_CHECKS = str2bool(os.getenv("MINIMAL_HEALTH_CHECKS", "False"))
Expand Down