From 6bb5bc8a84023235408827de5e19c88d242d0f0b Mon Sep 17 00:00:00 2001 From: Yar Kravtsov Date: Tue, 8 Oct 2024 09:21:02 +0300 Subject: [PATCH] refactor: Improve certificate obtaining process with timeout and logging --- .DS_Store | Bin 6148 -> 6148 bytes main.go | 1 + zerossl/zerossl.go | 5 ++++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.DS_Store b/.DS_Store index d3e8f31d3adc9b9a71905b3d56ffe10f20b6fa5a..7ad359daa63f411c5758e2d23bf3a64c24b38cf9 100644 GIT binary patch delta 165 zcmZoMXfc=|&e%RNQH+&?fq{WzVxovF6OaJ{AexbZL4biFlOYX=lNk~jN+u?%JAx#5 zfZSAuB8C!VNuWq^T1s(pQht68P$vUBLlsz2K0`4O=D?*kCR(#kHV|Ri%+0~W!Pver a@jLTmei21MkiiN-oB+gNu-Q@MFf#!CWgtTU delta 109 zcmZoMXfc=|&Zs)EP}qc#fq{XUp@1QqAw4anI5{alKL;cP224;IBml$$3{d%v7tPow jJ}BDE&LP0TsJijucjn3bB8q|_WeG@H8a6wM9A*Xpo+K4t diff --git a/main.go b/main.go index a2970ad..86aaac5 100644 --- a/main.go +++ b/main.go @@ -96,6 +96,7 @@ func run(cfg *Config) error { }() if certService.ShouldObtainCertificate(action, cert) { + log.Printf("Obtaining certificate for %s", cfg.Domain) if err := certService.ObtainOrRenewCertificate(ctx, cfg.Domain, cfg.Email, certFile, keyFile); err != nil { if errors.Is(err, context.Canceled) { return errors.New("operation canceled") diff --git a/zerossl/zerossl.go b/zerossl/zerossl.go index fbee1fb..bc2a8a1 100644 --- a/zerossl/zerossl.go +++ b/zerossl/zerossl.go @@ -163,7 +163,10 @@ func (s *Service) ObtainCertificate(ctx context.Context, domain, email string) ( return nil, nil, nil, fmt.Errorf("accept challenge: %w", err) } - order, err = client.WaitOrder(ctx, order.URI) + ctxWithTimeout, cancel := context.WithTimeout(ctx, 1*time.Minute) + defer cancel() + + order, err = client.WaitOrder(ctxWithTimeout, order.URI) if err != nil { return nil, nil, nil, fmt.Errorf("wait for order: %w", err) }