-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* extract get addresses from controllers * reuse dial logic in ssh server
- Loading branch information
1 parent
8de5428
commit c0b0b11
Showing
7 changed files
with
244 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2025 Canonical. | ||
|
||
package ssh | ||
|
||
import ( | ||
goerr "errors" | ||
"fmt" | ||
"net" | ||
"time" | ||
|
||
gossh "golang.org/x/crypto/ssh" | ||
|
||
"github.com/canonical/jimm/v3/internal/errors" | ||
) | ||
|
||
// dialControllerSSHServer dials the controller ssh server, trying the addresses sequentially and returning a go ssh client. | ||
func dialControllerSSHServer(addrs []string, destPort uint32) (*gossh.Client, error) { | ||
var client *gossh.Client | ||
var err error | ||
var errs []error | ||
for _, addr := range addrs { | ||
dest := net.JoinHostPort(addr, fmt.Sprint(destPort)) | ||
client, err = gossh.Dial("tcp", dest, &gossh.ClientConfig{ | ||
//nolint:gosec // this will be removed once we handle hostkeys | ||
HostKeyCallback: gossh.InsecureIgnoreHostKey(), | ||
Auth: []gossh.AuthMethod{ | ||
gossh.PasswordCallback(func() (secret string, err error) { | ||
return "jwt", nil | ||
}), | ||
}, | ||
Timeout: 5 * time.Second, | ||
}) | ||
if err != nil { | ||
errs = append(errs, err) | ||
} | ||
} | ||
if client == nil { | ||
return nil, errors.E(goerr.Join(errs...), "cannot dial controller") | ||
} | ||
return client, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.