Skip to content

Commit 84b6eab

Browse files
committed
decode API Server response body on error
Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
1 parent 93c6a2e commit 84b6eab

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

pkg/datagatherer/oidc/oidc.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,12 @@ func (g *DataGathererOIDC) Fetch() (any, int, error) {
8989

9090
func (g *DataGathererOIDC) fetchOIDCConfig(ctx context.Context) (map[string]any, error) {
9191
// Fetch the OIDC discovery document from the well-known endpoint.
92-
bytes, err := g.cl.Get().AbsPath("/.well-known/openid-configuration").Do(ctx).Raw()
93-
if err != nil {
92+
result := g.cl.Get().AbsPath("/.well-known/openid-configuration").Do(ctx)
93+
if err := result.Error(); err != nil {
9494
return nil, fmt.Errorf("failed to get OIDC discovery document: %s", k8sErrorMessage(err))
9595
}
9696

97+
bytes, _ := result.Raw()
9798
var oidcResponse map[string]any
9899
if err := json.Unmarshal(bytes, &oidcResponse); err != nil {
99100
return nil, fmt.Errorf("failed to unmarshal OIDC discovery document: %v", err)
@@ -109,11 +110,12 @@ func (g *DataGathererOIDC) fetchJWKS(ctx context.Context) (map[string]any, error
109110
// - on fully private AWS EKS clusters, the URL is still public and might not
110111
// be reachable from within the cluster (https://github.com/aws/containers-roadmap/issues/2038)
111112
// So we are using the default path instead, which we think should work in most cases.
112-
bytes, err := g.cl.Get().AbsPath("/openid/v1/jwks").Do(ctx).Raw()
113-
if err != nil {
113+
result := g.cl.Get().AbsPath("/openid/v1/jwks").Do(ctx)
114+
if err := result.Error(); err != nil {
114115
return nil, fmt.Errorf("failed to get JWKS from jwks_uri: %s", k8sErrorMessage(err))
115116
}
116117

118+
bytes, _ := result.Raw()
117119
var jwksResponse map[string]any
118120
if err := json.Unmarshal(bytes, &jwksResponse); err != nil {
119121
return nil, fmt.Errorf("failed to unmarshal JWKS response: %v", err)

0 commit comments

Comments
 (0)