Skip to content

Commit

Permalink
chages per review requests
Browse files Browse the repository at this point in the history
Signed-off-by: Matej Vasek <[email protected]>
  • Loading branch information
matejvasek committed Oct 22, 2021
1 parent f50bab9 commit 60c9002
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func tryInitSSHDockerClient() (dockerClient.CommonAPIClient, error) {
dockerClientOpts := []dockerClient.Opt{
dockerClient.WithVersion("1.38"),
dockerClient.WithHTTPClient(httpClient),
dockerClient.WithHost("http://example.com/"),
dockerClient.WithHost("http://dummy/"),
dockerClient.WithDialContext(dialContext),
}
return dockerClient.NewClientWithOpts(dockerClientOpts...)
Expand Down Expand Up @@ -235,7 +235,7 @@ func readSecret(prompt string) (pw []byte, err error) {
}
}

func newPasswordCbk() sshdialer.PasswordCallback {
func newPasswordCbk() sshdialer.SecretCallback {
var pwdSet bool
var pwd string
return func() (string, error) {
Expand All @@ -254,7 +254,7 @@ func newPasswordCbk() sshdialer.PasswordCallback {
}
}

func newPassPhraseCbk() sshdialer.PassPhraseCallback {
func newPassPhraseCbk() sshdialer.SecretCallback {
var pwdSet bool
var pwd string
return func() (string, error) {
Expand Down
17 changes: 9 additions & 8 deletions internal/sshdialer/ssh_dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@ import (
"golang.org/x/crypto/ssh/knownhosts"
)

type PasswordCallback func() (string, error)
type PassPhraseCallback func() (string, error)
type SecretCallback func() (string, error)
type HostKeyCallback func(hostPort string, pubKey ssh.PublicKey) error

type Config struct {
Identity string
PassPhrase string
PasswordCallback PasswordCallback
PassPhraseCallback PassPhraseCallback
PasswordCallback SecretCallback
PassPhraseCallback SecretCallback
HostKeyCallback HostKeyCallback
}

const defaultSSHPort = "22"

func NewDialContext(url *urlPkg.URL, config Config) (func(ctx context.Context, network, addr string) (net.Conn, error), error) {
sshConfig, err := NewSSHClientConfig(url, config)
if err != nil {
Expand All @@ -44,7 +45,7 @@ func NewDialContext(url *urlPkg.URL, config Config) (func(ctx context.Context, n

port := url.Port()
if port == "" {
port = "22"
port = defaultSSHPort
}
host := url.Hostname()

Expand Down Expand Up @@ -319,7 +320,7 @@ func NewSSHClientConfig(url *urlPkg.URL, credentialsConfig Config) (*ssh.ClientC
return clientConfig, nil
}

func publicKey(path string, passphrase []byte, passPhraseCallback PassPhraseCallback) (ssh.Signer, error) {
func publicKey(path string, passphrase []byte, passPhraseCallback SecretCallback) (ssh.Signer, error) {
key, err := ioutil.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("failed to read key file: %w", err)
Expand Down Expand Up @@ -348,7 +349,7 @@ func publicKey(path string, passphrase []byte, passPhraseCallback PassPhraseCall

func createHostKeyCallback(hostKeyCallback HostKeyCallback) func(hostPort string, remote net.Addr, key ssh.PublicKey) error {
return func(hostPort string, remote net.Addr, pubKey ssh.PublicKey) error {
host, port := hostPort, "22"
host, port := hostPort, defaultSSHPort
if _h, _p, err := net.SplitHostPort(host); err == nil {
host, port = _h, _p
}
Expand Down Expand Up @@ -381,7 +382,7 @@ func createHostKeyCallback(hostKeyCallback HostKeyCallback) func(hostPort string
}

for _, hp := range hostPorts {
h, p := hp, "22"
h, p := hp, defaultSSHPort
if _h, _p, err := net.SplitHostPort(hp); err == nil {
h, p = _h, _p
}
Expand Down

0 comments on commit 60c9002

Please sign in to comment.