#![doc = "Generated implementation of authenticated SDK resource facades."]
use reqwest_middleware::ClientWithMiddleware;
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;
#[derive(Clone, Debug)]
pub struct AuthenticatedClient {
http: HttpClient,
client: ConnectionsClient,
}
impl AuthenticatedClient {
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 })
}
pub fn with_client(mut self, client: impl Into<ClientWithMiddleware>) -> Self {
self.http = self.http.with_client(client);
self.client = self.client.with_transport(self.http.middleware_client());
self
}
pub fn with_token_source(mut self, provider: TokenSource) -> Self {
self.http = self.http.with_token_source(provider);
self
}
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)?
}
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)?
}
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)?
}
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)?
}
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)?
}
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)?
}
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)?
}
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)?
}
}