Skip to content

Commit

Permalink
Use basic authentication for RedFish API calls. =>
Browse files Browse the repository at this point in the history
https://github.com/HewlettPackard/ilo-rest-api-docs/blob/master/source/includes/_ilo5_authentication.md
RedFish handles authentication differently. Easiest is to use Basic Auth for now. Sessions can be added later.
  • Loading branch information
oothman committed Feb 17, 2021
1 parent 8cdfc7e commit 52e76aa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
40 changes: 22 additions & 18 deletions providers/hp/ilo/ilo.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (i *Ilo) CheckCredentials() (err error) {
}

// get calls a given json endpoint of the iLO and returns the data
func (i *Ilo) get(endpoint string) (payload []byte, err error) {
func (i *Ilo) get(endpoint string, useSession bool) (payload []byte, err error) {
i.log.V(1).Info("retrieving data from bmc", "step", "bmc connection", "vendor", hp.VendorID, "ip", i.ip, "endpoint", endpoint)

bmcURL := fmt.Sprintf("https://%s", i.ip)
Expand All @@ -120,10 +120,14 @@ func (i *Ilo) get(endpoint string) (payload []byte, err error) {
return payload, err
}

for _, cookie := range i.httpClient.Jar.Cookies(u) {
if cookie.Name == "sessionKey" {
req.AddCookie(cookie)
if useSession {
for _, cookie := range i.httpClient.Jar.Cookies(u) {
if cookie.Name == "sessionKey" {
req.AddCookie(cookie)
}
}
} else {
req.SetBasicAuth(i.username, i.password)
}

reqDump, _ := httputil.DumpRequestOut(req, true)
Expand Down Expand Up @@ -200,7 +204,7 @@ func (i *Ilo) ChassisSerial() (string, error) {
return "", err
}

payload, err := i.get("json/rck_info")
payload, err := i.get("json/rck_info", true)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -257,7 +261,7 @@ func (i *Ilo) Name() (name string, err error) {
}

url := "json/overview"
payload, err := i.get(url)
payload, err := i.get(url, true)
if err != nil {
return name, err
}
Expand All @@ -279,7 +283,7 @@ func (i *Ilo) Status() (health string, err error) {
}

url := "json/overview"
payload, err := i.get(url)
payload, err := i.get(url, true)
if err != nil {
return health, err
}
Expand All @@ -305,7 +309,7 @@ func (i *Ilo) Memory() (mem int, err error) {
}

url := "json/mem_info"
payload, err := i.get(url)
payload, err := i.get(url, true)
if err != nil {
return mem, err
}
Expand Down Expand Up @@ -335,7 +339,7 @@ func (i *Ilo) CPU() (cpu string, cpuCount int, coreCount int, hyperthreadCount i
}

url := "json/proc_info"
payload, err := i.get(url)
payload, err := i.get(url, true)
if err != nil {
return cpu, cpuCount, coreCount, hyperthreadCount, err
}
Expand All @@ -361,7 +365,7 @@ func (i *Ilo) BiosVersion() (version string, err error) {
}

url := "json/overview"
payload, err := i.get(url)
payload, err := i.get(url, true)
if err != nil {
return version, err
}
Expand All @@ -387,7 +391,7 @@ func (i *Ilo) PowerKw() (power float64, err error) {
}

url := "json/power_summary"
payload, err := i.get(url)
payload, err := i.get(url, true)
if err != nil {
return power, err
}
Expand All @@ -409,7 +413,7 @@ func (i *Ilo) PowerState() (state string, err error) {
}

url := "json/power_summary"
payload, err := i.get(url)
payload, err := i.get(url, true)
if err != nil {
return state, err
}
Expand All @@ -431,7 +435,7 @@ func (i *Ilo) TempC() (temp int, err error) {
}

url := "json/health_temperature"
payload, err := i.get(url)
payload, err := i.get(url, true)
if err != nil {
return temp, err
}
Expand Down Expand Up @@ -484,7 +488,7 @@ func (i *Ilo) License() (name string, licType string, err error) {
}

url := "json/license"
payload, err := i.get(url)
payload, err := i.get(url, true)
if err != nil {
return name, licType, err
}
Expand All @@ -506,7 +510,7 @@ func (i *Ilo) parseChassisInfo() (*hp.ChassisInfo, error) {

chassisInfo := &hp.ChassisInfo{}
// We try the new way of doing things first (RedFish).
payload, err := i.get(hp.ChassisInfoNewURL)
payload, err := i.get(hp.ChassisInfoNewURL, false)
if err == nil {
err = json.Unmarshal(payload, chassisInfo)
if err != nil {
Expand Down Expand Up @@ -534,7 +538,7 @@ func (i *Ilo) parseChassisInfo() (*hp.ChassisInfo, error) {
}

// This just means that we have to try the old way of doing things, since RedFish is not available.
payload, err = i.get(hp.ChassisInfoOldURL)
payload, err = i.get(hp.ChassisInfoOldURL, true)
if err != nil {
return nil, err
}
Expand All @@ -555,7 +559,7 @@ func (i *Ilo) Psus() (psus []*devices.Psu, err error) {
}

url := "json/power_supplies"
payload, err := i.get(url)
payload, err := i.get(url, true)
if err != nil {
return psus, err
}
Expand Down Expand Up @@ -598,7 +602,7 @@ func (i *Ilo) Disks() (disks []*devices.Disk, err error) {
}

url := "json/health_phy_drives"
payload, err := i.get(url)
payload, err := i.get(url, true)
if err != nil {
return disks, err
}
Expand Down
14 changes: 7 additions & 7 deletions providers/hp/ilo/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (i *Ilo) Screenshot() (response []byte, extension string, err error) {
return response, extension, errors.ErrFeatureUnavailable
}

response, err = i.get(endpoint)
response, err = i.get(endpoint, true)
if err != nil {
return []byte{}, extension, err
}
Expand All @@ -60,7 +60,7 @@ func (i *Ilo) queryDirectoryGroups() (directoryGroups []DirectoryGroups, err err

endpoint := "json/directory_groups"

payload, err := i.get(endpoint)
payload, err := i.get(endpoint, true)
if err != nil {
msg := "GET request failed."
i.log.V(1).Info(msg,
Expand Down Expand Up @@ -94,7 +94,7 @@ func (i *Ilo) queryUsers() (usersInfo []UserInfo, err error) {

endpoint := "json/user_info"

payload, err := i.get(endpoint)
payload, err := i.get(endpoint, true)
if err != nil {
msg := "GET request failed."
i.log.V(1).Info(msg,
Expand Down Expand Up @@ -129,7 +129,7 @@ func (i *Ilo) queryNetworkSntp() (networkSntp NetworkSntp, err error) {

endpoint := "json/network_sntp/interface/0"

payload, err := i.get(endpoint)
payload, err := i.get(endpoint, true)
if err != nil {
msg := "GET request failed."
i.log.V(1).Info(msg,
Expand Down Expand Up @@ -163,7 +163,7 @@ func (i *Ilo) queryAccessSettings() (AccessSettings, error) {

var accessSettings AccessSettings

payload, err := i.get(endpoint)
payload, err := i.get(endpoint, true)
if err != nil {
msg := "GET request failed."
i.log.V(1).Info(msg,
Expand Down Expand Up @@ -197,7 +197,7 @@ func (i *Ilo) queryNetworkIPv4() (NetworkIPv4, error) {

var networkIPv4 NetworkIPv4

payload, err := i.get(endpoint)
payload, err := i.get(endpoint, true)
if err != nil {
msg := "GET request failed."
i.log.V(1).Info(msg,
Expand Down Expand Up @@ -231,7 +231,7 @@ func (i *Ilo) queryPowerRegulator() (PowerRegulator, error) {

var powerRegulator PowerRegulator

payload, err := i.get(endpoint)
payload, err := i.get(endpoint, true)
if err != nil {
msg := "GET request failed."
i.log.V(1).Info(msg,
Expand Down

0 comments on commit 52e76aa

Please sign in to comment.