spiral-sdk 0.1.10

Rust SDK for Spiral resource and table APIs
Documentation
// Generated by tools/service-contracts/rust.py. Do not edit.
#![doc = "Generated implementation of authenticated SDK resource facades."]
use spiral_contract::call::CallError;
use uuid::Uuid;

use crate::api::connections::ConnectionsClient;
use crate::api::connections::objects::*;
use crate::auth::TokenSource;
use crate::http::HttpClient;
/// Service operations sharing a connection pool and resolving credentials for every request.
#[derive(Clone, Debug)]
pub struct AuthenticatedClient {
    http: HttpClient,
    client: ConnectionsClient,
}
impl AuthenticatedClient {
    /// Connect with bounded requests; configure credentials before authenticated calls.
    pub fn new(base: &str) -> Result<Self, CallError<ConnectionsError>> {
        Self::from_http(HttpClient::connect(base).map_err(CallError::transport)?)
    }
    pub(crate) fn from_http(http: HttpClient) -> Result<Self, CallError<ConnectionsError>> {
        let client =
            ConnectionsClient::from_transport(http.base_url().as_str(), http.middleware_client())?;
        Ok(Self { http, client })
    }
    /// Reuse a connection pool with redirects disabled to protect bearer credentials.
    pub fn with_client(mut self, client: reqwest::Client) -> Self {
        self.http = self.http.with_client(client);
        self.client = self.client.with_transport(self.http.middleware_client());
        self
    }
    /// Resolve the provider's current credential before each request and pagination fetch.
    pub fn with_token_source(mut self, provider: TokenSource) -> Self {
        self.http = self.http.with_token_source(provider);
        self
    }
    /// Create a Connection scoped to one Project.
    pub async fn create_connection(
        &self,
        request: CreateConnectionRequest,
    ) -> Result<CreateConnectionResponse, CallError<ConnectionsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client.create_connection_http(auth_header, request),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Drop a Connection and remove its stored secret.
    pub async fn drop_connection(
        &self,
        connection_id: Uuid,
    ) -> Result<DropResponse, CallError<ConnectionsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client.drop_connection_http(auth_header, connection_id),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Read a Connection without exposing its stored secret.
    pub async fn read_connection(
        &self,
        connection_id: Uuid,
    ) -> Result<ConnectionResponse, CallError<ConnectionsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client.read_connection_http(auth_header, connection_id),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Test credential vending and provider access. Provider refusals are reported in the response.
    pub async fn test_connection(
        &self,
        connection_id: Uuid,
    ) -> Result<TestResponse, CallError<ConnectionsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client.test_connection_http(auth_header, connection_id),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Change the maximum access granted by this Connection. Increasing access first verifies it
    /// with the provider.
    pub async fn update_allowed_access(
        &self,
        connection_id: Uuid,
        request: UpdateAllowedAccessRequest,
    ) -> Result<ConnectionResponse, CallError<ConnectionsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .update_allowed_access_http(auth_header, connection_id, request),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Replace the entire credential with one for the same provider. Include every required secret.
    pub async fn update_credential(
        &self,
        connection_id: Uuid,
        request: UpdateCredentialRequest,
    ) -> Result<ConnectionResponse, CallError<ConnectionsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .update_credential_http(auth_header, connection_id, request),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Replace the description. Omit it to clear the description.
    pub async fn update_description(
        &self,
        connection_id: Uuid,
        request: UpdateDescriptionRequest,
    ) -> Result<ConnectionResponse, CallError<ConnectionsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .update_description_http(auth_header, connection_id, request),
        )
        .await
        .map_err(CallError::transport)?
    }
    /// Obtain a short-lived read credential for a URI within the Connection.
    pub async fn vend_credential(
        &self,
        connection_id: Uuid,
        request: VendRequest,
    ) -> Result<VendResponse, CallError<ConnectionsError>> {
        let auth_header = self
            .http
            .auth_header()
            .await
            .map_err(CallError::transport)?;
        tokio::time::timeout(
            std::time::Duration::from_secs(60),
            self.client
                .vend_credential_http(auth_header, connection_id, request),
        )
        .await
        .map_err(CallError::transport)?
    }
}