Skip to content

Commit 93d7c5e

Browse files
committed
docs(credentials): correct stale empty-ids semantics
1 parent e442276 commit 93d7c5e

1 file changed

Lines changed: 20 additions & 8 deletions

File tree

‎src/client/credentials.rs‎

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,18 @@ pub fn check_status(profile_config: &config::ProfileConfig) -> AuthStatus {
6060
/// actually run.
6161
///
6262
/// An api-key credential scoped to exactly one workspace (a database API token)
63-
/// pins that workspace. For a multi-workspace or unrestricted api key we honor
64-
/// the saved default (`workspaces set` moves a workspace to the front of the
65-
/// config list) when the key can reach it, otherwise fall back to the
66-
/// credential's own first authorized workspace — never a workspace the gateway
67-
/// would reject. A CLI session uses the saved default. `None` means no default
68-
/// is known and the caller must pass `--workspace-id`.
63+
/// pins that workspace. For a multi-workspace api key we honor the saved
64+
/// default (`workspaces set` moves a workspace to the front of the config list)
65+
/// when the key can reach it, otherwise fall back to the credential's own first
66+
/// authorized workspace. A CLI session uses the saved default. `None` means no
67+
/// default is known and the caller must pass `--workspace-id`.
68+
///
69+
/// The scope comes from a live `GET /workspaces`, so this is best-effort rather
70+
/// than a guarantee: when that probe fails we fall back to the saved default
71+
/// and let the gateway be the one to reject it. Note the consequence for an
72+
/// unrestricted key with no saved default — previously it had no discoverable
73+
/// scope and the caller was forced to pass `--workspace-id`; now it resolves to
74+
/// whichever workspace the API lists first.
6975
pub(crate) fn default_workspace_id(profile_config: &config::ProfileConfig) -> Option<String> {
7076
let saved_default = || {
7177
profile_config
@@ -83,8 +89,14 @@ pub(crate) fn default_workspace_id(profile_config: &config::ProfileConfig) -> Op
8389
if let [only] = ids.as_slice() {
8490
return Some(only.clone());
8591
}
86-
// Multi/unrestricted key: prefer the saved default when the key authorizes
87-
// it (empty `ids` = unrestricted, reaches everything), else the key's first.
92+
// Multi-workspace key: prefer the saved default when the key authorizes it,
93+
// else the key's first.
94+
//
95+
// Empty `ids` no longer means "unrestricted". `api_key_workspace_ids` now
96+
// asks the server, so an unrestricted key comes back with the full list;
97+
// empty means only that we couldn't find out — no key, or the probe failed.
98+
// Honoring the saved default in that case is a deliberate degradation: it's
99+
// the best guess available, and the gateway still rejects it if wrong.
88100
if let Some(first) = saved_default()
89101
&& (ids.is_empty() || ids.contains(&first))
90102
{

0 commit comments

Comments
 (0)