Skip to content

Commit

Permalink
Bugfix/remove http header cookie (#194)
Browse files Browse the repository at this point in the history
set PATCH bios attr with etag which ONLY get from bios/setting

Signed-off-by: Guohao Wang <[email protected]>
  • Loading branch information
Sn0rt authored Aug 15, 2022
1 parent 2bd0e46 commit 83d861c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
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")
}
}

0 comments on commit 83d861c

Please sign in to comment.