Skip to content

Add created/expires fields to ApiCredentials with expiry check#62

Merged
Michel Edkrantz (MichelEdkrantz) merged 2 commits intomasterfrom
credentials-expiry
Feb 24, 2026
Merged

Add created/expires fields to ApiCredentials with expiry check#62
Michel Edkrantz (MichelEdkrantz) merged 2 commits intomasterfrom
credentials-expiry

Conversation

@MichelEdkrantz
Copy link
Copy Markdown
Member

Summary

  • Adds optional created and expires fields to ApiCredentials as timezone-aware datetime objects, parsed from ISO 8601 strings in the credentials JSON (handles Z suffix and nanosecond precision)
  • Expiry is checked when an auth session is constructed (RequestsAuthSession, HttpxAuthAsyncClient) via _check_expiry, so loading/storing credentials never fails due to expiry — only actually using them does
  • Keyring storage round-trips the datetime fields to/from ISO strings via .isoformat()
  • Adds a _resolve_credentials function returning the full ApiCredentials object; resolve_credentials delegates to it for backwards compatibility

Test plan

  • test_parse_stores_created_and_expires — fields parsed to datetime correctly
  • test_parse_does_not_check_expiry — expired credentials parse without error
  • test_parse_malformed_expires_returns_none — unparseable date becomes None
  • TestCheckExpiry — expired raises ValueError, future/missing does not
  • Full suite passes (uv run pytest)

🤖 Generated with Claude Code

ApiCredentials now carries optional created and expires fields as
timezone-aware datetimes, parsed from the ISO 8601 strings in the
credentials JSON (including Z suffix and nanosecond precision).

Expiry is checked when an auth session is constructed (_check_expiry
called after _resolve_credentials in RequestsAuthSession and
HttpxAuthAsyncClient), so loading/storing credentials never fails
due to expiry — only actually using them does.

Keyring storage serialises the datetime fields back to ISO strings
via .isoformat().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Update test_base_client_sync.py to patch _resolve_credentials (renamed
from resolve_credentials) and return ApiCredentials instead of tuples.

Exclude generated _version.py from ruff.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@MichelEdkrantz Michel Edkrantz (MichelEdkrantz) merged commit 698c1d6 into master Feb 24, 2026
10 checks passed
@MichelEdkrantz Michel Edkrantz (MichelEdkrantz) deleted the credentials-expiry branch February 24, 2026 10:58
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