Skip to content

Commit 0cfd10a

Browse files
author
Quentin Perez
committed
Use gotty-client instead of termjs-cli
1 parent 4f4f7ea commit 0cfd10a

File tree

2 files changed

+9
-27
lines changed

2 files changed

+9
-27
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,7 @@ $ scw inspect myserver | jq '.[0].public_ip.address'
11321132

11331133
### master (unreleased)
11341134

1135+
* Use `gotty-client` instead of `termjs-cli`
11351136
* Fix: bad detection of server already started when starting a server ([#224](https://github.com/scaleway/scaleway-cli/pull/224)) - [@arianvp](https://github.com/arianvp)
11361137
* Added _cs ([#180](https://github.com/scaleway/scaleway-cli/issues/180))
11371138
* Report **quotas** in `scw info` ([#130](https://github.com/scaleway/scaleway-cli/issues/130))

pkg/utils/utils.go

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"strings"
2222
"time"
2323

24+
"github.com/Sirupsen/logrus"
25+
"github.com/moul/gotty-client"
2426
"github.com/scaleway/scaleway-cli/pkg/sshcommand"
2527
log "github.com/scaleway/scaleway-cli/vendor/github.com/Sirupsen/logrus"
2628
)
@@ -179,38 +181,17 @@ func RemoveDuplicates(elements []string) []string {
179181
return result
180182
}
181183

182-
const termjsBin string = "termjs-cli"
183-
184-
// AttachToSerial tries to connect to server serial using 'term.js-cli' and fallback with a help message
184+
// AttachToSerial tries to connect to server serial using 'gotty-client' and fallback with a help message
185185
func AttachToSerial(serverID string, apiToken string, attachStdin bool) error {
186-
termjsURL := fmt.Sprintf("https://tty.cloud.online.net?server_id=%s&type=serial&auth_token=%s", serverID, apiToken)
186+
URL := fmt.Sprintf("https://tty.scaleway.com/v2/?arg=%s&arg=%s", apiToken, serverID)
187187

188-
args := []string{}
189-
if !attachStdin {
190-
args = append(args, "--no-stdin")
191-
}
192-
args = append(args, termjsURL)
193-
log.Debugf("Executing: %s %v", termjsBin, args)
194-
// FIXME: check if termjs-cli is installed
195-
spawn := exec.Command(termjsBin, args...)
196-
spawn.Stdout = os.Stdout
197-
spawn.Stdin = os.Stdin
198-
spawn.Stderr = os.Stderr
199-
err := spawn.Run()
188+
logrus.Debug("Connection to ", URL)
189+
gottycli, err := gottyclient.NewClient(URL)
200190
if err != nil {
201-
log.Warnf(`
202-
You need to install '%s' from https://github.com/moul/term.js-cli
203-
204-
npm install -g term.js-cli
205-
206-
However, you can access your serial using a web browser:
207-
208-
%s
209-
210-
`, termjsBin, termjsURL)
211191
return err
212192
}
213-
return nil
193+
fmt.Println("You are connected, type 'Ctrl+q' to quit.")
194+
return gottycli.Loop()
214195
}
215196

216197
func SSHGetFingerprint(key string) (string, error) {

0 commit comments

Comments
 (0)