Skip to content
Open
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
25 changes: 24 additions & 1 deletion pkg/util/redfish/redfish.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package redfish
import (
"context"
"encoding/base64"
stderrors "errors"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -173,7 +174,18 @@ func (r *SBaseRedfishClient) ParseRoot(root jsonutils.JSONObject) error {
func (r *SBaseRedfishClient) Probe(ctx context.Context) error {
resp, err := r.Get(ctx, r.IRedfishDriver().BasePath())
if err != nil {
return errors.Wrap(err, "r.get")
origErr := err
if !r.shouldProbeSessionFallback(err) {
return errors.Wrap(err, "r.get")
}
err = r.Login(ctx)
if err != nil {
return errors.Wrap(origErr, "r.get")
}
resp, err = r.Get(ctx, r.IRedfishDriver().BasePath())
if err != nil {
return errors.Wrap(err, "r.get")
}
}
if r.IsDebug {
log.Debugf("%s", resp.PrettyString())
Expand Down Expand Up @@ -208,6 +220,17 @@ func (r *SBaseRedfishClient) Probe(ctx context.Context) error {
return nil
}

func (r *SBaseRedfishClient) shouldProbeSessionFallback(err error) bool {
if len(r.SessionToken) > 0 {
return false
}
var jerr *httputils.JSONClientError
if !stderrors.As(err, &jerr) {
return false
}
return jerr.Code == http.StatusUnauthorized || jerr.Code == http.StatusForbidden
}

func (r *SBaseRedfishClient) Login(ctx context.Context) error {
sessionurl := httputils.JoinPath(r.IRedfishDriver().BasePath(), "Sessions")
params := jsonutils.NewDict()
Expand Down
Loading
Loading