Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Migrate last stdlib log to clog #270

Merged
merged 1 commit into from
May 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions pkg/signature/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"errors"
"fmt"
"io"
"log"
"os"
"path/filepath"
"strings"
Expand All @@ -31,20 +30,22 @@ import (

"github.com/psanford/memfs"

"github.com/chainguard-dev/clog"
"github.com/chainguard-dev/go-apk/pkg/tarball"
)

func SignIndex(ctx context.Context, signingKey string, indexFile string) error {
log := clog.FromContext(ctx)
is, err := indexIsAlreadySigned(indexFile)
if err != nil {
return err
}
if is {
log.Printf("index %s is already signed, doing nothing", indexFile)
log.Infof("index %s is already signed, doing nothing", indexFile)
return nil
}

log.Printf("signing index %s with key %s", indexFile, signingKey)
log.Infof("signing index %s with key %s", indexFile, signingKey)

indexData, indexDigest, err := ReadAndHashIndexFile(indexFile)
if err != nil {
Expand All @@ -56,7 +57,7 @@ func SignIndex(ctx context.Context, signingKey string, indexFile string) error {
return fmt.Errorf("unable to sign index: %w", err)
}

log.Printf("appending signature to index %s", indexFile)
log.Infof("appending signature to index %s", indexFile)

sigFS := memfs.New()
if err := sigFS.WriteFile(fmt.Sprintf(".SIGN.RSA.%s.pub", filepath.Base(signingKey)), sigData, 0644); err != nil {
Expand All @@ -74,7 +75,7 @@ func SignIndex(ctx context.Context, signingKey string, indexFile string) error {
return fmt.Errorf("unable to build tarball context: %w", err)
}

log.Printf("writing signed index to %s", indexFile)
log.Infof("writing signed index to %s", indexFile)

var sigBuffer bytes.Buffer
if err := multitarctx.WriteTargz(ctx, &sigBuffer, sigFS, sigFS); err != nil {
Expand All @@ -95,7 +96,7 @@ func SignIndex(ctx context.Context, signingKey string, indexFile string) error {
return fmt.Errorf("unable to write index data: %w", err)
}

log.Printf("signed index %s with key %s", indexFile, signingKey)
log.Infof("signed index %s with key %s", indexFile, signingKey)

return nil
}
Expand Down