Skip to main content

ClientBuilder

Struct ClientBuilder 

Source
pub struct ClientBuilder { /* private fields */ }
Expand description

Builder for Client.

Implementations§

Source§

impl ClientBuilder

Source

pub fn new() -> Self

Create a builder with production defaults: HTTPS, public addresses, TEA 1.0.0.

Source

pub fn cache_dir(self, dir: impl Into<PathBuf>) -> Self

Keep a persistent response cache in dir (experimental; off by default).

GET responses are stored and revalidated with ETag / Last-Modified conditional requests. The directory is created private (mode 0700, files 0600 on Unix); a symbolic link or a directory open to other users makes ClientBuilder::build fail. Responses to requests that carried credentials, Cache-Control: no-store and (by default) private responses are not stored. Cache contents are never trusted: artifact bytes are checked against their declared checksums on every use. See docs/cache.md and CacheConfig for the limits.

Source

pub fn cache(self, config: CacheConfig) -> Self

Enable the cache with explicit settings (experimental).

Source

pub fn offline(self, offline: bool) -> Self

Answer only from the cache and never open a connection (experimental).

A cacheable GET that is not in the cache (or whose entry is older than CacheConfig::max_age) fails with ClientError::Offline; any other request fails the same way. Requires ClientBuilder::cache_dir or ClientBuilder::cache; ClientBuilder::build fails without one.

Source

pub fn limits(self, limits: Limits) -> Self

Replace resource limits.

Source

pub fn destination_policy(self, policy: DestinationPolicy) -> Self

Replace the destination policy.

The default rejects cleartext HTTP, loopback, link-local, and private addresses.

Source

pub fn supported_versions(self, supported: SupportedApi) -> Self

Versions this client is willing to speak. Build metadata on the server is ignored.

Source

pub fn api_key(self, key: ApiKey) -> Self

API key used at POST /token for origins the caller has explicitly selected.

Discovery does not send this key to endpoints learned from .well-known/tea unless Self::allow_discovered_credentials is set. A crate::Service built from a caller-supplied base URL may use the key at that origin.

Source

pub fn allow_discovered_credentials(self, allow: bool) -> Self

Allow the API key to be presented to token endpoints chosen by discovery.

Leave this unset when the well-known document is not a trusted source of credential destinations.

Source

pub fn well_known_fetch_url(self, url: Url) -> Self

Fetch the well-known document from this URL instead of https://{tei-domain}/.well-known/tea.

The override is still subject to DestinationPolicy. It exists so tests and explicitly configured fixtures can supply the document without changing production URL construction.

Source

pub fn lenient_versions(self, lenient: bool) -> Self

Accept API versions that are not exactly a supported one (default false).

When true, /.well-known/tea and /discovery may advertise 1 or 1.0 (read as 1.0.0; the advertised spelling stays in the request path, so 1 calls /v1/…), and any stable version with the same major as a supported version is accepted, for example 1.0.1 and 1.1.0 for a client that supports 1.0.0. Pre-releases (1.2.0-rc.1) are accepted only on an exact match.

Selection order: exact supported versions first (highest version, then priority), then same-major stable versions (highest first). An exact match is never outranked by a version this client was not written for.

Risk: this client’s models were checked against the pinned 1.0.0 schemas only. A server that passes the version check may still send responses that fail to parse or that are misread. The default (false) is unchanged from earlier behavior.

Source

pub fn allow_weak_checksums(self, allow: bool) -> Self

Accept artifact downloads whose only declared checksums use weak algorithms (SHA-1).

Off by default: such a download fails with ClientError::Integrity and libtea_core::IntegrityOutcome::Weak. When set, a full match is reported as libtea_core::IntegrityOutcome::Verified and each libtea_core::ChecksumCheck::weak stays true.

Source

pub fn ignore_env_proxies(self, ignore: bool) -> Self

Ignore HTTP_PROXY / HTTPS_PROXY / ALL_PROXY (and lowercase forms).

By default environment proxies are honored. Through a proxy, the proxy resolves the target hostname, so the DNS-based DestinationPolicy checks are not enforced for hostnames; only scheme, userinfo, literal-IP, and redirect checks still apply. Set this to true to connect directly and keep the DNS checks.

Source

pub fn add_root_pem(self, pem: impl Into<Vec<u8>>) -> Self

Add a PEM trust anchor. System or webpki roots remain in use as well.

Source

pub fn build(self) -> Result<Client, ClientError>

Build the client.

§Errors

Returns an error when TLS or the HTTP client cannot be constructed.

Trait Implementations§

Source§

impl Default for ClientBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. 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<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more