Skip to content

refactor(token): Read TTLs directly from cache files #542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2025
Merged

Conversation

flexiondotorg
Copy link
Member

This commit refactors the token time-to-live (TTL) checking logic for improved performance, clarity, and robustness.

  • The monolithic TTL checking logic has been split into two distinct functions: get_token_ttl and get_refresh_ttl, each with a single responsibility.
  • Both functions now read expiration timestamps directly from the oidc-token and refresh-token files in the chainctl cache. This avoids executing the chainctl binary, which is significantly faster and prevents the side-effect of triggering an interactive login if a token has expired.
  • A new helper function, get_audience_cache_dir, has been introduced to centralize the logic for constructing cache paths, reducing code duplication.

As a result of these changes, the complex and brittle date-parsing functions (tounix, detect_date_type, try_date_parse) are no longer needed and have been removed, simplifying the script considerably.

This commit refactors the token time-to-live (TTL) checking logic for improved performance, clarity, and robustness.

- The monolithic TTL checking logic has been split into two distinct functions: `get_token_ttl` and `get_refresh_ttl`, each with a single responsibility.
- Both functions now read expiration timestamps directly from the `oidc-token` and `refresh-token` files in the `chainctl` cache. This avoids executing the `chainctl` binary, which is significantly faster and prevents the side-effect of triggering an interactive login if a token has expired.
- A new helper function, `get_audience_cache_dir`, has been introduced to centralize the logic for constructing cache paths, reducing code duplication.

As a result of these changes, the complex and brittle date-parsing functions (`tounix`, `detect_date_type`, `try_date_parse`) are no longer needed and have been removed, simplifying the script considerably.
@flexiondotorg flexiondotorg merged commit c49bdf2 into main Jun 18, 2025
@flexiondotorg flexiondotorg deleted the cg-token branch June 18, 2025 11:02
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