aboutsummaryrefslogtreecommitdiffhomepage
path: root/modules/caddytls/tls.go
diff options
context:
space:
mode:
authorFrancis Lavoie <[email protected]>2022-08-31 17:01:30 -0400
committerGitHub <[email protected]>2022-08-31 15:01:30 -0600
commitd4d8bbcfc64d1194079cae35697709f6d267d02f (patch)
tree8617401e3560f1eb5986878747180862822d4d4c /modules/caddytls/tls.go
parent68d8ac9802c5e7bf5bf55d1a3c1db634edc93999 (diff)
downloadcaddy-d4d8bbcfc64d1194079cae35697709f6d267d02f.tar.gz
caddy-d4d8bbcfc64d1194079cae35697709f6d267d02f.zip
events: Implement event system (#4912)
Co-authored-by: Matt Holt <[email protected]>
Diffstat (limited to 'modules/caddytls/tls.go')
-rw-r--r--modules/caddytls/tls.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/modules/caddytls/tls.go b/modules/caddytls/tls.go
index f12948998..fc5f2acee 100644
--- a/modules/caddytls/tls.go
+++ b/modules/caddytls/tls.go
@@ -15,6 +15,7 @@
package caddytls
import (
+ "context"
"crypto/tls"
"encoding/json"
"fmt"
@@ -25,6 +26,7 @@ import (
"time"
"github.com/caddyserver/caddy/v2"
+ "github.com/caddyserver/caddy/v2/modules/caddyevents"
"github.com/caddyserver/certmagic"
"go.uber.org/zap"
)
@@ -73,6 +75,7 @@ type TLS struct {
storageCleanTicker *time.Ticker
storageCleanStop chan struct{}
logger *zap.Logger
+ events *caddyevents.App
}
// CaddyModule returns the Caddy module information.
@@ -85,6 +88,11 @@ func (TLS) CaddyModule() caddy.ModuleInfo {
// Provision sets up the configuration for the TLS app.
func (t *TLS) Provision(ctx caddy.Context) error {
+ eventsAppIface, err := ctx.App("events")
+ if err != nil {
+ return fmt.Errorf("getting events app: %v", err)
+ }
+ t.events = eventsAppIface.(*caddyevents.App)
t.ctx = ctx
t.logger = ctx.Logger(t)
repl := caddy.NewReplacer()
@@ -189,6 +197,7 @@ func (t *TLS) Provision(ctx caddy.Context) error {
magic := certmagic.New(t.certCache, certmagic.Config{
Storage: ctx.Storage(),
Logger: t.logger,
+ OnEvent: t.onEvent,
OCSP: certmagic.OCSPConfig{
DisableStapling: t.DisableOCSPStapling,
},
@@ -514,6 +523,12 @@ func (t *TLS) storageCleanInterval() time.Duration {
return defaultStorageCleanInterval
}
+// onEvent translates CertMagic events into Caddy events then dispatches them.
+func (t *TLS) onEvent(ctx context.Context, eventName string, data map[string]any) error {
+ evt := t.events.Emit(t.ctx, eventName, data)
+ return evt.Aborted
+}
+
// CertificateLoader is a type that can load certificates.
// Certificates can optionally be associated with tags.
type CertificateLoader interface {