Skip to content

Commit b868118

Browse files
committed
WIP
1 parent a35da4f commit b868118

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

redfish/redfish.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ func (c *redfishClient) newRequest(ctx context.Context, path string) (*http.Requ
167167
}
168168
req.Header.Set("X-auth-token", c.token)
169169
req.Header.Set("Accept", "application/json")
170-
171170
req = req.WithContext(ctx)
172171
return req, nil
173172
}
@@ -220,8 +219,8 @@ func (c *redfishClient) Login(ctx context.Context) error {
220219
return fmt.Errorf("error marshaling JSON: %s", err)
221220
}
222221

223-
url := fmt.Sprintf("%s/%s", c.endpoint, "redfish/v1/SessionService/Sessions")
224-
req, err := http.NewRequestWithContext(ctx, "POST", url, bytes.NewBuffer(jsonBody))
222+
u := c.endpoint.JoinPath("/redfish/v1/SessionService/Sessions")
223+
req, err := http.NewRequestWithContext(ctx, "POST", u.String(), bytes.NewBuffer(jsonBody))
225224
if err != nil {
226225
return fmt.Errorf("error making NewRequest: %s", err)
227226
}
@@ -232,6 +231,9 @@ func (c *redfishClient) Login(ctx context.Context) error {
232231
return fmt.Errorf("error accessing rest service: %s", err)
233232
}
234233
defer resp.Body.Close()
234+
if resp.StatusCode != http.StatusCreated {
235+
return fmt.Errorf("error response from rest service: %d", resp.StatusCode)
236+
}
235237

236238
byteJSON, err := io.ReadAll(resp.Body)
237239
if err != nil {
@@ -249,14 +251,8 @@ func (c *redfishClient) Login(ctx context.Context) error {
249251
}
250252

251253
func (c *redfishClient) CheckSession(ctx context.Context) error {
252-
tr := http.DefaultTransport.(*http.Transport).Clone()
253-
tr.TLSClientConfig = &tls.Config{
254-
InsecureSkipVerify: true, // For self-signed certificates
255-
}
256-
c.httpClient = &http.Client{Transport: tr, Timeout: 5 * time.Second}
257-
258-
url := fmt.Sprintf("%s/%s/%s", c.endpoint, "redfish/v1/SessionService/Sessions", c.sessionId)
259-
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
254+
u := c.endpoint.JoinPath("/redfish/v1/SessionService/Sessions")
255+
req, err := http.NewRequestWithContext(ctx, "GET", u.String(), nil)
260256
if err != nil {
261257
return fmt.Errorf("error making NewRequest: %s", err)
262258
}
@@ -267,6 +263,10 @@ func (c *redfishClient) CheckSession(ctx context.Context) error {
267263
if err != nil {
268264
return fmt.Errorf("error accessing rest service: %s", err)
269265
}
266+
defer resp.Body.Close()
267+
if resp.StatusCode != http.StatusOK {
268+
return fmt.Errorf("error response from rest service: %d", resp.StatusCode)
269+
}
270270

271271
var ses sessionLoginResponse
272272
byteJSON, err := io.ReadAll(resp.Body)

0 commit comments

Comments
 (0)