Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
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
8 changes: 8 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package gofish
import (
"bytes"
"context"
"crypto/tls"
"encoding/base64"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -141,6 +142,13 @@ func setupClientWithConfig(ctx context.Context, config *ClientConfig) (c *APICli
// amend its configuration to match what was provided to us
if transport, ok := client.HTTPClient.Transport.(*http.Transport); ok {
if config.Insecure {
// If we're using the default transport, need to make sure there
// is a TLSClientConfig set in order to set the SkipVerify flag.
if transport.TLSClientConfig == nil {
transport.TLSClientConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
}
}
transport.TLSClientConfig.InsecureSkipVerify = config.Insecure
}

Expand Down
5 changes: 5 additions & 0 deletions common/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ func (e *Entity) DisableEtagMatch(b bool) {
e.disableEtagMatch = b
}

// IsEtagMatchDisabled indicates if etag matching is enabled on this entity
func (e *Entity) IsEtagMatchDisabled() bool {
return e.disableEtagMatch
}

// Update commits changes to an entity.
func (e *Entity) Update(originalEntity, updatedEntity reflect.Value, allowedUpdates []string) error {
payload := getPatchPayloadFromUpdate(originalEntity, updatedEntity)
Expand Down
18 changes: 17 additions & 1 deletion redfish/accountservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package redfish

import (
"encoding/json"
"fmt"
"reflect"

"github.com/stmcginnis/gofish/common"
Expand Down Expand Up @@ -510,7 +511,22 @@ func (accountservice *AccountService) CreateAccount(userName, password, roleID s
Password: password,
RoleID: roleID,
}
resp, err := accountservice.PostWithResponse(accountservice.accounts, t)

baseEntity := &accountservice.Entity

// The proper ETag for creating an account is found at `/AccountService/Accounts`
// If ETag matching is disabled, we don't care and don't need to waste a request,
// but otherwise, we need to load /Accounts to get the ETag then issue the request against that Entity
if !accountservice.IsEtagMatchDisabled() {
accountsEntity, err := common.GetObject[common.Entity](accountservice.GetClient(), accountservice.accounts)
if err != nil {
return nil, fmt.Errorf("failed to get accounts entity: %w", err)
}

baseEntity = accountsEntity
}

resp, err := baseEntity.PostWithResponse(accountservice.accounts, t)
if err != nil {
return nil, err
}
Expand Down
3 changes: 3 additions & 0 deletions redfish/chassis.go
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,9 @@ func (chassis *Chassis) Switches() ([]*Switch, error) {

// NetworkAdapters gets the collection of network adapters of this chassis
func (chassis *Chassis) NetworkAdapters() ([]*NetworkAdapter, error) {
if chassis.networkAdapters == "" {
return nil, nil
}
return ListReferencedNetworkAdapter(chassis.GetClient(), chassis.networkAdapters)
}

Expand Down