Skip to content

fix(usage): check dynamic env and add errors=replace in _token_spy_api_key in usage.py - #2826

Open
vaibhavsrv wants to merge 2 commits into
Osmantic:mainfrom
vaibhavsrv:fix/usage-token-spy-api-key-dynamic-env
Open

fix(usage): check dynamic env and add errors=replace in _token_spy_api_key in usage.py#2826
vaibhavsrv wants to merge 2 commits into
Osmantic:mainfrom
vaibhavsrv:fix/usage-token-spy-api-key-dynamic-env

Conversation

@vaibhavsrv

Copy link
Copy Markdown
Contributor

Problem

In ods/extensions/services/dashboard-api/routers/usage.py, _token_spy_api_key() checks module-level TOKEN_SPY_API_KEY, which is evaluated once at import time. If TOKEN_SPY_API_KEY is updated dynamically in os.environ post-import, _token_spy_api_key() returned stale key values. Additionally, reading TOKEN_SPY_KEY_FILE used read_text(encoding="utf-8") without errors="replace" or catching ValueError, causing uncaught decode crashes if key files contained non-standard byte sequences.

Fix

Update _token_spy_api_key() in usage.py to evaluate os.environ.get("TOKEN_SPY_API_KEY") dynamically, pass errors="replace" to read_text(), and catch (OSError, UnicodeError, ValueError).

Verification

Verified syntax with python3 -m py_compile ods/extensions/services/dashboard-api/routers/usage.py. git diff --check passed cleanly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant