diff --git a/chord_drs/config.py b/chord_drs/config.py index 9754205..882f975 100644 --- a/chord_drs/config.py +++ b/chord_drs/config.py @@ -1,4 +1,5 @@ import os +import urllib3 from pathlib import Path from dotenv import load_dotenv @@ -25,7 +26,17 @@ def _get_from_environ_or_fail(var: str) -> str: return val -TRUTH_VALUES = ("true", "1") +def str_to_bool(value: str) -> bool: + return value.strip().lower() in ("true", "1", "t", "yes") + + +BENTO_DEBUG: bool = str_to_bool(os.environ.get("BENTO_DEBUG", os.environ.get("FLASK_DEBUG", "false"))) +BENTO_VALIDATE_SSL = str_to_bool(os.environ.get("BENTO_VALIDATE_SSL", str(not BENTO_DEBUG))) + +if not BENTO_VALIDATE_SSL: + # Don't let urllib3 spam us with SSL validation warnings if we're operating with SSL validation off, most likely in + # a development/test context where we're using self-signed certificates. + urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) APP_DIR = Path(__file__).resolve().parent.absolute() @@ -36,7 +47,7 @@ def _get_from_environ_or_fail(var: str) -> str: ) # Authorization variables -AUTHZ_ENABLED = os.environ.get("AUTHZ_ENABLED", "true").strip().lower() in TRUTH_VALUES +AUTHZ_ENABLED = str_to_bool(os.environ.get("AUTHZ_ENABLED", "true")) AUTHZ_URL: str = _get_from_environ_or_fail("BENTO_AUTHZ_SERVICE_URL").strip().rstrip("/") if AUTHZ_ENABLED else "" # MinIO-related, check if the credentials have been provided in a file @@ -65,7 +76,7 @@ class Config: SQLALCHEMY_DATABASE_URI = "sqlite:///" + str(Path(os.path.join(BASEDIR, "db.sqlite3")).expanduser().resolve()) SQLALCHEMY_TRACK_MODIFICATIONS = False - PROMETHEUS_ENABLED: bool = os.environ.get("PROMETHEUS_ENABLED", "false").strip().lower() in TRUTH_VALUES + PROMETHEUS_ENABLED: bool = str_to_bool(os.environ.get("PROMETHEUS_ENABLED", "false")) SERVICE_ID: str = os.environ.get("SERVICE_ID", ":".join(list(SERVICE_TYPE.values())[:2])) SERVICE_DATA_SOURCE: str = DATA_SOURCE_MINIO if MINIO_URL else DATA_SOURCE_LOCAL @@ -76,8 +87,9 @@ class Config: MINIO_USERNAME: str | None = MINIO_USERNAME MINIO_PASSWORD: str | None = MINIO_PASSWORD MINIO_BUCKET: str | None = os.environ.get("MINIO_BUCKET") if MINIO_URL else None - BENTO_DEBUG = os.environ.get("BENTO_DEBUG", os.environ.get("FLASK_DEBUG", "false")).strip().lower() in TRUTH_VALUES - BENTO_CONTAINER_LOCAL = os.environ.get("BENTO_CONTAINER_LOCAL", "false").strip().lower() in TRUTH_VALUES + BENTO_DEBUG: bool = BENTO_DEBUG + BENTO_VALIDATE_SSL: bool = BENTO_VALIDATE_SSL + BENTO_CONTAINER_LOCAL: bool = str_to_bool(os.environ.get("BENTO_CONTAINER_LOCAL", "false")) # Temporary directory to write files to while they're being ingested - useful in containerized contexts, so we can # choose to write temporary files to a volume bound to a host directory with sufficient space for ingesting large