Skip to content

Commit

Permalink
Merge pull request #130 from bento-platform/chore/suppress-urllib3-wa…
Browse files Browse the repository at this point in the history
…rnings

chore: suppress urllib3 warnings when SSL validation is off
  • Loading branch information
davidlougheed authored Sep 20, 2024
2 parents 4358e30 + 39aef4d commit 70ebfe8
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions chord_drs/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import urllib3
from pathlib import Path

from dotenv import load_dotenv
Expand All @@ -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()

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 70ebfe8

Please sign in to comment.