Skip to main content

ConfigServer

Struct ConfigServer 

Source
pub struct ConfigServer { /* private fields */ }
Available on crate feature 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

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source

pub fn watch<F>( &self, watching: &Watching, interval: Duration, on_change: F, ) -> Result<(), Error>
where F: FnMut(Fetched) -> 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

Source§

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

Source§

fn watch_capability(&self) -> WatchCapability

Native: the server pushes a generation down a text/event-stream.

Source§

fn fetch(&self) -> Result<Fetched, Error>

Reads the current document. Read more
Source§

fn describe(&self) -> String

How to name this source in an error or a report.
Source§

fn watch( &self, watching: &Watching, interval: Duration, on_change: &mut dyn FnMut(Fetched) -> Result<(), Error>, ) -> Result<(), Error>

Watches until the handle is dropped, calling on_change with every document that differs from the last one delivered. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.