Skip to content

Commit f73f61b

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

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/node/cli.ts

+20-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,10 @@ 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": {
210+
type: "string",
211+
description: "GitHub authentication token (can only be passed in via $GITHUB_TOKEN or the config file).",
212+
},
208213
"proxy-domain": { type: "string[]", description: "Domain used for proxying ports." },
209214
"ignore-last-opened": {
210215
type: "boolean",
@@ -336,6 +341,10 @@ export const parse = (
336341
throw new Error("--hashed-password can only be set in the config file or passed in via $HASHED_PASSWORD")
337342
}
338343

344+
if (key === "github-auth" && !opts?.configFile) {
345+
throw new Error("--github-auth can only be set in the config file or passed in via $GITHUB_TOKEN")
346+
}
347+
339348
const option = options[key]
340349
if (option.type === "boolean") {
341350
;(args[key] as boolean) = true
@@ -409,7 +418,12 @@ export const parse = (
409418

410419
logger.debug(() => [
411420
`parsed ${opts?.configFile ? "config" : "command line"}`,
412-
field("args", { ...args, password: undefined }),
421+
field("args", {
422+
...args,
423+
password: args.password ? "<redacted>" : undefined,
424+
"hashed-password": args["hashed-password"] ? "<redacted>" : undefined,
425+
"github-auth": args["github-auth"] ? "<redacted>" : undefined,
426+
}),
413427
])
414428

415429
return args
@@ -530,9 +544,14 @@ export async function setDefaults(cliArgs: UserProvidedArgs, configArgs?: Config
530544
usingEnvPassword = false
531545
}
532546

547+
if (process.env.GITHUB_TOKEN) {
548+
args["github-auth"] = process.env.GITHUB_TOKEN
549+
}
550+
533551
// Ensure they're not readable by child processes.
534552
delete process.env.PASSWORD
535553
delete process.env.HASHED_PASSWORD
554+
delete process.env.GITHUB_TOKEN
536555

537556
// Filter duplicate proxy domains and remove any leading `*.`.
538557
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_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_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_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)