pub struct ConfigServer { /* private fields */ }client only.Expand description
A RemoteSource reading one application-and-profile from a config
server.
The credential is a bearer token, scoped by the server to the applications
it may read; TLS with a private authority and a client certificate is
TlsConfig, the same type every store crate in this workspace takes.
Implementations§
Source§impl ConfigServer
impl ConfigServer
Sourcepub fn new(
url: impl Into<String>,
application: impl Into<String>,
profile: impl Into<String>,
) -> Self
pub fn new( url: impl Into<String>, application: impl Into<String>, profile: impl Into<String>, ) -> Self
A source reading {url}/{application}/{profile}.
url may carry a path prefix — https://config.internal/config — for
a server mounted behind one. A userinfo component is refused rather
than dropped: this server’s credential is a bearer token, and a
password in a url is a password in every log that url reaches.
Sourcepub fn reporting_to(self, sink: RemoteSink) -> Self
pub fn reporting_to(self, sink: RemoteSink) -> Self
Report failed attempts to sink, so an outage is visible.
A watch swallows transport failures on purpose — outliving one is
what a watch is for — and the cost of that is a store that has been
unreachable for an hour while status().reachable() says otherwise.
This is the door the eight store crates carry, and the same
discipline: take the sink where the watch is wired, once, because a
sink captures the generation of the source installed at that moment
and that is what fences a winding-down loop’s failures away from its
replacement.
A failure moves the failure streak and nothing else. The fetch
count and the clock are left alone, so a dashboard keeps ageing
last_fetch while up goes to zero — the pair an alert wants. It
changes nothing about what watch returns.
Sourcepub fn with_token(self, token: impl Into<String>) -> Self
pub fn with_token(self, token: impl Into<String>) -> Self
The bearer token this server issued for these applications.
Without one the server answers 401 unless it was started with
anonymous access explicitly enabled.
Sourcepub fn with_token_file(self, path: impl Into<PathBuf>) -> Self
pub fn with_token_file(self, path: impl Into<PathBuf>) -> Self
The bearer token read from a file, re-read at every fetch —
for credentials something else rotates underneath this client,
first among them a pod’s projected service-account token (the
server’s [kubernetes] auth reviews exactly that). Wins over
with_token when both are set.
Sourcepub fn with_tls(self, tls: TlsConfig) -> Self
pub fn with_tls(self, tls: TlsConfig) -> Self
A private certificate authority, a client certificate, or both.
The same TlsConfig the store crates take, so a deployment spells
its trust once and uses it everywhere.
Sourcepub fn with_timeout(self, timeout: Duration) -> Self
pub fn with_timeout(self, timeout: Duration) -> Self
The deadline for one fetch: connect, TLS handshake, request and body.
Ten seconds by default. A fetch that hangs is a reload that never happens, and the loop above has no other way to notice.
Source§impl ConfigServer
impl ConfigServer
Sourcepub fn watch<F>(
&self,
watching: &Watching,
interval: Duration,
on_change: F,
) -> Result<(), Error>
pub fn watch<F>( &self, watching: &Watching, interval: Duration, on_change: F, ) -> Result<(), Error>
Follows the change stream, fetching whenever the generation moves.
Blocks until watching is stopped, so it belongs on a thread of its
own. interval is the reconnect pace rather than a poll: the stream
pushes, and this is how long to wait before trying again when it
ends. The waits are spread across a fleet and grow after a failure,
so a server coming back up is not met by every pod at once.
Each document is delivered only when it differs from the last one: a generation moves for every install, and an install that changed nothing this caller can see should wake nothing.
§Errors
If on_change refuses a document. A connection failing is not an
error — reconnecting through an outage is what this is for.
Trait Implementations§
Source§impl Debug for ConfigServer
impl Debug for ConfigServer
Source§fn fmt(&self, formatter: &mut Formatter<'_>) -> Result
fn fmt(&self, formatter: &mut Formatter<'_>) -> Result
Shape only. The token is the credential and never prints; TlsConfig
redacts its own key material; and the URL is redacted too, because a
user:password@ authority is refused at fetch time rather than at
construction — so a source carrying one can be printed.
Source§impl RemoteSource for ConfigServer
impl RemoteSource for ConfigServer
Source§fn watch_capability(&self) -> WatchCapability
fn watch_capability(&self) -> WatchCapability
Native: the server pushes a generation down a text/event-stream.