From 9c36aa6c7c8208c058aaa3d099407d55bd9a8f65 Mon Sep 17 00:00:00 2001 From: Jon Johnson Date: Thu, 31 Aug 2023 16:13:48 -0700 Subject: [PATCH] Wire up ggcr logs warning and debug logs (#67) We always want logs.Warn wired up so we can see if transient failures are actually being retried, but logs.Debug and logs.Progress are only wired up if terraform passes us the debug flag. Signed-off-by: Jon Johnson --- internal/secant/attest.go | 6 +++--- main.go | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/internal/secant/attest.go b/internal/secant/attest.go index 53fdbf91..c8f3a631 100644 --- a/internal/secant/attest.go +++ b/internal/secant/attest.go @@ -7,12 +7,12 @@ import ( "encoding/json" "fmt" "io" - "log" "net/url" "github.com/chainguard-dev/terraform-provider-cosign/internal/secant/models/intoto" "github.com/chainguard-dev/terraform-provider-cosign/internal/secant/tlog" "github.com/chainguard-dev/terraform-provider-cosign/internal/secant/types" + "github.com/google/go-containerregistry/pkg/logs" "github.com/google/go-containerregistry/pkg/name" v1 "github.com/google/go-containerregistry/pkg/v1" "github.com/google/go-containerregistry/pkg/v1/remote" @@ -113,8 +113,8 @@ func Attest(ctx context.Context, statement *types.Statement, sv types.CosignerSi return fmt.Errorf("creating intoto entry: %w", err) } - log.Printf("debug envelope:\n%s", string(envelope)) - log.Printf("debug rawCert:\n%s", string(rawCert)) + logs.Debug.Printf("debug envelope:\n%s", envelope) + logs.Debug.Printf("debug rawCert:\n%s", rawCert) entry, err := tlog.Upload(ctx, rekorClient, e) if err != nil { diff --git a/main.go b/main.go index 2f51ca36..81d95a1e 100644 --- a/main.go +++ b/main.go @@ -4,8 +4,10 @@ import ( "context" "flag" "log" + "os" "github.com/chainguard-dev/terraform-provider-cosign/internal/provider" + "github.com/google/go-containerregistry/pkg/logs" "github.com/hashicorp/terraform-plugin-framework/providerserver" ) @@ -24,6 +26,13 @@ func main() { Debug: debug, } + // Wire up ggcr logs. + logs.Warn.SetOutput(os.Stderr) + if debug { + logs.Progress.SetOutput(os.Stderr) + logs.Debug.SetOutput(os.Stderr) + } + if err := providerserver.Serve(context.Background(), provider.New(version), opts); err != nil { log.Fatal(err.Error()) }