Skip to content
This repository was archived by the owner on Jan 17, 2021. It is now read-only.

add ability to select code-server port and disable telemetry #178

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ type rootCmd struct {
syncBack bool
printVersion bool
noReuseConnection bool
disableTelemetry bool
bindAddr string
remotePort string
sshFlags string
uploadCodeServer string
}
Expand All @@ -58,7 +60,9 @@ func (c *rootCmd) RegisterFlags(fl *pflag.FlagSet) {
fl.BoolVar(&c.syncBack, "b", false, "sync extensions back on termination")
fl.BoolVar(&c.printVersion, "version", false, "print version information and exit")
fl.BoolVar(&c.noReuseConnection, "no-reuse-connection", false, "do not reuse SSH connection via control socket")
fl.BoolVar(&c.disableTelemetry, "disable-telemetry", false, "pass --disable-telemetry flag to code-server")
fl.StringVar(&c.bindAddr, "bind", "", "local bind address for SSH tunnel, in [HOST][:PORT] syntax (default: 127.0.0.1)")
fl.StringVar(&c.remotePort, "remote-port", "", "specify remote port on which code-server will be started")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also could be --code-server-port. Which one do you think is better?

fl.StringVar(&c.sshFlags, "ssh-flags", "", "custom SSH flags")
fl.StringVar(&c.uploadCodeServer, "upload-code-server", "", "custom code-server binary to upload to the remote host")
}
Expand Down Expand Up @@ -90,9 +94,11 @@ func (c *rootCmd) Run(fl *pflag.FlagSet) {
skipSync: c.skipSync,
sshFlags: c.sshFlags,
bindAddr: c.bindAddr,
remotePort: c.remotePort,
syncBack: c.syncBack,
reuseConnection: !c.noReuseConnection,
uploadCodeServer: c.uploadCodeServer,
disableTelemetry: c.disableTelemetry,
})

if err != nil {
Expand Down
14 changes: 12 additions & 2 deletions sshcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type options struct {
syncBack bool
noOpen bool
reuseConnection bool
disableTelemetry bool
bindAddr string
remotePort string
sshFlags string
Expand Down Expand Up @@ -140,13 +141,22 @@ func sshCode(host, dir string, o options) error {
flog.Info("synced extensions in %s", time.Since(start))
}

codeServerFlags := []string{
fmt.Sprintf("--bind-addr 127.0.0.1:%v", o.remotePort),
"--auth none",
}
if o.disableTelemetry {
codeServerFlags = append(codeServerFlags, "--disable-telemetry")
}
codeServerCmdStr := fmt.Sprintf("%v %v %v", codeServerPath, dir, strings.Join(codeServerFlags, " "))

flog.Info("starting code-server...")

flog.Info("Tunneling remote port %v to %v", o.remotePort, o.bindAddr)

sshCmdStr :=
fmt.Sprintf("ssh -tt -q -L %v:localhost:%v %v %v '%v %v --host 127.0.0.1 --auth none --port=%v'",
o.bindAddr, o.remotePort, o.sshFlags, host, codeServerPath, dir, o.remotePort,
fmt.Sprintf("ssh -tt -q -L %v:127.0.0.1:%v %v %v '%v'",
Copy link
Author

@gyzerok gyzerok May 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to 127.0.0.1 so it matches what is written in --host just for consistency.

o.bindAddr, o.remotePort, o.sshFlags, host, codeServerCmdStr,
)
// Starts code-server and forwards the remote port.
sshCmd := exec.Command("sh", "-l", "-c", sshCmdStr)
Expand Down