Skip to content

Commit

Permalink
Wire up ggcr logs warning and debug logs (#67)
Browse files Browse the repository at this point in the history
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 <jon.johnson@chainguard.dev>
  • Loading branch information
jonjohnsonjr authored Aug 31, 2023
1 parent bad66fa commit 9c36aa6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 3 additions & 3 deletions internal/secant/attest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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())
}
Expand Down

0 comments on commit 9c36aa6

Please sign in to comment.