From c3c24fe4d2935ae553ddd5a6be192f449b3f4512 Mon Sep 17 00:00:00 2001 From: Anmol Sethi Date: Tue, 6 Oct 2020 21:05:32 -0400 Subject: [PATCH] Fixes for @ammarb --- src/node/cli.ts | 8 ++++---- src/node/coder-cloud.ts | 2 +- src/node/entry.ts | 22 +++++++++------------- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/node/cli.ts b/src/node/cli.ts index 854686685..61e5d9d78 100644 --- a/src/node/cli.ts +++ b/src/node/cli.ts @@ -48,7 +48,7 @@ export interface Args extends VsArgs { readonly "reuse-window"?: boolean readonly "new-window"?: boolean - readonly "coder-link"?: OptionalString + readonly "coder-bind"?: string } interface Option { @@ -159,10 +159,10 @@ const options: Options> = { log: { type: LogLevel }, verbose: { type: "boolean", short: "vvv", description: "Enable verbose logging." }, - "coder-link": { - type: OptionalString, + "coder-bind": { + type: "string", description: ` - Securely link code-server via Coder Cloud with the passed name. You'll get a URL like + Securely bind code-server via Coder Cloud with the passed name. You'll get a URL like https://myname.coder-cloud.com at which you can easily access your code-server instance. Authorization is done via GitHub. Only the first code-server spawned with the current configuration will be accessible.`, diff --git a/src/node/coder-cloud.ts b/src/node/coder-cloud.ts index c8782812b..5f7b7c0a1 100644 --- a/src/node/coder-cloud.ts +++ b/src/node/coder-cloud.ts @@ -9,7 +9,7 @@ import xdgBasedir from "xdg-basedir" const coderCloudAgent = path.resolve(__dirname, "../../lib/coder-cloud-agent") -export async function coderCloudLink(serverName: string): Promise { +export async function coderCloudBind(serverName: string): Promise { const agent = spawn(coderCloudAgent, ["link", serverName], { stdio: ["inherit", "inherit", "pipe"], }) diff --git a/src/node/entry.ts b/src/node/entry.ts index 42abbc2de..1be886e03 100644 --- a/src/node/entry.ts +++ b/src/node/entry.ts @@ -12,7 +12,7 @@ import { StaticHttpProvider } from "./app/static" import { UpdateHttpProvider } from "./app/update" import { VscodeHttpProvider } from "./app/vscode" import { Args, bindAddrFromAllSources, optionDescriptions, parse, readConfigFile, setDefaults } from "./cli" -import { coderCloudLink, coderCloudProxy } from "./coder-cloud" +import { coderCloudBind, coderCloudProxy } from "./coder-cloud" import { AuthType, HttpServer, HttpServerOptions } from "./http" import { loadPlugins } from "./plugin" import { generateCertificate, hash, humanPath, open } from "./util" @@ -36,13 +36,15 @@ const version = pkg.version || "development" const commit = pkg.commit || "development" const main = async (args: Args, cliArgs: Args, configArgs: Args): Promise => { - if (args["coder-link"]) { - // If we're being exposed to the cloud, we listen on a random address. + if (args["coder-bind"]) { + // If we're being exposed to the cloud, we listen on a random address and disable auth. args = { ...args, host: "localhost", port: 0, + auth: AuthType.None, } + logger.info("coder-bind: disabling auth and listening on random localhost port") } if (!args.auth) { @@ -132,8 +134,6 @@ const main = async (args: Args, cliArgs: Args, configArgs: Args): Promise httpServer.proxyDomains.forEach((domain) => logger.info(` - *.${domain}`)) } - coderCloudProxy(serverAddress!) - if (serverAddress && !options.socket && args.open) { // The web socket doesn't seem to work if browsing with 0.0.0.0. const openAddress = serverAddress.replace(/:\/\/0.0.0.0/, "://localhost") @@ -141,16 +141,12 @@ const main = async (args: Args, cliArgs: Args, configArgs: Args): Promise logger.info(`Opened ${openAddress}`) } - if (args["coder-link"]) { - if (!args["coder-link"].value) { - logger.error("You must pass a name to link with coder cloud. See --help") - process.exit(1) - } - - logger.info(`linking code-server to the cloud with name ${args["coder-link"].value}`) + if (args["coder-bind"]) { + logger.info(`linking code-server to the cloud with name ${args["coder-bind"]}`) try { - await coderCloudLink(args["coder-link"].value) + await coderCloudBind(args["coder-bind"]) + coderCloudProxy(serverAddress!) } catch (err) { logger.error(err.message) process.exit(1)