Skip to content

Commit

Permalink
common/entity: add parameter to skip the If-Match Etag header (#277)
Browse files Browse the repository at this point in the history
This is a work around for bad vendor implementations where
the If-Match header does not work - even with the '*' value and requests
are incorrectly denied with an ETag mismatch error.
  • Loading branch information
joelrebel authored Sep 20, 2023
1 parent db55696 commit 77490fd
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions common/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ type Entity struct {
// Removes surrounding quotes of etag used in If-Match header of PATCH and POST requests.
// Only use this option to resolve bad vendor implementation where If-Match only matches the unquoted etag string.
stripEtagQuotes bool
// DisableEtagMatch when set will skip the If-Match header from PATCH and POST requests.
//
// This is a work around for bad vendor implementations where the If-Match header does not work - even with the '*' value
// and requests are incorrectly denied with an ETag mismatch error.
disableEtagMatch bool
}

// SetClient sets the API client connection to use for accessing this
Expand All @@ -47,6 +52,11 @@ func (e *Entity) StripEtagQuotes(b bool) {
e.stripEtagQuotes = b
}

// Disable Etag Match header from being sent by the client.
func (e *Entity) DisableEtagMatch(b bool) {
e.disableEtagMatch = b
}

// Update commits changes to an entity.
func (e *Entity) Update(originalEntity, updatedEntity reflect.Value, allowedUpdates []string) error {
payload := getPatchPayloadFromUpdate(originalEntity, updatedEntity)
Expand Down Expand Up @@ -98,7 +108,7 @@ func (e *Entity) Get(c Client, uri string, payload interface{}) error {
// Patch performs a Patch request against the Redfish service with etag
func (e *Entity) Patch(uri string, payload interface{}) error {
header := make(map[string]string)
if e.etag != "" {
if e.etag != "" && !e.disableEtagMatch {
if e.stripEtagQuotes {
e.etag = strings.Trim(e.etag, "\"")
}
Expand All @@ -116,7 +126,7 @@ func (e *Entity) Patch(uri string, payload interface{}) error {
// Post performs a Post request against the Redfish service with etag
func (e *Entity) Post(uri string, payload interface{}) error {
header := make(map[string]string)
if e.etag != "" {
if e.etag != "" && !e.disableEtagMatch {
if e.stripEtagQuotes {
e.etag = strings.Trim(e.etag, "\"")
}
Expand Down

0 comments on commit 77490fd

Please sign in to comment.