Skip to content

Commit

Permalink
Make SECRET_KEY configurable from mounted path.
Browse files Browse the repository at this point in the history
  • Loading branch information
jjmurre authored and Yrob committed May 13, 2024
1 parent 1521d3d commit 1b3fd01
Showing 1 changed file with 11 additions and 1 deletion.
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

0 comments on commit 1b3fd01

Please sign in to comment.