From 0e2c7e1d35b287fc0e56d6db2951f791e09b5a37 Mon Sep 17 00:00:00 2001 From: Matt Holt Date: Tue, 11 Jul 2023 13:10:58 -0600 Subject: caddytls: Reuse certificate cache through reloads (#5623) * caddytls: Don't purge cert cache on config reload * Update CertMagic This actually avoids reloading managed certs from storage when already in the cache, d'oh. * Fix bug; re-implement HasCertificateForSubject * Update go.mod: CertMagic tag --- context.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'context.go') diff --git a/context.go b/context.go index 615192c..004dee6 100644 --- a/context.go +++ b/context.go @@ -410,6 +410,11 @@ func (ctx Context) loadModuleInline(moduleNameKey, moduleScope string, raw json. // called during the Provision/Validate phase to reference a // module's own host app (since the parent app module is still // in the process of being provisioned, it is not yet ready). +// +// We return any type instead of the App type because it is NOT +// intended for the caller of this method to be the one to start +// or stop App modules. The caller is expected to assert to the +// concrete type. func (ctx Context) App(name string) (any, error) { if app, ok := ctx.cfg.apps[name]; ok { return app, nil @@ -428,18 +433,15 @@ func (ctx Context) App(name string) (any, error) { // AppIfConfigured returns an app by its name if it has been // configured. Can be called instead of App() to avoid -// instantiating an empty app when that's not desirable. -func (ctx Context) AppIfConfigured(name string) (any, error) { - app, ok := ctx.cfg.apps[name] - if !ok || app == nil { - return nil, nil - } - - appModule, err := ctx.App(name) - if err != nil { - return nil, err - } - return appModule, nil +// instantiating an empty app when that's not desirable. If +// the app has not been loaded, nil is returned. +// +// We return any type instead of the App type because it is not +// intended for the caller of this method to be the one to start +// or stop App modules. The caller is expected to assert to the +// concrete type. +func (ctx Context) AppIfConfigured(name string) any { + return ctx.cfg.apps[name] } // Storage returns the configured Caddy storage implementation. -- cgit v1.2.3