Switch from golang.org/x/net/websocket to nhooyr.io/websocket and handle NotFound errors (#105)

* Switch from golang.org/x/net/websocket to nhooyr.io/websocket

* Do not attach errors that we can handle to the Gin's context

* Add missing newline to "no credentials specified or found, ..." message

* Fix potential NPE in ChooseUsernameAndPassword()

* Fix type in PortForward() error message in "orchard ssh vm"

* Fix potential NPE in Connections()

* Use header.Set() for consistency's sake for Authorization header
This commit is contained in:
Nikolay Edigaryev
2023-07-04 18:10:41 +04:00
committed by GitHub
parent 3c3b8e8180
commit 6a325daf74
9 changed files with 88 additions and 42 deletions
+7 -12
View File
@@ -56,9 +56,7 @@ func runSSHVM(cmd *cobra.Command, args []string) error {
wsConn, err := client.VMs().PortForward(cmd.Context(), name, 22, wait)
if err != nil {
fmt.Printf("failed to forward an SSH port to VM %s: %v\n", name, err)
return err
return fmt.Errorf("%w: failed to setup port-forwarding to the VM %q: %v", ErrFailed, name, err)
}
defer wsConn.Close()
@@ -78,9 +76,6 @@ func runSSHVM(cmd *cobra.Command, args []string) error {
if err != nil {
return fmt.Errorf("%w: failed to establish an SSH connection: %v", ErrFailed, err)
}
defer func() {
_ = sshConn.Close()
}()
sshClient := ssh.NewClient(sshConn, chans, reqs)
@@ -188,16 +183,16 @@ func ChooseUsernameAndPassword(
// Try to get the credentials from the VM's object stored on controller
vm, err := client.VMs().Get(ctx, vmName)
if err != nil {
fmt.Printf("failed to retrieve VM %s's credentials from the API server: %v\n", vmName, err)
}
if vm.Username != "" && vm.Password != "" {
if err == nil && vm.Username != "" && vm.Password != "" {
return vm.Username, vm.Password
} else if err != nil {
fmt.Fprintf(os.Stderr, "failed to retrieve VM %s's credentials from the API server: %v\n",
vmName, err)
}
// Fall back
_, _ = fmt.Fprintf(os.Stderr, "no credentials specified or found, trying default admin:admin credentials...")
_, _ = fmt.Fprintf(os.Stderr, "no credentials specified or found, "+
"trying default admin:admin credentials...\n")
return "admin", "admin"
}