Skip to content
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 up --api-proxy handling #1148

Merged
merged 1 commit into from
Apr 12, 2023
Merged

🐛 fix up --api-proxy handling #1148

merged 1 commit into from
Apr 12, 2023

Conversation

joelddiaz
Copy link
Contributor

When doing something like:

cnquery login --api-proxy http://INVALID_PROXY:111 --token XYZ...

The login actually works even through it should have failed b/c of the bad proxy details.

This is due to the way we need to fetch the proxy CLI parameter through the viper package. Since the binding of this parameter is actually "api_proxy" with an underscore, we should reference it exactly that way.

With this change, we now get the expected failure/behavior when given the bad proxy info:

$ ./cnquery login --api-proxy http://192.168.86.3:111 --token "SOME_TOKEN_DATA"
→ token description: test
→ token will expire at Wed, 12 Apr 2023 09:51:44 EDT FTL failed to log in client error="failed to do request: Post "https://api.edge.mondoo.com/AgentManager/RegisterAgent\": proxyconnect tcp: dial tcp 192.168.86.3:111: connect: connection refused"

@@ -42,7 +42,7 @@ func (c *CommonCliConfig) GetAPIProxy() (*url.URL, error) {
return nil, nil
}

func (c *CommonCliConfig) GetHttpClient() (*http.Client, error) {
=func (c *CommonCliConfig) GetHttpClient() (*http.Client, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. A total typo. Fixed. Thanks

Copy link
Member

@chris-rock chris-rock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch @joelddiaz

When doing something like:

cnquery login --api-proxy http://INVALID_PROXY:111 --token XYZ...

The login actually works even through it should have failed b/c of the
bad proxy details.

This is due to the way we need to fetch the proxy CLI parameter through
the viper package. Since the binding of this parameter is actually
"api_proxy" with an underscore, we should reference it exactly that way.

With this change, we now get the expected failure/behavior when given
the bad proxy info:

$ ./cnquery login --api-proxy http://192.168.86.3:111 --token
"SOME_TOKEN_DATA"
→ token description: test
→ token will expire at Wed, 12 Apr 2023 09:51:44 EDT
FTL failed to log in client error="failed to do request: Post
\"https://api.edge.mondoo.com/AgentManager/RegisterAgent\": proxyconnect
tcp: dial tcp 192.168.86.3:111: connect: connection refused"

Signed-off-by: Joel Diaz <[email protected]>
@joelddiaz joelddiaz merged commit be51e33 into main Apr 12, 2023
@joelddiaz joelddiaz deleted the joel/api-proxy-cli-param branch April 12, 2023 15:28
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants