Skip to content

Commit a7a5f42

Browse files
more env specific stuff
1 parent e8763bf commit a7a5f42

3 files changed

Lines changed: 27 additions & 30 deletions

File tree

src/solesearch_api/config.py

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,34 @@
11
import os
22

3-
DB_URL = os.environ.get("DB_CONNECTION_STRING")
3+
REQUIRED_PROD_ENV_VARS = [
4+
"LOGFIRE_TOKEN",
5+
"DB_CONNECTION_STRING",
6+
"CELERY_BROKER_URL",
7+
"CELERY_RESULT_BACKEND",
8+
"AWS_HEALTHCHECK_URL",
9+
"AWS_ACCESS_KEY_ID",
10+
"AWS_SECRET_ACCESS_KEY",
11+
"AWS_REGION",
12+
]
13+
14+
if not os.environ.get("ENVIRONMENT"):
15+
raise OSError("ENVIRONMENT environment variable not set.")
416

5-
if not DB_URL:
6-
raise OSError("DB_CONNECTION_STRING environment variable not set.")
17+
if os.environ.get("ENVIRONMENT") == "prod":
18+
for var in REQUIRED_PROD_ENV_VARS:
19+
if not os.environ.get(var):
20+
raise OSError(f"{var} environment variable not set.")
721

22+
DB_URL = os.environ.get("DB_CONNECTION_STRING")
823
CELERY_BROKER = os.environ.get("CELERY_BROKER_URL")
9-
10-
if not CELERY_BROKER:
11-
raise OSError("CELERY_BROKER_URL environment variable not set.")
12-
1324
CELERY_BACKEND = os.environ.get("CELERY_RESULT_BACKEND")
14-
15-
if not CELERY_BACKEND:
16-
raise OSError("CELERY_RESULT_BACKEND environment variable not set.")
17-
1825
ENVIRONMENT = os.environ.get("ENVIRONMENT")
1926

20-
if not ENVIRONMENT:
21-
raise OSError("ENVIRONMENT environment variable not set.")
22-
2327
AWS_HEALTHCHECK_URL = os.environ.get("AWS_HEALTHCHECK_URL")
2428
AWS_ACCESS_KEY_ID = os.environ.get("AWS_ACCESS_KEY_ID")
2529
AWS_SECRET_ACCESS_KEY = os.environ.get("AWS_SECRET_ACCESS_KEY")
2630
AWS_REGION = os.environ.get("AWS_REGION", "us-east-1")
2731

28-
if not AWS_HEALTHCHECK_URL:
29-
raise OSError("AWS_HEALTHCHECK_URL environment variable not set.")
30-
31-
if not AWS_ACCESS_KEY_ID:
32-
raise OSError("AWS_ACCESS_KEY_ID environment variable not set.")
33-
34-
if not AWS_SECRET_ACCESS_KEY:
35-
raise OSError("AWS_SECRET_ACCESS_KEY environment variable not set.")
36-
3732
DATA_DIR = "/var/data/solesearch"
3833
HTML_DIR = os.path.join(DATA_DIR, "html")
3934
JSON_DIR = os.path.join(DATA_DIR, "json")

src/solesearch_api/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from fastapi_pagination import add_pagination
1212
from starlette.middleware.sessions import SessionMiddleware
1313

14+
from solesearch_api.config import ENVIRONMENT
1415
from solesearch_api.db import initialize_db
1516
from solesearch_api.routes import auth, scrape, sneakers
1617

@@ -38,7 +39,7 @@
3839
)
3940

4041
# Configure Logfire
41-
logfire.configure()
42+
logfire.configure(environment=ENVIRONMENT)
4243
logfire.instrument_fastapi(app)
4344
logger = logging.getLogger(__name__)
4445

src/solesearch_api/tasks/alerting/healthcheck.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313

1414
logger = logging.getLogger(__name__)
1515

16-
auth = AWS4Auth(
17-
AWS_ACCESS_KEY_ID,
18-
AWS_SECRET_ACCESS_KEY,
19-
AWS_REGION,
20-
"execute-api",
21-
)
16+
if ENVIRONMENT == "production":
17+
auth = AWS4Auth(
18+
AWS_ACCESS_KEY_ID,
19+
AWS_SECRET_ACCESS_KEY,
20+
AWS_REGION,
21+
"execute-api",
22+
)
2223

2324

2425
@app.task(name="solesearch_api.tasks.alerting.healthcheck")

0 commit comments

Comments
 (0)