Skip to content

Commit ba8c796

Browse files
committed
refactor: parse options with multiple = in cli
There was a case with the hashed-password which had multiple equal signs in the value and it wasn't being parsed correctly. This uses a new function and adds a few tests.
1 parent 97fb071 commit ba8c796

File tree

5 files changed

+54
-42
lines changed

5 files changed

+54
-42
lines changed

docs/FAQ.md

+32-34
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,38 @@
22
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
33
# FAQ
44

5-
- [FAQ](#faq)
6-
- [Questions?](#questions)
7-
- [iPad Status?](#ipad-status)
8-
- [Community Projects (awesome-code-server)](#community-projects-awesome-code-server)
9-
- [How can I reuse my VS Code configuration?](#how-can-i-reuse-my-vs-code-configuration)
10-
- [Differences compared to VS Code?](#differences-compared-to-vs-code)
11-
- [Installing an extension](#installing-an-extension)
12-
- [How can I request a missing extension?](#how-can-i-request-a-missing-extension)
13-
- [Installing an extension manually](#installing-an-extension-manually)
14-
- [How do I configure the marketplace URL?](#how-do-i-configure-the-marketplace-url)
15-
- [Where are extensions stored?](#where-are-extensions-stored)
16-
- [How is this different from VS Code Codespaces?](#how-is-this-different-from-vs-code-codespaces)
17-
- [How should I expose code-server to the internet?](#how-should-i-expose-code-server-to-the-internet)
18-
- [Can I store my password hashed?](#can-i-store-my-password-hashed)
19-
- [How do I securely access web services?](#how-do-i-securely-access-web-services)
20-
- [Sub-paths](#sub-paths)
21-
- [Sub-domains](#sub-domains)
22-
- [Why does the code-server proxy strip `/proxy/<port>` from the request path?](#why-does-the-code-server-proxy-strip-proxyport-from-the-request-path)
23-
- [Proxying to Create React App](#proxying-to-create-react-app)
24-
- [Multi-tenancy](#multi-tenancy)
25-
- [Docker in code-server container?](#docker-in-code-server-container)
26-
- [How can I disable telemetry?](#how-can-i-disable-telemetry)
27-
- [How does code-server decide what workspace or folder to open?](#how-does-code-server-decide-what-workspace-or-folder-to-open)
28-
- [How do I debug issues with code-server?](#how-do-i-debug-issues-with-code-server)
29-
- [Heartbeat File](#heartbeat-file)
30-
- [Healthz endpoint](#healthz-endpoint)
31-
- [How does the config file work?](#how-does-the-config-file-work)
32-
- [Isn't an install script piped into sh insecure?](#isnt-an-install-script-piped-into-sh-insecure)
33-
- [How do I make my keyboard shortcuts work?](#how-do-i-make-my-keyboard-shortcuts-work)
34-
- [How do I access my Documents/Downloads/Desktop folders in code-server on OSX?](#how-do-i-access-my-documentsdownloadsdesktop-folders-in-code-server-on-osx)
35-
- [Differences compared to Theia?](#differences-compared-to-theia)
36-
- [`$HTTP_PROXY`, `$HTTPS_PROXY`, `$NO_PROXY`](#http_proxy-https_proxy-no_proxy)
37-
- [Enterprise](#enterprise)
5+
- [Questions?](#questions)
6+
- [iPad Status?](#ipad-status)
7+
- [Community Projects (awesome-code-server)](#community-projects-awesome-code-server)
8+
- [How can I reuse my VS Code configuration?](#how-can-i-reuse-my-vs-code-configuration)
9+
- [Differences compared to VS Code?](#differences-compared-to-vs-code)
10+
- [Installing an extension](#installing-an-extension)
11+
- [How can I request a missing extension?](#how-can-i-request-a-missing-extension)
12+
- [Installing an extension manually](#installing-an-extension-manually)
13+
- [How do I configure the marketplace URL?](#how-do-i-configure-the-marketplace-url)
14+
- [Where are extensions stored?](#where-are-extensions-stored)
15+
- [How is this different from VS Code Codespaces?](#how-is-this-different-from-vs-code-codespaces)
16+
- [How should I expose code-server to the internet?](#how-should-i-expose-code-server-to-the-internet)
17+
- [Can I store my password hashed?](#can-i-store-my-password-hashed)
18+
- [How do I securely access web services?](#how-do-i-securely-access-web-services)
19+
- [Sub-paths](#sub-paths)
20+
- [Sub-domains](#sub-domains)
21+
- [Why does the code-server proxy strip `/proxy/<port>` from the request path?](#why-does-the-code-server-proxy-strip-proxyport-from-the-request-path)
22+
- [Proxying to Create React App](#proxying-to-create-react-app)
23+
- [Multi-tenancy](#multi-tenancy)
24+
- [Docker in code-server container?](#docker-in-code-server-container)
25+
- [How can I disable telemetry?](#how-can-i-disable-telemetry)
26+
- [How does code-server decide what workspace or folder to open?](#how-does-code-server-decide-what-workspace-or-folder-to-open)
27+
- [How do I debug issues with code-server?](#how-do-i-debug-issues-with-code-server)
28+
- [Heartbeat File](#heartbeat-file)
29+
- [Healthz endpoint](#healthz-endpoint)
30+
- [How does the config file work?](#how-does-the-config-file-work)
31+
- [Isn't an install script piped into sh insecure?](#isnt-an-install-script-piped-into-sh-insecure)
32+
- [How do I make my keyboard shortcuts work?](#how-do-i-make-my-keyboard-shortcuts-work)
33+
- [How do I access my Documents/Downloads/Desktop folders in code-server on OSX?](#how-do-i-access-my-documentsdownloadsdesktop-folders-in-code-server-on-osx)
34+
- [Differences compared to Theia?](#differences-compared-to-theia)
35+
- [`$HTTP_PROXY`, `$HTTPS_PROXY`, `$NO_PROXY`](#http_proxy-https_proxy-no_proxy)
36+
- [Enterprise](#enterprise)
3837

3938
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
4039

@@ -209,7 +208,6 @@ Yes you can! Set the value of `hashed-password` instead of `password`. Generate
209208
```shell
210209
echo -n "password" | npx argon2-cli -e
211210
$argon2i$v=19$m=4096,t=3,p=1$wst5qhbgk2lu1ih4dmuxvg$ls1alrvdiwtvzhwnzcm1dugg+5dto3dt1d5v9xtlws4
212-
213211
```
214212

215213
Of course replace `thisismypassword` with your actual password and **remember to put it inside quotes**!

src/node/cli.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,7 @@ export const parse = (
289289
let key: keyof Args | undefined
290290
let value: string | undefined
291291
if (arg.startsWith("--")) {
292-
// TODO fix this
293-
const split = arg.replace(/^--/, "").split("=", 2)
292+
const split = splitOnFirstEquals(arg.replace(/^--/, ""))
294293
key = split[0] as keyof Args
295294
value = split[1]
296295
} else {
@@ -563,7 +562,6 @@ export function parseConfigFile(configFile: string, configPath: string): ConfigA
563562
const config = yaml.load(configFile, {
564563
filename: configPath,
565564
})
566-
console.log("what is this config", config)
567565
if (!config || typeof config === "string") {
568566
throw new Error(`invalid config: ${config}`)
569567
}
@@ -576,11 +574,9 @@ export function parseConfigFile(configFile: string, configPath: string): ConfigA
576574
}
577575
return `--${optName}=${opt}`
578576
})
579-
console.log("what are the configFileArgv", configFileArgv)
580577
const args = parse(configFileArgv, {
581578
configFile: configPath,
582579
})
583-
console.log(args, "args")
584580
return {
585581
...args,
586582
config: configPath,

test/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@
1818
"resolutions": {
1919
"@playwright/test/playwright": "^1.11.0-next-alpha-apr-13-2021"
2020
},
21-
"dependencies": {
22-
}
21+
"dependencies": {}
2322
}

test/unit/cli.test.ts

+15
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,21 @@ describe("parser", () => {
349349
],
350350
})
351351
})
352+
it("should parse options with double-dash and multiple equal signs ", async () => {
353+
const args = parse(
354+
[
355+
"--hashed-password=$argon2i$v=19$m=4096,t=3,p=1$0qr/o+0t00hsbjfqcksfdq$ofcm4rl6o+b7oxpua4qlxubypbbpsf+8l531u7p9hyy",
356+
],
357+
{
358+
configFile: "/pathtoconfig",
359+
},
360+
)
361+
expect(args).toEqual({
362+
_: [],
363+
"hashed-password":
364+
"$argon2i$v=19$m=4096,t=3,p=1$0qr/o+0t00hsbjfqcksfdq$ofcm4rl6o+b7oxpua4qlxubypbbpsf+8l531u7p9hyy",
365+
})
366+
})
352367
})
353368

354369
describe("cli", () => {

typings/pluginapi.d.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ export const proxy: ProxyServer
145145
/**
146146
* Middleware to ensure the user is authenticated. Throws if they are not.
147147
*/
148-
export function ensureAuthenticated(req: express.Request, res?: express.Response, next?: express.NextFunction): Promise<void>
148+
export function ensureAuthenticated(
149+
req: express.Request,
150+
res?: express.Response,
151+
next?: express.NextFunction,
152+
): Promise<void>
149153

150154
/**
151155
* Returns true if the user is authenticated.

0 commit comments

Comments
 (0)