Add acme client logger middleware
This commit is contained in:
parent
47465d645b
commit
5a434865ad
@ -20,6 +20,7 @@ import (
|
||||
clientset "github.com/jetstack/cert-manager/pkg/client/clientset/versioned"
|
||||
"github.com/jetstack/cert-manager/pkg/issuer"
|
||||
"github.com/jetstack/cert-manager/pkg/issuer/acme/client"
|
||||
"github.com/jetstack/cert-manager/pkg/issuer/acme/client/middleware"
|
||||
"github.com/jetstack/cert-manager/pkg/issuer/acme/dns"
|
||||
"github.com/jetstack/cert-manager/pkg/issuer/acme/http"
|
||||
"github.com/jetstack/cert-manager/pkg/util"
|
||||
@ -141,7 +142,7 @@ func (a *Acme) acmeClientWithKey(accountPrivKey *rsa.PrivateKey) client.Interfac
|
||||
Key: accountPrivKey,
|
||||
DirectoryURL: a.issuer.GetSpec().ACME.Server,
|
||||
}
|
||||
return cl
|
||||
return middleware.NewLogger(cl)
|
||||
}
|
||||
|
||||
func (a *Acme) acmeClientImpl() (client.Interface, error) {
|
||||
|
||||
74
pkg/issuer/acme/client/middleware/logger.go
Normal file
74
pkg/issuer/acme/client/middleware/logger.go
Normal file
@ -0,0 +1,74 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/golang/glog"
|
||||
|
||||
"github.com/jetstack/cert-manager/pkg/issuer/acme/client"
|
||||
"github.com/jetstack/cert-manager/third_party/crypto/acme"
|
||||
)
|
||||
|
||||
func NewLogger(baseCl client.Interface) client.Interface {
|
||||
return &Logger{baseCl: baseCl}
|
||||
}
|
||||
|
||||
// Logger is a glog based logging middleware for an ACME client
|
||||
type Logger struct {
|
||||
baseCl client.Interface
|
||||
}
|
||||
|
||||
func (l *Logger) CreateOrder(ctx context.Context, order *acme.Order) (*acme.Order, error) {
|
||||
glog.Infof("Calling CreateOrder")
|
||||
return l.CreateOrder(ctx, order)
|
||||
}
|
||||
|
||||
func (l *Logger) GetOrder(ctx context.Context, url string) (*acme.Order, error) {
|
||||
glog.Infof("Calling GetOrder")
|
||||
return l.GetOrder(ctx, url)
|
||||
}
|
||||
|
||||
func (l *Logger) FinalizeOrder(ctx context.Context, finalizeURL string, csr []byte) (der [][]byte, err error) {
|
||||
glog.Infof("Calling FinalizeOrder")
|
||||
return l.FinalizeOrder(ctx, finalizeURL, csr)
|
||||
}
|
||||
|
||||
func (l *Logger) AcceptChallenge(ctx context.Context, chal *acme.Challenge) (*acme.Challenge, error) {
|
||||
glog.Infof("Calling AcceptChallenge")
|
||||
return l.AcceptChallenge(ctx, chal)
|
||||
}
|
||||
|
||||
func (l *Logger) GetChallenge(ctx context.Context, url string) (*acme.Challenge, error) {
|
||||
glog.Infof("Calling GetChallenge")
|
||||
return l.GetChallenge(ctx, url)
|
||||
}
|
||||
|
||||
func (l *Logger) GetAuthorization(ctx context.Context, url string) (*acme.Authorization, error) {
|
||||
glog.Infof("Calling GetAuthorization")
|
||||
return l.GetAuthorization(ctx, url)
|
||||
}
|
||||
|
||||
func (l *Logger) WaitAuthorization(ctx context.Context, url string) (*acme.Authorization, error) {
|
||||
glog.Infof("Calling WaitAuthorization")
|
||||
return l.WaitAuthorization(ctx, url)
|
||||
}
|
||||
|
||||
func (l *Logger) CreateAccount(ctx context.Context, a *acme.Account) (*acme.Account, error) {
|
||||
glog.Infof("Calling CreateAccount")
|
||||
return l.CreateAccount(ctx, a)
|
||||
}
|
||||
|
||||
func (l *Logger) GetAccount(ctx context.Context) (*acme.Account, error) {
|
||||
glog.Infof("Calling GetAccount")
|
||||
return l.GetAccount(ctx)
|
||||
}
|
||||
|
||||
func (l *Logger) HTTP01ChallengeResponse(token string) (string, error) {
|
||||
glog.Infof("Calling HTTP01ChallengeResponse")
|
||||
return l.HTTP01ChallengeResponse(token)
|
||||
}
|
||||
|
||||
func (l *Logger) DNS01ChallengeRecord(token string) (string, error) {
|
||||
glog.Infof("Calling DNS01ChallengeRecord")
|
||||
return l.DNS01ChallengeRecord(token)
|
||||
}
|
||||
@ -202,6 +202,8 @@ func (a *Acme) presentChallenge(ctx context.Context, cl client.Interface, crt *v
|
||||
}
|
||||
|
||||
func (a *Acme) cleanupLastOrder(ctx context.Context, crt *v1alpha1.Certificate) error {
|
||||
glog.Infof("Cleaning up previous order for certificate %s/%s", crt.Namespace, crt.Name)
|
||||
|
||||
err := a.cleanupIrrelevantChallenges(ctx, crt, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -216,6 +218,7 @@ func (a *Acme) cleanupLastOrder(ctx context.Context, crt *v1alpha1.Certificate)
|
||||
// TODO: ensure all DNS challenge solvers return non-error if the challenge
|
||||
// record doesn't exist
|
||||
func (a *Acme) cleanupIrrelevantChallenges(ctx context.Context, crt *v1alpha1.Certificate, keepChals []v1alpha1.ACMEOrderChallenge) error {
|
||||
glog.Infof("Cleaning up old/expired challenges for Certificate %s/%s", crt.Namespace, crt.Name)
|
||||
var toCleanUp []v1alpha1.ACMEOrderChallenge
|
||||
for _, c := range crt.Status.ACMEStatus().Order.Challenges {
|
||||
keep := false
|
||||
@ -239,6 +242,7 @@ func (a *Acme) cleanupIrrelevantChallenges(ctx context.Context, crt *v1alpha1.Ce
|
||||
}
|
||||
|
||||
func (a *Acme) cleanupChallenge(ctx context.Context, crt *v1alpha1.Certificate, c v1alpha1.ACMEOrderChallenge) error {
|
||||
glog.Infof("Cleaning up challenge for domain %q as part of Certificate %s/%s", c.Domain, crt.Namespace, crt.Name)
|
||||
solver, err := a.solverFor(c.Type)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Loading…
Reference in New Issue
Block a user