Skip to content

Commit

Permalink
azure: Close http response body (#450)
Browse files Browse the repository at this point in the history
Closing the http response body seems to be forgotten in the Azure
KeyVault KMS backend. This commit fixes it.
  • Loading branch information
vadmeste committed Mar 1, 2024
1 parent a960e3c commit 8ecd396
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions internal/keystore/azure/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func (c *client) CreateSecret(ctx context.Context, name, value string) (status,
if err != nil {
return status{}, err
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusOK {
return status{
StatusCode: http.StatusOK,
Expand Down Expand Up @@ -133,6 +134,7 @@ func (c *client) GetSecret(ctx context.Context, name, version string) (string, s
if err != nil {
return "", status{}, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
response, err := parseErrorResponse(resp)
if err != nil {
Expand Down Expand Up @@ -207,6 +209,7 @@ func (c *client) DeleteSecret(ctx context.Context, name string) (status, error)
if err != nil {
return status{}, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
if resp.StatusCode != http.StatusOK {
response, err := parseErrorResponse(resp)
Expand Down Expand Up @@ -245,6 +248,7 @@ func (c *client) PurgeSecret(ctx context.Context, name string) (status, error) {
if err != nil {
return status{}, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusNoContent {
response, err := parseErrorResponse(resp)
if err != nil {
Expand Down Expand Up @@ -296,6 +300,7 @@ func (c *client) GetFirstVersion(ctx context.Context, name string) (string, stat
if err != nil {
return "", status{}, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
response, err := parseErrorResponse(resp)
if err != nil {
Expand Down Expand Up @@ -379,6 +384,7 @@ func (c *client) ListSecrets(ctx context.Context, nextLink string) ([]string, st
if err != nil {
return nil, "", status{}, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
response, err := parseErrorResponse(resp)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion internal/keystore/azure/key-vault.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ func (s *Store) Status(ctx context.Context) (kes.KeyStoreState, error) {
}

start := time.Now()
if _, err = http.DefaultClient.Do(req); err != nil {
resp, err := http.DefaultClient.Do(req)
if err != nil {
return kes.KeyStoreState{}, &keystore.ErrUnreachable{Err: err}
}
resp.Body.Close()
return kes.KeyStoreState{
Latency: time.Since(start),
}, nil
Expand Down

0 comments on commit 8ecd396

Please sign in to comment.