Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,7 @@ $ scw inspect myserver | jq '.[0].public_ip.address'

### master (unreleased)

* Use `gotty-client` instead of `termjs-cli`
* 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)
* Added _cs ([#180](https://github.com/scaleway/scaleway-cli/issues/180))
* Report **quotas** in `scw info` ([#130](https://github.com/scaleway/scaleway-cli/issues/130))
Expand Down
35 changes: 8 additions & 27 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"strings"
"time"

"github.com/Sirupsen/logrus"
"github.com/moul/gotty-client"
"github.com/scaleway/scaleway-cli/pkg/sshcommand"
log "github.com/scaleway/scaleway-cli/vendor/github.com/Sirupsen/logrus"
)
Expand Down Expand Up @@ -179,38 +181,17 @@ func RemoveDuplicates(elements []string) []string {
return result
}

const termjsBin string = "termjs-cli"

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

args := []string{}
if !attachStdin {
args = append(args, "--no-stdin")
}
args = append(args, termjsURL)
log.Debugf("Executing: %s %v", termjsBin, args)
// FIXME: check if termjs-cli is installed
spawn := exec.Command(termjsBin, args...)
spawn.Stdout = os.Stdout
spawn.Stdin = os.Stdin
spawn.Stderr = os.Stderr
err := spawn.Run()
logrus.Debug("Connection to ", URL)
gottycli, err := gottyclient.NewClient(URL)
Copy link
Contributor

Choose a reason for hiding this comment

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

We will take advantage of this migration to pass context streams:

Copy link
Contributor

Choose a reason for hiding this comment

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

Also ensure that scw -D will print out the URL

if err != nil {
log.Warnf(`
You need to install '%s' from https://github.com/moul/term.js-cli

npm install -g term.js-cli

However, you can access your serial using a web browser:

%s

`, termjsBin, termjsURL)
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to write the "Press ctrl+Q to quit".

}
return nil
fmt.Println("You are connected, type 'Ctrl+q' to quit.")
return gottycli.Loop()
}

func SSHGetFingerprint(key string) (string, error) {
Expand Down