authority: use an empty meter if none supplied

pull/1688/head
Panagiotis Siatras 5 months ago
parent 1cbcafe7bd
commit 9e4ba6e1d1
No known key found for this signature in database

@ -145,6 +145,10 @@ func New(cfg *config.Config, opts ...Option) (*Authority, error) {
}
}
if a.meter == nil {
a.meter = noopMeter{}
}
return a, nil
}
@ -185,6 +189,10 @@ func NewEmbedded(opts ...Option) (*Authority, error) {
}
}
if a.meter == nil {
a.meter = noopMeter{}
}
return a, nil
}

@ -14,3 +14,14 @@ type Meter interface {
// SSHRenewedf is called whenever a SSH certificate is renewed.
SSHRenewed(provisioner string)
}
// noopMeter implements a noop [Meter].
type noopMeter struct{}
func (noopMeter) X509Signed(string) {}
func (noopMeter) X509Renewed(string) {}
func (noopMeter) SSHSigned(string) {}
func (noopMeter) SSHRenewed(string) {}

@ -300,9 +300,7 @@ func (a *Authority) SignSSH(_ context.Context, key ssh.PublicKey, opts provision
return nil, errs.Wrap(http.StatusInternalServerError, err, "authority.SignSSH: error storing certificate in db")
}
if h := a.meter; h != nil {
h.SSHSigned(prov.GetName())
}
a.meter.SSHSigned(prov.GetName())
return cert, nil
}

@ -289,9 +289,7 @@ func (a *Authority) Sign(csr *x509.CertificateRequest, signOpts provisioner.Sign
}
}
if h := a.meter; h != nil {
h.X509Signed(prov.GetName())
}
a.meter.X509Signed(prov.GetName())
return fullchain, nil
}
@ -451,9 +449,7 @@ func (a *Authority) RenewContext(ctx context.Context, oldCert *x509.Certificate,
}
}
if h := a.meter; h != nil {
h.X509Renewed(prov.GetName())
}
a.meter.X509Renewed(prov.GetName())
return fullchain, nil
}

Loading…
Cancel
Save