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

fix: Support serialized JSON environment variables #1415

Merged
merged 1 commit into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion querybook/config/querybook_default_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ FLASK_SECRET_KEY: ~
# Url of the querybook site, used for auth callback and notifications
PUBLIC_URL: ''
# Use this config to set cache policy of flask, see https://pythonhosted.org/Flask-Cache/ for details
FLASK_CACHE_CONFIG: '{"CACHE_TYPE": "simple"}'
FLASK_CACHE_CONFIG:
CACHE_TYPE: 'simple'

# --------------- Celery ---------------
REDIS_URL: ~
Expand Down
19 changes: 17 additions & 2 deletions querybook/server/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ class MissingConfigException(Exception):
pass


def is_json(value):
"""
Check if a given value is a valid JSON serialized dict or list
"""
try:
parsed = json.loads(value)
return isinstance(parsed, (dict, list))
except ValueError:
return False


def get_env_config(name, optional=True):
found = True
val = None
Expand All @@ -32,6 +43,9 @@ def get_env_config(name, optional=True):
raise MissingConfigException(
"{} is required to start the process.".format(name)
)
# Check for string-serialized JSON dicts/lists
if isinstance(val, str) and is_json(val):
val = json.loads(val)
return val


Expand All @@ -40,7 +54,8 @@ class QuerybookSettings(object):
PRODUCTION = os.environ.get("production", "false") == "true"
PUBLIC_URL = get_env_config("PUBLIC_URL")
FLASK_SECRET_KEY = get_env_config("FLASK_SECRET_KEY", optional=False)
FLASK_CACHE_CONFIG = json.loads(get_env_config("FLASK_CACHE_CONFIG"))
FLASK_CACHE_CONFIG = get_env_config("FLASK_CACHE_CONFIG")

# Celery
REDIS_URL = get_env_config("REDIS_URL", optional=False)

Expand Down Expand Up @@ -117,7 +132,7 @@ class QuerybookSettings(object):

DB_MAX_UPLOAD_SIZE = int(get_env_config("DB_MAX_UPLOAD_SIZE"))

GOOGLE_CREDS = json.loads(get_env_config("GOOGLE_CREDS") or "null")
GOOGLE_CREDS = get_env_config("GOOGLE_CREDS")

# Logging
LOG_LOCATION = get_env_config("LOG_LOCATION")
Expand Down
Loading