Skip to content

Commit 0f595d9

Browse files
committed
handle nil response when auth
Signed-off-by: Kobbi Gal <kobbi.g@akeyless.io>
1 parent 0eae114 commit 0f595d9

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

secretstores/akeyless/akeyless.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,20 @@ func (a *akeylessSecretStore) authenticate(ctx context.Context, metadata *akeyle
124124

125125
a.logger.Debug("authenticating with Akeyless...")
126126
out, httpResponse, err := a.v2.Auth(ctx).Body(*authRequest).Execute()
127-
if err != nil || httpResponse.StatusCode != 200 {
128-
return fmt.Errorf("failed to authenticate with Akeyless (HTTP status code: %d): %w", httpResponse.StatusCode, errors.New(httpResponse.Status))
127+
if err != nil {
128+
if httpResponse != nil {
129+
return fmt.Errorf("failed to authenticate with Akeyless (HTTP status code: %d): %w", httpResponse.StatusCode, err)
130+
}
131+
return fmt.Errorf("failed to authenticate with Akeyless: %w", err)
132+
}
133+
if httpResponse == nil || httpResponse.StatusCode != 200 {
134+
statusCode := 0
135+
status := "unknown"
136+
if httpResponse != nil {
137+
statusCode = httpResponse.StatusCode
138+
status = httpResponse.Status
139+
}
140+
return fmt.Errorf("failed to authenticate with Akeyless (HTTP status code: %d): %s", statusCode, status)
129141
}
130142

131143
a.logger.Debugf("authentication successful - token expires at %s", out.GetExpiration())

0 commit comments

Comments
 (0)