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

Tooling updates + add Proxy support to httpclient.DefaultTransport #414

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

mmlb
Copy link
Collaborator

@mmlb mmlb commented Mar 11, 2025

What does this PR implement/change/remove?

  • Some spring cleaning of non-source files
  • Addition of Proxy config to the httpclient.DefaultTransport
  • Add example binaries to .gitignore

Spring cleaning changes are annoyingly large but mostly mechanical, either via gofumpt or golangci-lint run --fix, there were some manual fixes I made to avoid disabling linters that complained about a handful of things.

I also added Proxy config to the DefaultTransport just like the DefaultTransport in the http package does. This setup will make it so http requests will go via a proxy when HTTPS_PROXY env var exists. This way we can debug redfish over https using mitmproxy or similar setup.

I added the binaries to .gitignore because they should have been there from the beginning.

Description for changelog/release notes

https connections now go through a proxy if the HTTPS_PROXY environment variable is set

@mmlb mmlb requested a review from joelrebel March 11, 2025 18:09
@mmlb mmlb force-pushed the push-muqtvtlsqyrn branch 3 times, most recently from 6e6567e to 8d1a4b3 Compare March 11, 2025 18:51
go.mod Outdated
@@ -1,6 +1,6 @@
module github.com/bmc-toolbox/bmclib/v2

go 1.21
go 1.23
Copy link
Member

Choose a reason for hiding this comment

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

I recommend that we don't bump this version to 1.23. This version doesn't correspond to Go's supported versions but "The minimum version of Go required to compile packages in this module." - ref.

The current bmclib policy is, "As a library we will only bump the version of Go in the go.mod file when there are required dependencies in bmclib that necessitate a version bump." - ref

From this PR, the only thing I can tell that needs the version to increment is for x := range 5. I believe this was introduced in Go 1.22. So the conversation should be around whether to go from 1.21 to 1.22 and not 1.21 to 1.23. I am onboard with going to 1.22 but not 1.23.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right, but no one should be running go <1.23 anyway. I kind of see it as a chicken/egg situation. When 1.25 comes out I'd like to bump this to 1.24 and then make use of go tool support to run various tools (like golangci-lint) via native go pinning.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, that's not the policy. As a library, we shouldn't dictate the version clients use. Per the policy, go tool support isn't a reason to update this. There are many examples of older Go versions in large active Go module repos in the wild. https://github.com/spf13/cobra, for example.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh til! well will back this out then

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

there's also the copyloopvar change that came in from 1.22 that affects this repo (albeit just one line). I'll back this out and have a separate PR for 1.22 + enabling those linters.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Alright dropped back down to 1.21 and undid changes

@@ -602,7 +600,7 @@ func (a *ASRockRack) queryHTTPS(ctx context.Context, endpoint, method string, pa
}

// add headers
req.Header.Add("X-CSRFTOKEN", a.loginSession.CSRFToken)
req.Header.Add("X-Csrftoken", a.loginSession.CSRFToken)
Copy link
Member

Choose a reason for hiding this comment

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

What's motivating this change? I believe there was a code comment elsewhere that referenced old firmware needing some specific casing. Regardless, the HTTP spec says that headers are case-insensitive. ref

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this was an autofix from one of the linters, can do the magic comment to have it ignore this but I'd like some clarity before going that route.

I'm not seeing anything in the code base about old firmware expecting specific case of headers, are you thinking about supermicro with form-data fields https://github.com/bmc-toolbox/bmclib/blob/main/providers/supermicro/floppy.go#L91-L96?

Copy link
Member

Choose a reason for hiding this comment

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

I'd recommend the headers are left as is, unless a change is required in practice

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will do

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

should be back to original format

