From b5e81d4f41fb9d419282357b497038511a2df2ec Mon Sep 17 00:00:00 2001 From: Aaron Luna Date: Mon, 8 Jan 2024 00:35:35 -0800 Subject: [PATCH] Add debug print statements for API settings and environment variables --- app/config/__init__.py | 7 +++++++ app/config/api_settings.py | 24 ++++-------------------- app/config/dotenv_file.py | 7 +++++++ app/data/scripts/get_prod_data.py | 11 +++++++++-- 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/app/config/__init__.py b/app/config/__init__.py index 90a80c0..3c9ef6b 100644 --- a/app/config/__init__.py +++ b/app/config/__init__.py @@ -1,5 +1,7 @@ import logging import os +from dataclasses import asdict +from pprint import pprint from app.config.api_settings import UnicodeApiSettings, get_api_settings, get_test_settings @@ -7,6 +9,11 @@ def get_settings() -> UnicodeApiSettings: env = os.environ.get("ENV", "DEV") settings = get_test_settings() if "TEST" in env else get_api_settings() + + print(f"{'#' * 10} API SETTINGS (get_settings) {'#' * 10}\n\n") + pprint(asdict(settings)) + print(f"\n\n{'#' * 34}\n\n") + logger = logging.getLogger("app.api") logger.debug(settings.api_settings_report) logger.debug(settings.rate_limit_settings_report) diff --git a/app/config/api_settings.py b/app/config/api_settings.py index e2ea5ea..138225e 100644 --- a/app/config/api_settings.py +++ b/app/config/api_settings.py @@ -3,6 +3,7 @@ from dataclasses import dataclass, field from datetime import timedelta from pathlib import Path +from pprint import pprint import app.db.models as db from app.config.dotenv_file import read_dotenv_file @@ -179,26 +180,6 @@ def init_data_folders(self) -> None: # pragma: no cover self.PLANES_CSV.unlink() -def get_prod_settings() -> UnicodeApiSettings: # pragma: no cover - settings = { - "ENV": os.environ.get("ENV", "DEV"), - "UNICODE_VERSION": "15.1.0", - "PROJECT_NAME": "Unicode API", - "API_VERSION": "/v1", - "REDIS_PW": os.environ.get("REDIS_PW", ""), - "REDIS_HOST": os.environ.get("REDIS_HOST", ""), - "REDIS_PORT": int(os.environ.get("REDIS_PORT", "6379")), - "REDIS_DB": int(os.environ.get("REDIS_DB", "0")), - "RATE_LIMIT_PER_PERIOD": int(os.environ.get("RATE_LIMIT_PER_PERIOD", "1")), - "RATE_LIMIT_PERIOD_SECONDS": timedelta(seconds=int(os.environ.get("RATE_LIMIT_PERIOD_SECONDS", "100"))), - "RATE_LIMIT_BURST": int(os.environ.get("RATE_LIMIT_BURST", "10")), - "SERVER_NAME": "unicode-api.aaronluna.dev", - "SERVER_HOST": PROD_API_ROOT, - "CACHE_HEADER": "X-UnicodeAPI-Cache", - } - return UnicodeApiSettings(**settings) - - def get_api_settings() -> UnicodeApiSettings: # pragma: no cover env_vars = read_dotenv_file(DOTENV_FILE) settings = { @@ -217,6 +198,9 @@ def get_api_settings() -> UnicodeApiSettings: # pragma: no cover "SERVER_HOST": PROD_API_ROOT, "CACHE_HEADER": "X-UnicodeAPI-Cache", } + print(f"{'#' * 10} SETTINGS DICT (get_api_settings) {'#' * 10}\n\n") + pprint(settings) + print(f"\n\n{'#' * 34}\n\n") return UnicodeApiSettings(**settings) diff --git a/app/config/dotenv_file.py b/app/config/dotenv_file.py index 46d332a..0f53966 100644 --- a/app/config/dotenv_file.py +++ b/app/config/dotenv_file.py @@ -1,5 +1,6 @@ import os from pathlib import Path +from pprint import pprint def read_dotenv_file(dotenv_filepath: Path) -> dict[str, str]: @@ -9,4 +10,10 @@ def read_dotenv_file(dotenv_filepath: Path) -> dict[str, str]: env_var_dict = {v[0]: v[1].strip('"').strip("'").strip() for v in env_var_pairs if len(v) == 2} for var_name, value in env_var_dict.items(): os.environ[var_name] = value + print(f"{'#' * 10} ENV_VAR_PAIRS (read_dotenv_file) {'#' * 10}\n\n") + pprint(env_var_pairs) + print(f"\n\n{'#' * 35}\n\n") + print(f"{'#' * 10} ENV_VAR_DICT (read_dotenv_file) {'#' * 10}\n\n") + pprint(env_var_dict) + print(f"\n\n{'#' * 34}\n\n") return env_var_dict diff --git a/app/data/scripts/get_prod_data.py b/app/data/scripts/get_prod_data.py index 90ed92a..b6e8c89 100644 --- a/app/data/scripts/get_prod_data.py +++ b/app/data/scripts/get_prod_data.py @@ -1,15 +1,22 @@ import logging +from dataclasses import asdict from pathlib import Path +from pprint import pprint from zipfile import ZipFile from app.config import UnicodeApiSettings -from app.config.api_settings import get_prod_settings +from app.config.api_settings import get_api_settings from app.core.result import Result from app.data.util import download_file def get_prod_data() -> Result[None]: - settings = get_prod_settings() + settings = get_api_settings() + + print(f"{'#' * 10} API SETTINGS (get_prod_data) {'#' * 10}\n\n") + pprint(asdict(settings)) + print(f"\n\n{'#' * 34}\n\n") + logger = logging.getLogger("app.api") logger.info( "Begin Process: Bootstrap Unicode Data (ENV: ${settings.ENV}, UNICODE_VERSION: ${settings.UNICODE_VERSION})"