From 7afeaee9f7254b3da4ede89034a9e3d531071bdb Mon Sep 17 00:00:00 2001 From: Andreas Pfurtscheller <1051396+aplr@users.noreply.github.com> Date: Thu, 24 Oct 2024 16:48:43 +0100 Subject: [PATCH] Add PollInterval to ZeroSSLIssuer (#316) --- zerosslissuer.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/zerosslissuer.go b/zerosslissuer.go index 4a33bfa2..ec4a9b96 100644 --- a/zerosslissuer.go +++ b/zerosslissuer.go @@ -62,6 +62,9 @@ type ZeroSSLIssuer struct { // validation, set this field. CNAMEValidation *DNSManager + // Delay between poll attempts. + PollInterval time.Duration + // An optional (but highly recommended) logger. Logger *zap.Logger } @@ -203,8 +206,8 @@ func (iss *ZeroSSLIssuer) Issue(ctx context.Context, csr *x509.CertificateReques }, nil } -func (*ZeroSSLIssuer) waitForCertToBeIssued(ctx context.Context, client zerossl.Client, cert zerossl.CertificateObject) (zerossl.CertificateObject, error) { - ticker := time.NewTicker(5 * time.Second) +func (iss *ZeroSSLIssuer) waitForCertToBeIssued(ctx context.Context, client zerossl.Client, cert zerossl.CertificateObject) (zerossl.CertificateObject, error) { + ticker := time.NewTicker(iss.pollInterval()) defer ticker.Stop() for { @@ -227,6 +230,13 @@ func (*ZeroSSLIssuer) waitForCertToBeIssued(ctx context.Context, client zerossl. } } +func (iss *ZeroSSLIssuer) pollInterval() time.Duration { + if iss.PollInterval == 0 { + return defaultPollInterval + } + return iss.PollInterval +} + func (iss *ZeroSSLIssuer) getClient() zerossl.Client { return zerossl.Client{AccessKey: iss.APIKey} } @@ -302,6 +312,7 @@ const ( zerosslAPIBase = "https://" + zerossl.BaseURL + "/acme" zerosslValidationPathPrefix = "/.well-known/pki-validation/" zerosslIssuerKey = "zerossl" + defaultPollInterval = 5 * time.Second ) // Interface guards