diff mbox series

[bug#67497,3/4] In certbot service, reduce code duplication.

Message ID ed0f8c6ad1ddb4ae435d5c5cf1c8d9f72a5e41ad.1701120054.git.felix.lechner@lease-up.com
State New
Headers show
Series [bug#67497,1/4] In documentation, rename %certbot-deploy-hook back to %nginx-deploy-hook.. | expand

Commit Message

Felix Lechner Nov. 27, 2023, 9:20 p.m. UTC
The certbot command is can only be changed with a great deal of attention. The
program branches early and constructs two separate invocations. Changes would
generally have to be made in two places. Otherwise, a new bug might be
introduced.

This commit places the conditional inquestion inside the list so that future
edits are more fool-proof.

Change-Id: I4a54f8b78ff4722688de7772d3c26a6191d6ff89
---
 gnu/services/certbot.scm | 58 +++++++++++++++++++---------------------
 1 file changed, 27 insertions(+), 31 deletions(-)
diff mbox series

Patch

diff --git a/gnu/services/certbot.scm b/gnu/services/certbot.scm
index 0c45471659..8490a69a99 100644
--- a/gnu/services/certbot.scm
+++ b/gnu/services/certbot.scm
@@ -100,37 +100,33 @@  (define certbot-command
                                                 csr authentication-hook
                                                 cleanup-hook deploy-hook)
                  (let ((name (or custom-name (car domains))))
-                   (if challenge
-                     (append
-                      (list name certbot "certonly" "-n" "--agree-tos"
-                            "--manual"
-                            (string-append "--preferred-challenges=" challenge)
-                            "--cert-name" name
-                            "--manual-public-ip-logging-ok"
-                            "-d" (string-join domains ","))
-                      (if csr `("--csr" ,csr) '())
-                      (if email
-                          `("--email" ,email)
-                          '("--register-unsafely-without-email"))
-                      (if server `("--server" ,server) '())
-                      (if rsa-key-size `("--rsa-key-size" ,rsa-key-size) '())
-                      (if authentication-hook
-                          `("--manual-auth-hook" ,authentication-hook)
-                          '())
-                      (if cleanup-hook `("--manual-cleanup-hook" ,cleanup-hook) '())
-                      (if deploy-hook `("--deploy-hook" ,deploy-hook) '()))
-                     (append
-                      (list name certbot "certonly" "-n" "--agree-tos"
-                            "--webroot" "-w" webroot
-                            "--cert-name" name
-                            "-d" (string-join domains ","))
-                      (if csr `("--csr" ,csr) '())
-                      (if email
-                          `("--email" ,email)
-                          '("--register-unsafely-without-email"))
-                      (if server `("--server" ,server) '())
-                      (if rsa-key-size `("--rsa-key-size" ,rsa-key-size) '())
-                      (if deploy-hook `("--deploy-hook" ,deploy-hook) '()))))))
+                   (append
+                    (list name
+                          certbot
+                          "certonly"
+                          "-n"
+                          "--agree-tos")
+                    (if challenge
+                        (append
+                         (list "--manual"
+                               (string-append "--preferred-challenges=" challenge)
+                               "--manual-public-ip-logging-ok")
+                         (if authentication-hook
+                             (list "--manual-auth-hook" authentication-hook)
+                             '())
+                         (if cleanup-hook
+                             (list "--manual-cleanup-hook" cleanup-hook)
+                             '()))
+                        (list "--webroot" "-w" webroot))
+                    (list "--cert-name" name
+                          "-d" (string-join domains ","))
+                    (if csr (list "--csr" csr) '())
+                    (if email
+                        (list "--email" email)
+                        (list "--register-unsafely-without-email"))
+                    (if server (list "--server" server) '())
+                    (if rsa-key-size (list "--rsa-key-size" rsa-key-size) '())
+                    (if deploy-hook (list "--deploy-hook" deploy-hook) '())))))
               certificates)))
        (program-file
         "certbot-command"