fix: load API bearer token from env var instead of hardcoding (#2) #44
No reviewers
Labels
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/paper-dynasty-card-creation#44
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "ai/paper-dynasty-card-creation-2"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #2
Summary
Removes the hardcoded
PD_API_TOKENbearer token from source files and loads it from the environment instead.Changes
db_calls.py: Addedimport os,from dotenv import load_dotenv, callload_dotenv()at module level, replaced hardcoded token withos.environ.get('PD_API_TOKEN', '').claude/ops-rework/check_prod_missing_ratings.py: Same pattern appliedpyproject.toml: Addedpython-dotenv>=1.0.0as a dependencyHow it works
The
.envfile (already present and gitignored) contains:load_dotenv()loads this file when present, so local dev works automatically. In CI/production, the env var should be set directly.Other observations
Tp3aO3jhYve5NJF1IqOmJTmkwas already committed to git history — Cal should consider rotating it in the Paper Dynasty API admin panel.AI Code Review
Files Reviewed
db_calls.py(modified).claude/ops-rework/check_prod_missing_ratings.py(modified)pyproject.toml(modified)Findings
Correctness
load_dotenv()is called at module level beforeAUTH_TOKENis assigned in both files — ordering is correct.os.environ.get('PD_API_TOKEN', '')falls back to an empty string if the var is unset, producing"Bearer "— API calls will fail with a 401/403. This is acceptable behavior (fails loudly enough in practice), but a startup warning log on empty token would improve DX.Security
Tp3aO3jhYve5NJF1IqOmJTmkis removed from source.Style & Conventions
db_calls.pybeyond the core credential fix (lines inget_req_url,log_return_value,player_desc). These are harmless but outside the stated scope of the PR.Suggestions
PD_API_TOKENis empty so misconfigured environments surface a clear message rather than a silent 401:Verdict: COMMENT (LGTM)
Clean, correct fix. The pattern is applied consistently to both files, the dependency is properly declared, and the load ordering is right. Merge when the hardcoded token has been rotated in the API admin panel (git history remediation is a separate concern and doesn't need to block this PR).
Automated review by Claude PR Reviewer
Pull request closed