Skip to content

Commit

Permalink
refactor: Improve certificate obtaining process with timeout and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
yarlson committed Oct 8, 2024
1 parent d50291e commit 6bb5bc8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 1 deletion.
Binary file modified .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 4 additions & 1 deletion zerossl/zerossl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 6bb5bc8

Please sign in to comment.