@@ -76,13 +74,13 @@ func (c *Client) ConvertTaskState(state string) constants.TaskState {
switch strings.ToLower(state) {
case "starting", "downloading", "downloaded", "scheduling":
return constants.Initializing
case "running", "stopping", "cancelling":
case "running", "stopping", "canceling":
Copy link
Member

Choose a reason for hiding this comment

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

I don't think these should change as they are States that correspond to the gofish library. https://github.com/stmcginnis/gofish/blob/4b51c15f0a3df649821f9fc395a82483ff60bb2a/redfish/task.go#L16-L55

It is spelled Cancelling in that library. We should probably be using the const from that package anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

uggh good catch will back out. We are using the consts from that package already. The problem is we are converting that package's types <-> string when it should be done by that package itself (via stringer imo).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

should be back to original (plus //nolint: directive)

client.go Outdated
client := *old
transport, ok := client.Transport.(*http.Transport)
if !ok {
panic("old client's transport is not expected type")
Copy link
Member

Choose a reason for hiding this comment

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

hmm...I'm concerned about this panic. I know we weren't even checking the type assert before, and it could have implicitly caused a panic already, but could we introduce a more graceful way to handle the bad type assert? Maybe a return error or something similar?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think its worth it, changing to an error return is going to have wide effect when done for registerASRRProvider and probably others (bubbling the error up). Its never really going to be a problem either since we aren't really using different implementations. If it ever changes then it'll be caught early at startup instead of later at runtime.

Not a whole lot of benefit imo.

Copy link
Member

Choose a reason for hiding this comment

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

This does seem like an exceptional case, can the panic message include a clearer message, along the lines of "expected a http client of the http.Transport type, got $blah instead"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've updated the panic message

Copy link
Member

@joelrebel joelrebel left a comment

Choose a reason for hiding this comment

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

Thanks for updates and fixes @mmlb , for the reviewers sake, going ahead could we keep the PRs scope limited

client.go Outdated
client := *old
transport, ok := client.Transport.(*http.Transport)
if !ok {
panic("old client's transport is not expected type")
Copy link
Member

Choose a reason for hiding this comment

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

This does seem like an exceptional case, can the panic message include a clearer message, along the lines of "expected a http client of the http.Transport type, got $blah instead"?

mmlb added 3 commits March 12, 2025 11:24
Automated using the following command:
```
git ls-files '*.go' |
xargs -I% sh -c '
  sed "/^import (/,/^)/ {
    /^\s*$/ d
  }" % >%.tmp &&
  goimports -w %.tmp &&
  (if cmp -s % %.tmp; then rm %.tmp; else mv %.tmp %; fi)'
```
@mmlb
Copy link
Collaborator Author

mmlb commented Mar 12, 2025

Thanks for updates and fixes @mmlb , for the reviewers sake, going ahead could we keep the PRs scope limited

I'm going to drop new features from this PR and just do the format/lint fixes, aka the cleaning part

mmlb added 3 commits March 12, 2025 12:02
Going to go from disable-all,enable-some to enable-all,disable-some so
we are going to want to avoid golangci-lint changing out from under us.
@mmlb mmlb force-pushed the push-muqtvtlsqyrn branch from 8d1a4b3 to 886d623 Compare March 12, 2025 19:00
Drop enabling govets shadow because it's too annoying
@mmlb mmlb force-pushed the push-muqtvtlsqyrn branch from 39f3295 to 95d4d4c Compare March 12, 2025 19:31
@mmlb mmlb force-pushed the push-muqtvtlsqyrn branch from 95d4d4c to 0d3b939 Compare March 12, 2025 19:38
@mmlb
Copy link
Collaborator Author

mmlb commented Mar 12, 2025

Thanks for updates and fixes @mmlb , for the reviewers sake, going ahead could we keep the PRs scope limited

I've trimmed things down and also split the commits a little bit so that they are easier to review. I split out what was previously "automatic fixes + manual fixes" into multiple ones. The first iteration was all together so that each commit would still pass linting so it was quite large. Now a couple of intermediate commits won't pass but makes for smaller diffs.

Copy link
Member

@joelrebel joelrebel left a comment

Choose a reason for hiding this comment

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

This looks fine to me

Copy link
Member

@jacobweinstock jacobweinstock left a comment

Choose a reason for hiding this comment

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

Thanks for updates and fixes @mmlb , for the reviewers sake, going ahead could we keep the PRs scope limited

I don't think multiple commits was what @joelrebel was driving at here. Limiting scope would be, for example, creating a PR just for the linting changes, one for the small pedantic differences you prefer, and another for just the proxy support.

@@ -93,7 +94,7 @@ func Test_setComponentUpdateMisc(t *testing.T) {
return
}

assert.Nil(t, err)
assert.NoError(t, err)
Copy link
Member

Choose a reason for hiding this comment

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

The use of require.NoError and assert.NoError seems arbitrary. When to use which is not clear. Is this something that golangci-lint catches? If not, I recommend either creating a doc for when one should be used over the other, or just stick to one.

Comment on lines +98 to +99
case constants.PowerCycleHost, constants.Unknown:
fallthrough
Copy link
Member

Choose a reason for hiding this comment

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

For what is this optimizing? Why is this needed if it's just going to fallthrough to the default? Won't the default case be called regardless of whether this case exists or not?

Copy link
Member

@jacobweinstock jacobweinstock Mar 13, 2025

Choose a reason for hiding this comment

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

Oh, is this to satisfy a linting complaint? If so, I recommend a code comment to improve understandability and the required cognitive load.

Copy link
Member

Choose a reason for hiding this comment

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

constants.PowerCycleHost and constants.Unknown should not be part of the switch case since they are not Redfish task states,
could we have this case removed?

http://redfish.dmtf.org/schemas/DSP2046_2019.4.html#redfish.dmtf.org/schemas/v1/Task.json|details|TaskState

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants