Repository navigation
Warn before the API token expires and explain refused tokens - #25
Merged
Merged
Conversation
A response with Valar-Token-Expires within 14 days prints one warning per run to stderr: when the token expires and where to create a new one. The console link is shown for api.valar.dev; other endpoints are pointed at their console. The token itself is never printed. A 401 whose WWW-Authenticate error_description says the token expired or was revoked returns that reason as an api.TokenRefusedError, and the error output adds how to replace the token, in human and JSON mode. The exit code stays 4. Both buffered requests and log streams are covered.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Makes token expiry visible in the CLI before RFC-0005 release 2 gives every existing user token an expiry 90 days after the upgrade.
Expiry warning. When a response carries
Valar-Token-Expires(RFC 3339) and the token expires within 14 days, the CLI prints one warning per run to stderr, however many requests the command makes:The console link is shown for
api.valar.dev. Other endpoints get "in the Valar console". The token value is never printed.Refused tokens. A 401 whose
WWW-Authenticateerror_descriptionsays the token expired or was revoked becomes anapi.TokenRefusedErrorcarrying that reason, and the error output adds how to replace the token:JSON mode puts the same text in
error.message. The exit code stays 4 (notAllowed). The reason comes from the header, so it shows even if the body isn't JSON. Other 401s ("unknown token", or the current platform's "invalid credentials") are unchanged.Buffered requests and log streams (
streamOnce) both handle the header and the challenge. A followed log stream still stops on a refused token rather than reconnecting.One line in the README says that tokens expire and what the CLI prints.
Pairs with valar/platform#319, #321 and #322
The platform sets
Valar-Token-Expiresand theWWW-Authenticatereason in #321. #319 starts the 90-day expiry of legacy tokens. Release this CLI version before that platform release (2.14.0) is deployed, so users are warned from the first day of the 14-day window. Against today's platform the CLI behaves as before: neither header is sent.Tests
api/token_test.go:TokenRefusedErrorwith the endpoint, for requests and streams, including with a non-JSON body;cmd/token_test.go:reportErroradds the hint in human and JSON output with exit code 4.go vet ./...andgo test ./...pass. I also ran a built binary against a local fake API. It printed the warning once with the service list and exited 0, and printed the expired-token reason with the hint and exited 4 (in JSON mode too).