pub trait Provider {
// Required methods
fn name(&self) -> &str;
fn short_label(&self) -> &str;
fn fetch_hosts_cancellable(
&self,
token: &str,
cancel: &AtomicBool,
env: &Env,
) -> Result<Vec<ProviderHost>, ProviderError>;
// Provided methods
fn fetch_hosts(
&self,
token: &str,
env: &Env,
) -> Result<Vec<ProviderHost>, ProviderError> { ... }
fn fetch_hosts_with_progress(
&self,
token: &str,
cancel: &AtomicBool,
env: &Env,
_progress: &dyn Fn(&str),
) -> Result<Vec<ProviderHost>, ProviderError> { ... }
}Expand description
Trait implemented by each cloud provider.
The trait deliberately stays narrow: every provider implements
fetch_hosts_cancellable itself rather than overriding a uniform
fetch loop. Variation is too wide for a single shape. Linode and
DigitalOcean use ?page=N&per_page=N; GCP uses ?maxResults=N
plus a pageToken cursor across an aggregated multi-zone listing;
Azure paginates across multiple subscriptions; AWS uses SigV4 plus
the EC2 query API; Tailscale mixes Basic and Bearer auth depending
on key prefix; Oracle signs each request with a per-tenancy RSA
key.
What is shared lives in this module as free helpers so every provider opts in to the parts that apply:
bearer_auth:Authorization: Bearer <token>formatter.ProviderMetadata: typed builder forProviderHost::metadata.paginate: cancellable page-walk withMAX_PAGESguard.http_agent/http_agent_insecure: ureq agent setup.map_ureq_error: HTTP error toProviderErrormapping (401 toAuthFailed, 429 toRateLimited, etc).strip_cidr,percent_encode,epoch_to_date: string and URL helpers.
Adding a new provider: implement fetch_hosts_cancellable and
reach for the helpers above instead of reimplementing them. Do
not invent provider-specific copies of these primitives; that is
where past parity bugs have hidden.
Required Methods§
Sourcefn short_label(&self) -> &str
fn short_label(&self) -> &str
Short label for aliases (e.g. “do”).
Sourcefn fetch_hosts_cancellable(
&self,
token: &str,
cancel: &AtomicBool,
env: &Env,
) -> Result<Vec<ProviderHost>, ProviderError>
fn fetch_hosts_cancellable( &self, token: &str, cancel: &AtomicBool, env: &Env, ) -> Result<Vec<ProviderHost>, ProviderError>
Fetch hosts with cancellation support. env carries the resolved
process environment (home directory, credential env vars) so the few
providers that read AWS credentials or expand ~ in key paths take
them from the injected snapshot instead of ambient std::env /
dirs::home_dir. Most providers ignore it.
Provided Methods§
Sourcefn fetch_hosts(
&self,
token: &str,
env: &Env,
) -> Result<Vec<ProviderHost>, ProviderError>
fn fetch_hosts( &self, token: &str, env: &Env, ) -> Result<Vec<ProviderHost>, ProviderError>
Fetch all servers from the provider API.
Sourcefn fetch_hosts_with_progress(
&self,
token: &str,
cancel: &AtomicBool,
env: &Env,
_progress: &dyn Fn(&str),
) -> Result<Vec<ProviderHost>, ProviderError>
fn fetch_hosts_with_progress( &self, token: &str, cancel: &AtomicBool, env: &Env, _progress: &dyn Fn(&str), ) -> Result<Vec<ProviderHost>, ProviderError>
Fetch hosts with progress reporting. Default delegates to fetch_hosts_cancellable.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".