lintel 0.2.0
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
lintel::TlsReloadRegistry Class Reference

#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 ()
 

Detailed Description

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.

Member Typedef Documentation

◆ Handler

using lintel::TlsReloadRegistry::Handler = std::function<std::string()>

A reload handler.

Returns
an error description when the reload failed, an empty string on success

◆ ReloadId

Identifies one registration, for removal by its owner.

Member Function Documentation

◆ clear()

void lintel::TlsReloadRegistry::clear ( )

Remove every registered handler (used by tests).

◆ instance()

static TlsReloadRegistry & lintel::TlsReloadRegistry::instance ( )
static
Returns
the process-wide registry instance

◆ registerHandler()

ReloadId lintel::TlsReloadRegistry::registerHandler ( std::string  name,
Handler  handler 
)

Register a named handler; an existing handler of the same name is replaced.

Parameters
nameunique name, reported by POST /admin/reload-tls
handlerthe reload handler
Returns
the id of this registration, for unregisterHandler()

◆ reload()

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.

Returns
one result per registered handler

◆ unregisterHandler()

void lintel::TlsReloadRegistry::unregisterHandler ( ReloadId  id)

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.


The documentation for this class was generated from the following file: