Merge branch 'chrda81-feature/docker-secrets'
This commit is contained in:
commit
6b86de59c8
|
@ -2,6 +2,8 @@ import re
|
|||
from os import environ
|
||||
from typing import Any
|
||||
|
||||
from flask import current_app
|
||||
|
||||
from spiffworkflow_backend.config.normalized_environment import normalized_environment
|
||||
|
||||
# Consider: https://flask.palletsprojects.com/en/2.2.x/config/#configuring-from-environment-variables
|
||||
|
@ -15,6 +17,22 @@ def config_from_env(variable_name: str, *, default: str | bool | int | None = No
|
|||
value_from_env = None
|
||||
|
||||
value_to_return: str | bool | int | None = value_from_env
|
||||
# using docker secrets - put file contents to env value
|
||||
if variable_name.endswith("_FILE"):
|
||||
value_from_file = default if value_from_env is None else value_from_env
|
||||
if value_from_file:
|
||||
if isinstance(value_from_file, str) and value_from_file.startswith("/run/secrets"):
|
||||
# rewrite variable name: remove _FILE
|
||||
variable_name = variable_name.removesuffix("_FILE")
|
||||
try:
|
||||
with open(value_from_file) as file:
|
||||
value_to_return = file.read().strip() # Read entire content and strip any extra whitespace
|
||||
except FileNotFoundError:
|
||||
value_to_return = None # Handle the case where the file does not exist
|
||||
except Exception as e:
|
||||
current_app.logger.error(f"Error reading from {value_from_file}: {str(e)}")
|
||||
value_to_return = None # Handle other potential errors
|
||||
|
||||
if value_from_env is not None:
|
||||
if isinstance(default, bool):
|
||||
if value_from_env.lower() == "true":
|
||||
|
|
Loading…
Reference in New Issue