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

Bugfix/remove http header cookie #194

Merged
merged 3 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,6 @@ func (c *APIClient) runRawRequestWithHeaders(method, url string, payloadBuffer i
if c.auth != nil {
if c.auth.Token != "" {
req.Header.Set("X-Auth-Token", c.auth.Token)
req.Header.Set("Cookie", fmt.Sprintf("sessionKey=%s", c.auth.Token))
} else if c.auth.BasicAuth && c.auth.Username != "" && c.auth.Password != "" {
encodedAuth := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%v:%v", c.auth.Username, c.auth.Password)))
req.Header.Set("Authorization", fmt.Sprintf("Basic %v", encodedAuth))
Expand Down
20 changes: 9 additions & 11 deletions redfish/bios.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ type Bios struct {
activeSoftwareImage string
// rawData holds the original serialized JSON so we can compare updates.
rawData []byte
// etag contains the etag header when fetching the object. This is used to
// control updates to make sure the object has not been modified my a different
// process between fetching and updating that could cause conflicts.
etag string
}

// UnmarshalJSON unmarshals an Bios object from the raw JSON.
Expand Down Expand Up @@ -158,10 +154,6 @@ func GetBios(c common.Client, uri string) (*Bios, error) {
return nil, err
}

if resp.Header["Etag"] != nil {
bios.etag = resp.Header["Etag"][0]
}

bios.SetClient(c)
return &bios, nil
}
Expand Down Expand Up @@ -271,6 +263,12 @@ func (bios *Bios) UpdateBiosAttributesApplyAt(attrs BiosAttributes, applyTime co
}
}

resp, err := bios.Client.Get(bios.settingsTarget)
if err != nil {
return err
}
defer resp.Body.Close()

// If there are any allowed updates, try to send updates to the system and
// return the result.
if len(payload) > 0 {
Expand All @@ -280,11 +278,11 @@ func (bios *Bios) UpdateBiosAttributesApplyAt(attrs BiosAttributes, applyTime co
}

var header = make(map[string]string)
if bios.etag != "" {
header["If-Match"] = bios.etag
if resp.Header["Etag"] != nil {
header["If-Match"] = resp.Header["Etag"][0]
}

resp, err := bios.Client.PatchWithHeaders(bios.settingsTarget, data, header)
resp, err = bios.Client.PatchWithHeaders(bios.settingsTarget, data, header)
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions redfish/bios_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,15 @@ func TestUpdateBiosAttributes(t *testing.T) {

calls := testClient.CapturedCalls()

if len(calls) != 1 {
if len(calls) != 2 {
t.Errorf("Expected one call to be made, captured: %v", calls)
}

if !strings.Contains(calls[0].Payload, "AssetTag") {
if !strings.Contains(calls[1].Payload, "AssetTag") {
t.Errorf("Unexpected update payload: %s", calls[0].Payload)
}

if strings.Contains(calls[0].Payload, "@Redfish.SettingsApplyTime") {
if strings.Contains(calls[1].Payload, "@Redfish.SettingsApplyTime") {
t.Error("Expected 'SettingsApplyTime' to not be present")
}
}
Expand All @@ -240,15 +240,15 @@ func TestUpdateBiosAttributesApplyAt(t *testing.T) {

calls := testClient.CapturedCalls()

if len(calls) != 1 {
if len(calls) != 2 {
t.Errorf("Expected one call to be made, captured: %v", calls)
}

if !strings.Contains(calls[0].Payload, "AssetTag") {
if !strings.Contains(calls[1].Payload, "AssetTag") {
t.Errorf("Unexpected update payload: %s", calls[0].Payload)
}

if !strings.Contains(calls[0].Payload, "@Redfish.SettingsApplyTime") {
if !strings.Contains(calls[1].Payload, "@Redfish.SettingsApplyTime") {
t.Error("Expected 'SettingsApplyTime' to be present")
}
}