|
lintel 0.2.0
|
#include <TlsReloadRegistry.h>
Classes | |
| struct | ReloadResult |
Public Types | |
| using | ReloadId = std::size_t |
| using | Handler = std::function< std::string()> |
Public Member Functions | |
| ReloadId | registerHandler (std::string name, Handler handler) |
| void | unregisterHandler (ReloadId id) |
| void | clear () |
| std::vector< ReloadResult > | reload () const |
Static Public Member Functions | |
| static TlsReloadRegistry & | instance () |
Process-wide registry of reloadable resources, currently the TLS certificate/key pair of the HTTP server.
A certificate is loaded into the server's OpenSSL context once, when the httplib::SSLServer is built. Replacing it on disk (for example when certbot renews a Let's Encrypt certificate) therefore has no effect until the process restarts. A controller cannot reach the server to change that: the controller list is resolved from the container before the ServerProvider that creates the server, so a controller holding the server would be a dependency cycle. The server instead registers a reload handler here, and POST /admin/reload-tls runs it.
The registry is a process-wide singleton (the same pattern LoggerService and ReadinessRegistry use). Registering a name that is already present replaces the old handler, so a re-initialization stays idempotent - and it returns a fresh id, because the replaced owner must not be able to unregister its successor: a ServerProvider that builds one server after another would otherwise strip the reload handler of the server it just created when the previous instance is destroyed.
Thread safety: registerHandler(), unregisterHandler(), clear() and reload() may be called from any thread. The handlers run outside the registry lock, so a reload that re-reads files does not block registration.
| using lintel::TlsReloadRegistry::Handler = std::function<std::string()> |
A reload handler.
| using lintel::TlsReloadRegistry::ReloadId = std::size_t |
Identifies one registration, for removal by its owner.
| void lintel::TlsReloadRegistry::clear | ( | ) |
Remove every registered handler (used by tests).
|
static |
Register a named handler; an existing handler of the same name is replaced.
| name | unique name, reported by POST /admin/reload-tls |
| handler | the reload handler |
| std::vector< ReloadResult > lintel::TlsReloadRegistry::reload | ( | ) | const |
Run all registered handlers in registration order.
A handler that throws counts as failed with the exception message as detail.
Remove the registration with id; no-op when it is gone.
Takes the id rather than the name on purpose: when a name was registered again by someone else, the earlier owner must not remove the new handler.