Skip to main content

Provider

Trait Provider 

Source
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 for ProviderHost::metadata.
  • paginate: cancellable page-walk with MAX_PAGES guard.
  • http_agent / http_agent_insecure: ureq agent setup.
  • map_ureq_error: HTTP error to ProviderError mapping (401 to AuthFailed, 429 to RateLimited, 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§

Source

fn name(&self) -> &str

Full provider name (e.g. “digitalocean”).

Source

fn short_label(&self) -> &str

Short label for aliases (e.g. “do”).

Source

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§

Source

fn fetch_hosts( &self, token: &str, env: &Env, ) -> Result<Vec<ProviderHost>, ProviderError>

Fetch all servers from the provider API.

Source

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".

Implementors§