debug(gsap-attestor): include raw input and both parse errors in diagnostics

Temporary diagnostic commit — surfaces the exact data SPIRE sends to
the Configure RPC so we can determine why JSON decode fails.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Tyler J King 2026-05-13 08:32:16 -04:00
parent 646944ab2a
commit f4f02b0e2e

View file

@ -2,6 +2,7 @@ package main
import ( import (
"context" "context"
"fmt"
"sync" "sync"
"github.com/hashicorp/hcl/v2/hclsimple" "github.com/hashicorp/hcl/v2/hclsimple"
@ -41,12 +42,15 @@ func (p *Plugin) Attest(ctx context.Context, req *workloadattestorv1.AttestReque
func decodeConfig(data string) (GsapAttestorConfig, error) { func decodeConfig(data string) (GsapAttestorConfig, error) {
var cfg GsapAttestorConfig var cfg GsapAttestorConfig
if err := hclsimple.Decode("plugin.json", []byte(data), nil, &cfg); err != nil { jsonErr := hclsimple.Decode("plugin.json", []byte(data), nil, &cfg)
if err2 := hclsimple.Decode("plugin.hcl", []byte(data), nil, &cfg); err2 != nil { if jsonErr == nil {
return cfg, err2
}
}
return cfg, nil return cfg, nil
}
hclErr := hclsimple.Decode("plugin.hcl", []byte(data), nil, &cfg)
if hclErr == nil {
return cfg, nil
}
return cfg, fmt.Errorf("json: %v; hcl: %v; raw input: %q", jsonErr, hclErr, data)
} }
func (p *Plugin) Configure(_ context.Context, req *configv1.ConfigureRequest) (*configv1.ConfigureResponse, error) { func (p *Plugin) Configure(_ context.Context, req *configv1.ConfigureRequest) (*configv1.ConfigureResponse, error) {