@marcel91200 / caddy Mirror · read-only / commits / 6e0e3e15
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

httpcaddyfile: Add global option for `storage_clean_interval` (#4134)

Followup to https://github.com/caddyserver/caddy/commit/42b7134ffa3bf3e9e86514c82407979c2627a5ab

Francis Lavoie committed May 2, 2021 at 13:57 UTC 6e0e3e1537c399faabd30cc08a9fe68a7be87639
3 files changed +26 -1
caddyconfig/httpcaddyfile/options.go
+15
@@ -32,6 +32,7 @@ func init() {
32 RegisterGlobalOption("default_sni", parseOptSingleString)
33 RegisterGlobalOption("order", parseOptOrder)
34 RegisterGlobalOption("storage", parseOptStorage)
35 + RegisterGlobalOption("storage_clean_interval", parseOptStorageCleanInterval)
36 RegisterGlobalOption("acme_ca", parseOptSingleString)
37 RegisterGlobalOption("acme_ca_root", parseOptSingleString)
38 RegisterGlobalOption("acme_dns", parseOptACMEDNS)
@@ -177,6 +178,20 @@ func parseOptStorage(d *caddyfile.Dispenser, _ interface{}) (interface{}, error)
178 return storage, nil
179 }
180
181 +func parseOptStorageCleanInterval(d *caddyfile.Dispenser, _ interface{}) (interface{}, error) {
182 + if !d.Next() { // consume option name
183 + return nil, d.ArgErr()
184 + }
185 + if !d.Next() { // get duration value
186 + return nil, d.ArgErr()
187 + }
188 + dur, err := caddy.ParseDuration(d.Val())
189 + if err != nil {
190 + return nil, err
191 + }
192 + return caddy.Duration(dur), nil
193 +}
194 +
195 func parseOptACMEDNS(d *caddyfile.Dispenser, _ interface{}) (interface{}, error) {
196 if !d.Next() { // consume option name
197 return nil, d.ArgErr()
caddyconfig/httpcaddyfile/tlsapp.go
+8
@@ -278,6 +278,14 @@ func (st ServerType) buildTLSApp(
278 tlsApp.Automation.OnDemand = onDemand
279 }
280
281 + // set the storage clean interval if configured
282 + if storageCleanInterval, ok := options["storage_clean_interval"].(caddy.Duration); ok {
283 + if tlsApp.Automation == nil {
284 + tlsApp.Automation = new(caddytls.AutomationConfig)
285 + }
286 + tlsApp.Automation.StorageCleanInterval = storageCleanInterval
287 + }
288 +
289 // if any hostnames appear on the same server block as a key with
290 // no host, they will not be used with route matchers because the
291 // hostless key matches all hosts, therefore, it wouldn't be
caddytest/integration/caddyfile_adapt/global_options_acme.txt
+3 -1
@@ -20,6 +20,7 @@
20 interval 30s
21 burst 20
22 }
23 + storage_clean_interval 7d
24
25 key_type ed25519
26 }
@@ -80,7 +81,8 @@
81 "burst": 20
82 },
83 "ask": "https://example.com"
83 - }
84 + },
85 + "storage_clean_interval": 604800000000000
86 }
87 }
88 }