-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(client): prefer CLI arguments, following OpenSSH behaviour #45
Changes from 5 commits
ed016ea
6300714
0012b92
732da5a
1c216c7
274c10b
d11b7fb
5798137
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -400,9 +400,6 @@ func mainWithStatusCode() int { | |
} | ||
|
||
urlHostname, urlPort := parsedUrl.Hostname(), parsedUrl.Port() | ||
if urlPort == "" { | ||
urlPort = "443" | ||
} | ||
|
||
configHostname, configPort, configUser, configAuthMethods, err := ssh3.GetConfigForHost(urlHostname, sshConfig) | ||
if err != nil { | ||
|
@@ -416,14 +413,33 @@ func mainWithStatusCode() int { | |
} | ||
|
||
hostnameIsAnIP := net.ParseIP(hostname) != nil | ||
|
||
port := configPort | ||
if port == -1 && urlPort != "" { | ||
port, err = strconv.Atoi(urlPort) | ||
if err != nil { | ||
log.Error().Msgf("invalid port number: %s: %s", urlPort, err) | ||
// *** Port selection *** | ||
// There are six scenarios: | ||
// | ||
// | CLI port | parse | config port | program behaviour | | ||
// | -------- | ----- | ----------- | -------------------- | | ||
// | yes | nok | yes | throw error and exit | | ||
// | yes | nok | no | throw error and exit | | ||
// | yes | ok | yes | use CLI port | | ||
// | yes | ok | no | use CLI port | | ||
// | no | --- | yes | use config port | | ||
// | no | --- | no | use default port | | ||
|
||
var port int | ||
if urlPort != "" { | ||
if parsedPort, err := strconv.Atoi(urlPort); err != nil || parsedPort > 0xffff { | ||
// use WithLevel(zerolog.FatalLevel) to log a fatal level, but let us handle | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you mind inverting the two parts if this branch ? Putting the non-error case in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, will do. I think this is more a go habit, as most of my |
||
// program termination. log.Fatal() exits with os.Exit(1). | ||
log.WithLevel(zerolog.FatalLevel).Str("Port", urlPort).Err(err).Msg("cli contains an invalid port") | ||
fmt.Fprintf(os.Stderr, "Bad port '%s'\n", urlPort) | ||
return -1 | ||
} else { | ||
port = parsedPort | ||
} | ||
} else if configPort != -1 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add the comment |
||
port = configPort | ||
} else { | ||
port = 443 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a comment, like |
||
} | ||
|
||
username := parsedUrl.User.Username() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall I am not a huge fan of the table. I think we can make it more concise. The error case when the port cannot be parsed seems obvious.
I think it is fine if we just say that the CLI port takes precedence over the config port when specified.