Repository navigation
Conversation
zmofei
added this pull request to stack #90
October 9, 2026 11:34
Requests the CLI sends for itself, starting with telemetry delivery, must not borrow the token behind a user's command. Resolve a separate one: the MAPBOX_CLI_TOKEN override, then the stored login if it is not about to expire (never refreshed, so a background request cannot spend the refresh token), then a token bundled at build time. Nothing calls it yet.
zmofei
removed this pull request from stack #90
October 9, 2026 11:50
zmofei
added this pull request to stack #92
October 9, 2026 11:50
The stored login now wins over MAPBOX_CLI_TOKEN, which applies only when the user is not logged in. The bundled token comes from its own build-time variable, MAPBOX_CLI_BUNDLED_TOKEN, so a token exported in a dev shell is not compiled into local builds, and build.rs refuses anything but pk.
cli_token::send attaches the token itself and moves to the next one on a 401: the default public token kept with the login, then MAPBOX_CLI_TOKEN, then the bundled token. The OAuth login token is never sent as the request's token; it is only read, never refreshed, to fetch the default token when it is missing or was rotated. The save never waits on the credentials lock and never writes into a profile that has logged out or switched account.
The CLI's token is only the fallback for someone with none of their own. --token and MAPBOX_ACCESS_TOKEN now come first, ranked as a command ranks them, and the login's OAuth token is used when the default public token cannot be had.
Every request made with the CLI's token is billed to the account that owns it, so CLI_TOKEN_APIS lists where it may go, by host and path prefix, each with its reason. send() skips the CLI's token for anything else, and a command whose API is listed now falls back to it when the user has no token of their own. The list holds only telemetry today, so no command changes.
The login is loaded with load_fresh_credentials, refresh included, so it never goes stale and there is nothing extra to store, fetch or replace. It is looked for read-only first, so a machine that never logged in does not get a ~/.mapbox from the credentials lock.
Member
Author
|
Merged into #46, which now carries this together with its first caller. |
zmofei
removed this pull request from stack #92
October 9, 2026 14:33
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.
Adds
cli_token::send, which sends a request the CLI makes for itself rather than for a user's command. The first caller will be telemetry delivery to Mapbox Events (#46).The user's own token always comes first; the CLI's token is only the fallback for someone with none. In order:
--tokenorMAPBOX_ACCESS_TOKEN(ranked as commands rank them, viacli_token::user_token), then the stored login, loaded as commands load it with refresh, thenMAPBOX_CLI_TOKENat run time, then apk.token compiled in fromMAPBOX_CLI_BUNDLED_TOKENat build time. A 401 moves on to the next one.sendmay block on the credentials lock and refresh the login, so it is meant for requests nobody is waiting on, such as a detached child. It checks read-only that a login exists first, so a machine that never logged in does not get a~/.mapbox.The built-in token can be extracted from the binary, so
build.rsfails the build unless it is apk.token. A plaincargo buildhas none.The CLI's token is billed to the account that owns it, so it is only sent to the APIs in
CLI_TOKEN_APIS(host, path prefix and reason; today just telemetry). A command whose API is listed falls back to it when the user has no token of their own, with a note on stderr; one whose token is rejected, or run with--use-login, does not.Testing: unit tests cover the order, the fallback and the whitelist. Reverted ten of the guards one at a time and watched their tests fail. Checked by hand that an
sk.bundled token fails the build.cargo build,fmt,clippy -D warningsandcargo testpass. Not tested: against the real API,send's login step end to end,MAPBOX_ACCESS_TOKENread from the environment, or a release build carrying a real token.No caller yet. A background request will use it like this, with the first being telemetry:
Normal commands keep resolving their own token as before. Nothing calls this yet, so no user-visible change and no changelog entry.