Skip to content

Commit b83c1d5

Browse files
bossm8ldez
andauthored
feat: add hook-timeout to run and renew commands (#2389)
Co-authored-by: Fernandez Ludovic <[email protected]>
1 parent 5f53d3e commit b83c1d5

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

cmd/cmd_renew.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const (
2525
flgARIWaitToRenewDuration = "ari-wait-to-renew-duration"
2626
flgReuseKey = "reuse-key"
2727
flgRenewHook = "renew-hook"
28+
flgRenewHookTimeout = "renew-hook-timeout"
2829
flgNoRandomSleep = "no-random-sleep"
2930
flgForceCertDomains = "force-cert-domains"
3031
)
@@ -109,6 +110,11 @@ func createRenew() *cli.Command {
109110
Name: flgRenewHook,
110111
Usage: "Define a hook. The hook is executed only when the certificates are effectively renewed.",
111112
},
113+
&cli.DurationFlag{
114+
Name: flgRenewHookTimeout,
115+
Usage: "Define the timeout for the hook execution.",
116+
Value: 2 * time.Minute,
117+
},
112118
&cli.BoolFlag{
113119
Name: flgNoRandomSleep,
114120
Usage: "Do not add a random sleep before the renewal." +
@@ -254,7 +260,7 @@ func renewForDomains(ctx *cli.Context, account *Account, keyType certcrypto.KeyT
254260

255261
addPathToMetadata(meta, domain, certRes, certsStorage)
256262

257-
return launchHook(ctx.String(flgRenewHook), meta)
263+
return launchHook(ctx.String(flgRenewHook), ctx.Duration(flgRenewHookTimeout), meta)
258264
}
259265

260266
func renewForCSR(ctx *cli.Context, account *Account, keyType certcrypto.KeyType, certsStorage *CertificatesStorage, bundle bool, meta map[string]string) error {
@@ -337,7 +343,7 @@ func renewForCSR(ctx *cli.Context, account *Account, keyType certcrypto.KeyType,
337343

338344
addPathToMetadata(meta, domain, certRes, certsStorage)
339345

340-
return launchHook(ctx.String(flgRenewHook), meta)
346+
return launchHook(ctx.String(flgRenewHook), ctx.Duration(flgRenewHookTimeout), meta)
341347
}
342348

343349
func needRenewal(x509Cert *x509.Certificate, domain string, days int) bool {

cmd/cmd_run.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const (
2323
flgPreferredChain = "preferred-chain"
2424
flgAlwaysDeactivateAuthorizations = "always-deactivate-authorizations"
2525
flgRunHook = "run-hook"
26+
flgRunHookTimeout = "run-hook-timeout"
2627
)
2728

2829
func createRun() *cli.Command {
@@ -75,6 +76,11 @@ func createRun() *cli.Command {
7576
Name: flgRunHook,
7677
Usage: "Define a hook. The hook is executed when the certificates are effectively created.",
7778
},
79+
&cli.DurationFlag{
80+
Name: flgRunHookTimeout,
81+
Usage: "Define the timeout for the hook execution.",
82+
Value: 2 * time.Minute,
83+
},
7884
},
7985
}
8086
}
@@ -129,7 +135,7 @@ func run(ctx *cli.Context) error {
129135

130136
addPathToMetadata(meta, cert.Domain, cert, certsStorage)
131137

132-
return launchHook(ctx.String(flgRunHook), meta)
138+
return launchHook(ctx.String(flgRunHook), ctx.Duration(flgRunHookTimeout), meta)
133139
}
134140

135141
func handleTOS(ctx *cli.Context, client *lego.Client) bool {

cmd/hook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import (
1010
"time"
1111
)
1212

13-
func launchHook(hook string, meta map[string]string) error {
13+
func launchHook(hook string, timeout time.Duration, meta map[string]string) error {
1414
if hook == "" {
1515
return nil
1616
}
1717

18-
ctxCmd, cancel := context.WithTimeout(context.Background(), 120*time.Second)
18+
ctxCmd, cancel := context.WithTimeout(context.Background(), timeout)
1919
defer cancel()
2020

2121
parts := strings.Fields(hook)

docs/data/zz_cli_help.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ OPTIONS:
7474
--preferred-chain value If the CA offers multiple certificate chains, prefer the chain with an issuer matching this Subject Common Name. If no match, the default offered chain will be used.
7575
--always-deactivate-authorizations value Force the authorizations to be relinquished even if the certificate request was successful.
7676
--run-hook value Define a hook. The hook is executed when the certificates are effectively created.
77+
--run-hook-timeout value Define the timeout for the hook execution. (default: 2m0s)
7778
--help, -h show help
7879
"""
7980

@@ -98,6 +99,7 @@ OPTIONS:
9899
--preferred-chain value If the CA offers multiple certificate chains, prefer the chain with an issuer matching this Subject Common Name. If no match, the default offered chain will be used.
99100
--always-deactivate-authorizations value Force the authorizations to be relinquished even if the certificate request was successful.
100101
--renew-hook value Define a hook. The hook is executed only when the certificates are effectively renewed.
102+
--renew-hook-timeout value Define the timeout for the hook execution. (default: 2m0s)
101103
--no-random-sleep Do not add a random sleep before the renewal. We do not recommend using this flag if you are doing your renewals in an automated way. (default: false)
102104
--force-cert-domains Check and ensure that the cert's domain list matches those passed in the domains argument. (default: false)
103105
--help, -h show help

0 commit comments

Comments
 (0)