Skip to content

Commit 7aebe65

Browse files
committed
feat: github-auth flag
This will allow injecting credentials into code-server if you already have them.
1 parent 94f378c commit 7aebe65

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/node/cli.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export interface UserProvidedArgs {
8787
"locate-extension"?: string[]
8888
"show-versions"?: boolean
8989
category?: string
90+
"github-auth"?: string
9091
}
9192

9293
interface Option<T> {
@@ -205,6 +206,7 @@ const options: Options<Required<UserProvidedArgs>> = {
205206
},
206207
"uninstall-extension": { type: "string[]", description: "Uninstall a VS Code extension by id." },
207208
"show-versions": { type: "boolean", description: "Show VS Code extension versions." },
209+
"github-auth": { type: "string", description: "GitHub authentication token (can only be passed in via $GITHUB_AUTH_TOKEN or the config file)." },
208210
"proxy-domain": { type: "string[]", description: "Domain used for proxying ports." },
209211
"ignore-last-opened": {
210212
type: "boolean",
@@ -336,6 +338,10 @@ export const parse = (
336338
throw new Error("--hashed-password can only be set in the config file or passed in via $HASHED_PASSWORD")
337339
}
338340

341+
if (key === "github-auth" && !opts?.configFile) {
342+
throw new Error("--github-auth can only be set in the config file or passed in via $GITHUB_AUTH_TOKEN")
343+
}
344+
339345
const option = options[key]
340346
if (option.type === "boolean") {
341347
;(args[key] as boolean) = true
@@ -409,7 +415,12 @@ export const parse = (
409415

410416
logger.debug(() => [
411417
`parsed ${opts?.configFile ? "config" : "command line"}`,
412-
field("args", { ...args, password: undefined }),
418+
field("args", {
419+
...args,
420+
password: args.password ? "<redacted>" : undefined,
421+
"hashed-password": args["hashed-password"] ? "<redacted>" : undefined,
422+
"github-auth": args["github-auth"] ? "<redacted>" : undefined
423+
}),
413424
])
414425

415426
return args
@@ -530,9 +541,14 @@ export async function setDefaults(cliArgs: UserProvidedArgs, configArgs?: Config
530541
usingEnvPassword = false
531542
}
532543

544+
if (process.env.GITHUB_AUTH_TOKEN) {
545+
args["github-auth"] = process.env.GITHUB_AUTH_TOKEN
546+
}
547+
533548
// Ensure they're not readable by child processes.
534549
delete process.env.PASSWORD
535550
delete process.env.HASHED_PASSWORD
551+
delete process.env.GITHUB_AUTH_TOKEN
536552

537553
// Filter duplicate proxy domains and remove any leading `*.`.
538554
const proxyDomains = new Set((args["proxy-domain"] || []).map((d) => d.replace(/^\*\./, "")))

test/unit/node/cli.test.ts

+19
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,19 @@ describe("parser", () => {
313313
})
314314
})
315315

316+
it("should use env var github token", async () => {
317+
process.env.GITHUB_AUTH_TOKEN = "ga-foo"
318+
const args = parse([])
319+
expect(args).toEqual({})
320+
321+
const defaultArgs = await setDefaults(args)
322+
expect(defaultArgs).toEqual({
323+
...defaults,
324+
"github-auth": "ga-foo",
325+
})
326+
expect(process.env.GITHUB_AUTH_TOKEN).toBe(undefined)
327+
})
328+
316329
it("should error if password passed in", () => {
317330
expect(() => parse(["--password", "supersecret123"])).toThrowError(
318331
"--password can only be set in the config file or passed in via $PASSWORD",
@@ -325,6 +338,12 @@ describe("parser", () => {
325338
)
326339
})
327340

341+
it("should error if github-auth passed in", () => {
342+
expect(() => parse(["--github-auth", "fdas423fs8a"])).toThrowError(
343+
"--github-auth can only be set in the config file or passed in via $GITHUB_AUTH_TOKEN",
344+
)
345+
})
346+
328347
it("should filter proxy domains", async () => {
329348
const args = parse(["--proxy-domain", "*.coder.com", "--proxy-domain", "coder.com", "--proxy-domain", "coder.org"])
330349
expect(args).toEqual({

0 commit comments

Comments
 (0)