Skip to content

Commit

Permalink
Merge pull request #33 from a-luna:fix-gh-action-deploy_attempt-18
Browse files Browse the repository at this point in the history
Add debug print statements for API settings and environment variables
  • Loading branch information
a-luna authored Jan 8, 2024
2 parents 8869b2c + b5e81d4 commit 1036cd0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
7 changes: 7 additions & 0 deletions app/config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
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


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)
Expand Down
24 changes: 4 additions & 20 deletions app/config/api_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand All @@ -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)


Expand Down
7 changes: 7 additions & 0 deletions app/config/dotenv_file.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from pathlib import Path
from pprint import pprint


def read_dotenv_file(dotenv_filepath: Path) -> dict[str, str]:
Expand All @@ -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
11 changes: 9 additions & 2 deletions app/data/scripts/get_prod_data.py
Original file line number Diff line number Diff line change
@@ -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})"
Expand Down

0 comments on commit 1036cd0

Please sign in to comment.