diff --git a/pkg/notary/log.go b/pkg/notary/log.go new file mode 100644 index 0000000000..70391009dc --- /dev/null +++ b/pkg/notary/log.go @@ -0,0 +1,87 @@ +package notary + +import ( + "errors" + "fmt" + + "github.com/go-logr/logr" + notationlog "github.com/notaryproject/notation-go/log" +) + +func NotaryLoggerAdapter(logger logr.Logger) notationlog.Logger { + return ¬aryLoggerAdapter{ + logger: logger.V(4), + } +} + +type notaryLoggerAdapter struct { + logger logr.Logger +} + +func (nla *notaryLoggerAdapter) Debug(args ...interface{}) { + nla.info(0, args...) +} + +func (nla *notaryLoggerAdapter) Debugf(format string, args ...interface{}) { + nla.infof(0, format, args...) +} + +func (nla *notaryLoggerAdapter) Debugln(args ...interface{}) { + nla.infoln(0, args...) +} + +func (nla *notaryLoggerAdapter) Info(args ...interface{}) { + nla.info(1, args...) +} + +func (nla *notaryLoggerAdapter) Infof(format string, args ...interface{}) { + nla.infof(1, format, args...) +} + +func (nla *notaryLoggerAdapter) Infoln(args ...interface{}) { + nla.infoln(1, args...) +} + +func (nla *notaryLoggerAdapter) Warn(args ...interface{}) { + nla.info(2, args...) +} + +func (nla *notaryLoggerAdapter) Warnf(format string, args ...interface{}) { + nla.infof(2, format, args...) +} + +func (nla *notaryLoggerAdapter) Warnln(args ...interface{}) { + nla.infoln(2, args...) +} + +func (nla *notaryLoggerAdapter) Error(args ...interface{}) { + nla.logger.Error(errors.New(fmt.Sprint(args...)), "") +} + +func (nla *notaryLoggerAdapter) Errorf(format string, args ...interface{}) { + nla.logger.Error(fmt.Errorf(format, args...), "") +} + +func (nla *notaryLoggerAdapter) Errorln(args ...interface{}) { + nla.logger.Error(errors.New(fmt.Sprintln(args...)), "") +} + +func (nla *notaryLoggerAdapter) info(level int, args ...interface{}) { + nla.log(level, fmt.Sprint(args...)) +} + +func (nla *notaryLoggerAdapter) infof(level int, format string, args ...interface{}) { + nla.log(level, fmt.Sprintf(format, args...)) +} + +func (nla *notaryLoggerAdapter) infoln(level int, args ...interface{}) { + nla.log(level, fmt.Sprintln(args...)) +} + +func (nla *notaryLoggerAdapter) log(level int, message string) { + logger := nla.logger + if level > 0 { + logger = logger.V(level) + } + logger.Info(message) +} diff --git a/pkg/notary/notary.go b/pkg/notary/notary.go index 3bea2c2033..e5ddffb973 100644 --- a/pkg/notary/notary.go +++ b/pkg/notary/notary.go @@ -15,6 +15,7 @@ import ( _ "github.com/notaryproject/notation-core-go/signature/cose" _ "github.com/notaryproject/notation-core-go/signature/jws" "github.com/notaryproject/notation-go" + notationlog "github.com/notaryproject/notation-go/log" "github.com/notaryproject/notation-go/verifier" "github.com/notaryproject/notation-go/verifier/trustpolicy" "github.com/opencontainers/go-digest" @@ -68,7 +69,7 @@ func (v *notaryVerifier) VerifySignature(ctx context.Context, opts images.Option MaxSignatureAttempts: 10, } - targetDesc, outcomes, err := notation.Verify(context.TODO(), notationVerifier, parsedRef.Repo, remoteVerifyOptions) + targetDesc, outcomes, err := notation.Verify(notationlog.WithLogger(ctx, NotaryLoggerAdapter(v.log.WithName("Notary Verifier Debug"))), notationVerifier, parsedRef.Repo, remoteVerifyOptions) if err != nil { return nil, errors.Wrapf(err, "failed to verify %s", ref) }