Skip to content

Commit 5ddf592

Browse files
committed
refactor: address review feedback on global-config
- rename FeatureSet.keyringTokenRead to tokenRead (token subcommand works for both stores) - rename resolveUiUrl to resolveCoderDashboardUrl - clarify openInBrowser docstring (connectionUrl is arbitrary) - split buildGlobalFlags on auth mode to drop the nested ternary
1 parent c76d431 commit 5ddf592

9 files changed

Lines changed: 37 additions & 38 deletions

File tree

src/core/cliCredentialManager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,11 @@ export class CliCredentialManager {
257257
return { kind: "none" };
258258
}
259259
if (isKeyringEnabled(configs) && cli.featureSet.keyringAuth) {
260-
return cli.featureSet.keyringTokenRead
260+
return cli.featureSet.tokenRead
261261
? { kind: "keyring", binPath: cli.binPath }
262262
: { kind: "none" };
263263
}
264-
if (cli.featureSet.keyringTokenRead) {
264+
if (cli.featureSet.tokenRead) {
265265
return cliFileTransport(cli);
266266
}
267267
return { kind: "none" };
@@ -338,7 +338,7 @@ function cliFileTransport(cli: {
338338
return {
339339
kind: "cli-file",
340340
binPath: cli.binPath,
341-
allowOverride: cli.featureSet.keyringTokenRead,
341+
allowOverride: cli.featureSet.tokenRead,
342342
};
343343
}
344344

src/featureSet.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export interface FeatureSet {
77
buildReason: boolean;
88
cliUpdate: boolean;
99
keyringAuth: boolean;
10-
keyringTokenRead: boolean;
10+
tokenRead: boolean;
1111
supportBundle: boolean;
1212
}
1313

@@ -45,8 +45,8 @@ export function featureSetForVersion(
4545
cliUpdate: versionAtLeast(version, "2.24.0"),
4646
// Keyring-backed token storage via `coder login`
4747
keyringAuth: versionAtLeast(version, "2.29.0"),
48-
// `coder login token` for reading tokens from the keyring
49-
keyringTokenRead: versionAtLeast(version, "2.31.0"),
48+
// `coder login token` for reading tokens (keyring or file)
49+
tokenRead: versionAtLeast(version, "2.31.0"),
5050
// `coder support bundle` (officially released/unhidden in 2.10.0)
5151
supportBundle: versionAtLeast(version, "2.10.0"),
5252
};

src/oauth/authorizer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as vscode from "vscode";
22

33
import { CoderApi } from "../api/coderApi";
4-
import { resolveUiUrl } from "../util/uri";
4+
import { resolveCoderDashboardUrl } from "../util/uri";
55

66
import {
77
AUTH_GRANT_TYPE,
@@ -382,7 +382,7 @@ function toBrowserAuthorizationUrl(
382382
): URL {
383383
const endpoint = new URL(authorizationEndpoint);
384384
const connectionBase = new URL(connectionUrl);
385-
const browserBase = new URL(resolveUiUrl(connectionUrl));
385+
const browserBase = new URL(resolveCoderDashboardUrl(connectionUrl));
386386
const connectionPrefix = connectionBase.pathname.replace(/\/$/, "");
387387
const browserPrefix = browserBase.pathname.replace(/\/$/, "");
388388
const underConnection =

src/settings/cli.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,25 @@ function buildGlobalFlags(
5252
escHeader: (s: string) => string,
5353
): string[] {
5454
const userFlags = getExpandedUserGlobalFlags(configs);
55+
const headers = getHeaderArgs(configs, escHeader);
5556

56-
// Honor a user `--global-config` only when allowOverride (file mode, 2.31+);
57-
// otherwise strip it and emit our own so it matches where we read/write.
57+
// Escape after stripping so expansion whitespace stays in one shell token.
58+
const cleanUserFlags = (stripGlobalConfig: boolean) =>
59+
stripManagedFlags(userFlags, stripGlobalConfig).map(escAuth);
60+
61+
// Keyring mode: --url auth; drop user --global-config (would force file storage).
62+
if (auth.mode === "url") {
63+
return [...cleanUserFlags(true), "--url", escAuth(auth.url), ...headers];
64+
}
65+
66+
// File mode: keep the user's --global-config on 2.31+, else emit our own.
5867
const honorOverride =
59-
auth.mode === "global-config" &&
6068
auth.allowOverride &&
6169
userFlags.some((flag) => isFlag(flag, "--global-config"));
62-
63-
// Escape each user flag so expansion-introduced whitespace stays inside
64-
// one shell token. `escAuth` is `identity` on the array path.
65-
const filtered = stripManagedFlags(userFlags, !honorOverride).map(escAuth);
66-
67-
const authFlags =
68-
auth.mode === "url"
69-
? ["--url", escAuth(auth.url)]
70-
: honorOverride
71-
? []
72-
: ["--global-config", escAuth(auth.configDir)];
73-
74-
return [...filtered, ...authFlags, ...getHeaderArgs(configs, escHeader)];
70+
const authFlags = honorOverride
71+
? []
72+
: ["--global-config", escAuth(auth.configDir)];
73+
return [...cleanUserFlags(!honorOverride), ...authFlags, ...headers];
7574
}
7675

7776
function stripManagedFlags(
@@ -129,7 +128,7 @@ export function resolveCliAuth(
129128
return {
130129
mode: "global-config",
131130
configDir,
132-
allowOverride: featureSet.keyringTokenRead,
131+
allowOverride: featureSet.tokenRead,
133132
};
134133
}
135134

src/util/uri.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function normalizeUrl(value: string): string {
2525
* `coder.alternativeWebUrl` setting when configured, otherwise returns
2626
* the connection URL unchanged.
2727
*/
28-
export function resolveUiUrl(connectionUrl: string): string {
28+
export function resolveCoderDashboardUrl(connectionUrl: string): string {
2929
const alt = normalizeUrl(
3030
vscode.workspace
3131
.getConfiguration("coder")
@@ -35,13 +35,13 @@ export function resolveUiUrl(connectionUrl: string): string {
3535
}
3636

3737
/**
38-
* Open a path on the Coder deployment in the user's browser, applying
39-
* `coder.alternativeWebUrl` when configured.
38+
* Open a path in the user's browser, resolved against `coder.alternativeWebUrl`
39+
* when set, otherwise against `connectionUrl`.
4040
*/
4141
export function openInBrowser(
4242
connectionUrl: string,
4343
path: string,
4444
): Thenable<boolean> {
45-
const base = vscode.Uri.parse(resolveUiUrl(connectionUrl));
45+
const base = vscode.Uri.parse(resolveCoderDashboardUrl(connectionUrl));
4646
return vscode.env.openExternal(vscode.Uri.joinPath(base, path));
4747
}

test/unit/api/workspace.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const featureSet: FeatureSet = {
2828
buildReason: true,
2929
cliUpdate: true,
3030
keyringAuth: true,
31-
keyringTokenRead: true,
31+
tokenRead: true,
3232
supportBundle: true,
3333
};
3434

test/unit/core/cliCredentialManager.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ describe("CliCredentialManager", () => {
491491

492492
it("returns undefined when CLI version too old for token read", async () => {
493493
vi.mocked(isKeyringEnabled).mockReturnValue(true);
494-
// 2.30 supports keyringAuth but not keyringTokenRead (requires 2.31+)
494+
// 2.30 supports keyringAuth but not tokenRead (requires 2.31+)
495495
vi.mocked(cliExec.version).mockResolvedValueOnce("2.30.0");
496496
stubExecFile({ stdout: "my-token" });
497497
const { manager } = setup();

test/unit/featureSet.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ describe("check version support", () => {
4848
["v2.29.0", "v2.29.1", "v2.30.0", "v3.0.0"],
4949
);
5050
});
51-
it("keyring token read", () => {
51+
it("token read", () => {
5252
expectFlag(
53-
"keyringTokenRead",
53+
"tokenRead",
5454
["v2.30.0", "v2.29.0", "v2.28.0", "v1.0.0"],
5555
["v2.31.0", "v2.31.1", "v2.32.0", "v3.0.0"],
5656
);

test/unit/util/uri.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
normalizeUrl,
66
openInBrowser,
77
removeTrailingSlashes,
8-
resolveUiUrl,
8+
resolveCoderDashboardUrl,
99
toSafeHost,
1010
} from "@/util/uri";
1111

@@ -51,15 +51,15 @@ describe("normalizeUrl", () => {
5151
});
5252
});
5353

54-
describe("resolveUiUrl", () => {
54+
describe("resolveCoderDashboardUrl", () => {
5555
let configurationProvider: MockConfigurationProvider;
5656

5757
beforeEach(() => {
5858
configurationProvider = new MockConfigurationProvider();
5959
});
6060

6161
it("returns the connection URL when no alternative is configured", () => {
62-
expect(resolveUiUrl("https://coder.example.com:7004")).toBe(
62+
expect(resolveCoderDashboardUrl("https://coder.example.com:7004")).toBe(
6363
"https://coder.example.com:7004",
6464
);
6565
});
@@ -71,7 +71,7 @@ describe("resolveUiUrl", () => {
7171
"returns the connection URL when the alternative is $name",
7272
({ value }) => {
7373
configurationProvider.set("coder.alternativeWebUrl", value);
74-
expect(resolveUiUrl("https://coder.example.com:7004")).toBe(
74+
expect(resolveCoderDashboardUrl("https://coder.example.com:7004")).toBe(
7575
"https://coder.example.com:7004",
7676
);
7777
},
@@ -90,7 +90,7 @@ describe("resolveUiUrl", () => {
9090
{ name: "trims whitespace", value: " https://coder.example.com " },
9191
])("$name", ({ value }) => {
9292
configurationProvider.set("coder.alternativeWebUrl", value);
93-
expect(resolveUiUrl("https://coder.example.com:7004")).toBe(
93+
expect(resolveCoderDashboardUrl("https://coder.example.com:7004")).toBe(
9494
"https://coder.example.com",
9595
);
9696
});

0 commit comments

Comments
 (0)