caddytls: Regularly reload static certificates
Fixes #6933
@mholt I pushed some changes. I changed CertificateLoader like this:
type CertificateLoader interface {
Initialize(updateCertificates func(add []Certificate, remove []string) error) error
}
That way, existing loaders (e.g. StorageLoader) will simply call the updateCertificates callback during the Initialize method, but other loaders (i.e. FolderLoader) will call it during Initialize, but also afterwards, during fsnotify events.
Would it make sense like that?
I was thinking more of using each loader modules' Provision() and Cleanup() methods to start/stop a goroutine that does the watching and reloading.
As for removing... let me think more on that.
When moving the code into the Provision method, how would it access the certCache?
Via the tls app, so, ctx.App("tls") (then type-assert).
We might need to add a method or two to the caddytls.TLS app type which can expose the cache or at least the operations we need on it: https://pkg.go.dev/github.com/caddyserver/caddy/v2/modules/caddytls#TLS