cli: return a more helpful error message on maa patch failure

This commit is contained in:
Moritz Sanft 2024-06-07 12:20:48 +02:00
parent 2c03a16a68
commit 887587ba62
No known key found for this signature in database
GPG Key ID: 335D28368B1DA615

View File

@ -9,6 +9,7 @@ import (
"context"
"encoding/base64"
"fmt"
"io"
"net/http"
"github.com/Azure/azure-sdk-for-go/profiles/latest/attestation/attestation"
@ -55,10 +56,14 @@ func (p AzurePolicyPatcher) Patch(ctx context.Context, attestationURL string) er
if err != nil {
return fmt.Errorf("sending request: %w", err)
}
resp.Body.Close()
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("updating attestation policy: unexpected status code: %s", resp.Status)
body, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("updating attestation policy: unexpected status code: %s\nread response body: %w", resp.Status, err)
}
return fmt.Errorf("updating attestation policy: unexpected status code: %s\nresponse body: %s", resp.Status, string(body))
}
return nil