-
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
Conversation
The client prefered using values from the config file. The expected behaviour is to prefer vales from the CLI and fill the missing ones with defaults in the configuration files. This commit fixes 35 by prefering CLI over config. fix 35
ed016ea fixed the config port being preferred over the CLI port, but introduced a bug where the default was preferred over the config port. This commit addresses this by setting the default port only after checking config port availability.
Follow OpenSSH behaviour and prefer using the in configuration set hostname over the one in the CLI. fix: 35
The integration test suite might be a bit agressive sometimes, I'll run it locally later and let you know |
How do I run the tests? |
In my opinion, the failures are not a result of code changes, as I get the same errors when running integration tests on the main branch. I'm not familiar with the Ginko test framework, so I don't know where the faults are coming from. I am willing to help resolve the failing tests with some guidance. |
Sorry for the delay, I am bit busy on week ends :-) Sooo, it is a bit surprising, especially that I am not able to reproduce the fails on my own setup on several distros. It seems either the server in the integration tests crashes at some point. What is also weird is that I cannot reproduce the fails on the main branch when I rerun the Github action on it, but the error seems unrelated to your PR. We probably need a bit more logging on the server-side, and in the test suite, check that the server Concerning the MacOS build, it does not run the integration test suite because MacOS cannot run the server yet. Thanks for the PR ad the help ! Let's continue to investigate. |
Allright, both the integration test suite and your PR seem fine, the problem is probably the github secrets that do not seem accessible in PRs from non-maintainers. These secrets are not real secrets so I'll remove these and generate all the stuff (mock certs and keys) in the CI script. |
Thank you for investing the time looking into this. I have just merged with |
Github seems to love it. |
Nice! Your changes seem to make GitHub happy, which makes me happy (^u^). Thanks again for investigating the problem. Please don't hesitate to ask for changes if needed. |
cli/client/main.go
Outdated
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 | ||
// programm termination. log.Fatal() exits with os.Exit(1). |
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.
// programm termination. log.Fatal() exits with os.Exit(1). | |
// program termination. log.Fatal() exits with os.Exit(1). |
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.
Nice catch!
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.
Thank you for the PR !
Just a few comments but it's great. :-)
If you disagree with the comments we can iterate.
cli/client/main.go
Outdated
port, err = strconv.Atoi(urlPort) | ||
if err != nil { | ||
log.Error().Msgf("invalid port number: %s: %s", urlPort, err) | ||
// *** Port selection *** |
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.
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 comment
The 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 if
part and the error case in the else
part ? I think it makes it more readable because the default flow goes towards what we want to achieve. But maybe it is just me ? If you have good reasons to let it like that, let me know.
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.
Sure, will do. I think this is more a go habit, as most of my if
statements are used to check for the absence of errors 😄
} | ||
} else if configPort != -1 { |
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.
Add the comment // no port specified in the CLI args
?
} else if configPort != -1 { | ||
port = configPort | ||
} else { | ||
port = 443 |
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.
Add a comment, like // no explicit port from the CLI and no port specified in config
?
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.
Great ! If you could just remove the part when the code is reformatted it it would make it easier to review and make the final commit cleaner. :-)
Other than that, I am happy with your changes !
cli/client/main.go
Outdated
if transportErr.ErrorCode.IsCryptoError() { | ||
if tty == nil { | ||
log.Error().Msgf("insecure server cert in non-terminal session, aborting") | ||
return -1 | ||
} | ||
if _, ok = knownHosts[hostname]; ok { | ||
log.Error().Msgf("The server certificate cannot be verified using the one installed in %s. " + |
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.
I am okay to reformat the code in a standard manner but could we do that in another PR ? :-)
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.
Ouch! That was not intended — you're absolutely right about keeping one topic per PR.
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.
Done! I don't want to monopolize your time, so I won't re-re-request a review at this time.
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.
You can request it anytime, don't worry.
This reverts commit 274c10b.
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.
Looks good, thanks!
This PR fixes issue #35 where the client preferred the values from the configuration file
~/.ssh/config
instead of the CLI arguments. The new behaviour reflects the one used by OpenSSH, preferring the port from the CLI and the hostname from the configuration.