context: AppIfConfigured returns error; consider not-yet-provisioned modules (#6292)

* context: Add new `AppStrict()` method to avoid instantiating empty apps

* Rename AppStrict -> AppIfConfigured

---------

Co-authored-by: Matthew Holt <mholt@users.noreply.github.com>
This commit is contained in:
Francis Lavoie 2024-05-20 13:14:58 -04:00 committed by GitHub
parent 73e094e1dd
commit a6a45ff6c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 25 additions and 25 deletions

View file

@ -50,8 +50,11 @@ func (a *adminAPI) Provision(ctx caddy.Context) error {
a.ctx = ctx
a.log = ctx.Logger(a) // TODO: passing in 'a' is a hack until the admin API is officially extensible (see #5032)
// Avoid initializing PKI if it wasn't configured
if pkiApp := a.ctx.AppIfConfigured("pki"); pkiApp != nil {
// Avoid initializing PKI if it wasn't configured.
// We intentionally ignore the error since it's not
// fatal if the PKI app is not explicitly configured.
pkiApp, err := ctx.AppIfConfigured("pki")
if err == nil {
a.pkiApp = pkiApp.(*PKI)
}