cli: return a more helpful error message on MAA patch failure (#3153)

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

* Update internal/maa/patch.go

Co-authored-by: Daniel Weiße <66256922+daniel-weisse@users.noreply.github.com>

---------

Co-authored-by: Daniel Weiße <66256922+daniel-weisse@users.noreply.github.com>
This commit is contained in:
Moritz Sanft 2024-06-07 15:18:34 +02:00 committed by GitHub
parent 7d4e7eff65
commit 095a66fb83
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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,11 @@ 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, _ := io.ReadAll(resp.Body)
return fmt.Errorf("updating attestation policy: unexpected status code: %s: %s", resp.Status, string(body))
}
return nil