1- import * as vscode from "vscode" ;
2-
3- import { type FeatureSet } from "./featureSet" ;
41import { getHeaderArgs } from "./headers" ;
52import { isKeyringSupported } from "./keyringStore" ;
63import { escapeCommandArg } from "./util" ;
74
5+ import type { WorkspaceConfiguration } from "vscode" ;
6+
7+ import type { FeatureSet } from "./featureSet" ;
8+
89export type CliAuth =
910 | { mode : "global-config" ; configDir : string }
1011 | { mode : "url" ; url : string } ;
@@ -13,7 +14,7 @@ export type CliAuth =
1314 * Returns the raw global flags from user configuration.
1415 */
1516export function getGlobalFlagsRaw (
16- configs : Pick < vscode . WorkspaceConfiguration , "get" > ,
17+ configs : Pick < WorkspaceConfiguration , "get" > ,
1718) : string [ ] {
1819 return configs . get < string [ ] > ( "coder.globalFlags" , [ ] ) ;
1920}
@@ -23,7 +24,7 @@ export function getGlobalFlagsRaw(
2324 * Includes either `--global-config` or `--url` depending on the auth mode.
2425 */
2526export function getGlobalFlags (
26- configs : Pick < vscode . WorkspaceConfiguration , "get" > ,
27+ configs : Pick < WorkspaceConfiguration , "get" > ,
2728 auth : CliAuth ,
2829) : string [ ] {
2930 const authFlags =
@@ -39,28 +40,37 @@ export function getGlobalFlags(
3940 ] ;
4041}
4142
43+ /**
44+ * Returns true when the user has keyring enabled and the platform supports it.
45+ */
46+ export function isKeyringEnabled (
47+ configs : Pick < WorkspaceConfiguration , "get" > ,
48+ ) : boolean {
49+ return isKeyringSupported ( ) && configs . get < boolean > ( "coder.useKeyring" , true ) ;
50+ }
51+
4252/**
4353 * Single source of truth: should the extension use the OS keyring for this session?
4454 * Requires CLI >= 2.29.0, macOS or Windows, and the coder.useKeyring setting enabled.
4555 */
46- export function shouldUseKeyring ( featureSet : FeatureSet ) : boolean {
47- return (
48- featureSet . keyringAuth &&
49- isKeyringSupported ( ) &&
50- vscode . workspace . getConfiguration ( ) . get < boolean > ( "coder.useKeyring" , true )
51- ) ;
56+ export function shouldUseKeyring (
57+ configs : Pick < WorkspaceConfiguration , "get" > ,
58+ featureSet : FeatureSet ,
59+ ) : boolean {
60+ return isKeyringEnabled ( configs ) && featureSet . keyringAuth ;
5261}
5362
5463/**
5564 * Resolves how the CLI should authenticate: via the keyring (`--url`) or via
5665 * the global config directory (`--global-config`).
5766 */
5867export function resolveCliAuth (
68+ configs : Pick < WorkspaceConfiguration , "get" > ,
5969 featureSet : FeatureSet ,
6070 deploymentUrl : string | undefined ,
6171 configDir : string ,
6272) : CliAuth {
63- if ( shouldUseKeyring ( featureSet ) && deploymentUrl ) {
73+ if ( shouldUseKeyring ( configs , featureSet ) ) {
6474 return { mode : "url" , url : deploymentUrl } ;
6575 }
6676 return { mode : "global-config" , configDir } ;
@@ -70,7 +80,7 @@ export function resolveCliAuth(
7080 * Returns SSH flags for the `coder ssh` command from user configuration.
7181 */
7282export function getSshFlags (
73- configs : Pick < vscode . WorkspaceConfiguration , "get" > ,
83+ configs : Pick < WorkspaceConfiguration , "get" > ,
7484) : string [ ] {
7585 // Make sure to match this default with the one in the package.json
7686 return configs . get < string [ ] > ( "coder.sshFlags" , [ "--disable-autostart" ] ) ;
0 commit comments