Repository navigation
feat(cli): Pick the stored account from the target org or server #1528
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
Open
+1,337
−118
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5138ed7
feat(cli): Pick the stored account from the target org or server
sentry-junior[bot] 4ddadf8
fix(cli): Avoid snapshotting the env-token host when parsing SaaS URLs
sentry-junior[bot] 333e6bf
fix(cli): Rank automatic account picks by last use
sentry-junior[bot] 38c29a7
fix(cli): Only trust a fresh org list as proof of non-membership
sentry-junior[bot] e63d7c0
ref(cli): Select accounts by recency in SQL, call the pick the defaul…
sentry-junior[bot] f712bad
fix(cli): Keep logins off the org-picked account and clear its stale …
sentry-junior[bot] 57ec430
fix(cli): Match DSN org ids against accounts that only resolved the slug
sentry-junior[bot] a592763
fix(cli): Route an org to its owner when the account in effect cannot…
sentry-junior[bot] 7ab07b6
fix(cli): Keep in-place logins on the active account and env-token ho…
sentry-junior[bot] 0570f1c
fix(cli): Tie in-place logins to the account on the login's server
sentry-junior[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /** | ||
| * Per-invocation account selection. | ||
| * | ||
| * Commands can resolve which stored account to use from what they target | ||
| * (see `selectAccountForOrg` in `auth.ts`). That choice becomes the | ||
| * invocation's default account: every credential read for the rest of the | ||
| * invocation uses it. It is never persisted — the stored active account | ||
| * (`sentry auth login` / `sentry auth switch`) is untouched, so the next | ||
| * invocation starts from scratch and may pick a different account. | ||
| * | ||
| * Why this is keyed by the environment object instead of being a plain | ||
| * module-level variable: | ||
| * | ||
| * - CLI mode runs one command per process. `getEnv()` always returns | ||
| * `process.env`, so there is exactly one scope and this behaves like a | ||
| * module-level variable. | ||
| * - Library mode (`createSentrySDK()`, see `sdk-invoke.ts`) runs many | ||
| * commands inside the consumer's long-lived process, and they | ||
| * can overlap: each call builds its own isolated env copy and runs under | ||
| * `withEnv()` (AsyncLocalStorage), so `getEnv()` returns that copy for | ||
| * everything the call awaits. A module-level variable would be shared by | ||
| * all of them — a call targeting org A would select account 1, and a | ||
| * concurrent (or later) call targeting org B would silently reuse account | ||
| * 1 instead of resolving its own. Keying by the env object gives every | ||
| * call its own scope with no explicit setup or teardown. | ||
| * - A `WeakMap` lets a finished call's scope be garbage-collected together | ||
| * with its env copy, so long-running library consumers do not accumulate | ||
| * one entry per call. | ||
| */ | ||
|
|
||
| import { getEnv } from "../env.js"; | ||
|
|
||
| type AccountScope = { | ||
| /** Default account for the rest of this invocation, chosen from its target. */ | ||
| accountId?: string; | ||
| }; | ||
|
|
||
| /** One scope per invocation env; see the module comment for why. */ | ||
| let scopes = new WeakMap<NodeJS.ProcessEnv, AccountScope>(); | ||
|
|
||
| /** The mutable account selection for the current invocation. */ | ||
| export function getAccountScope(): AccountScope { | ||
| const env = getEnv(); | ||
| let scope = scopes.get(env); | ||
| if (!scope) { | ||
| scope = {}; | ||
| scopes.set(env, scope); | ||
| } | ||
| return scope; | ||
| } | ||
|
|
||
| /** Forget every invocation's account selection. Tests only. */ | ||
| export function resetAccountScopes(): void { | ||
| scopes = new WeakMap(); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.