#![doc = "Generated implementation of authenticated SDK resource facades."]
use spiral_contract::call::CallError;
use crate::api::authorization::AuthorizationClient;
use crate::api::authorization::objects::*;
use crate::auth::TokenSource;
use crate::http::HttpClient;
#[derive(Clone, Debug)]
pub struct AuthenticatedClient {
http: HttpClient,
client: AuthorizationClient,
}
impl AuthenticatedClient {
pub fn new(base: &str) -> Result<Self, CallError<AuthorizationError>> {
Self::from_http(HttpClient::connect(base).map_err(CallError::transport)?)
}
pub(crate) fn from_http(http: HttpClient) -> Result<Self, CallError<AuthorizationError>> {
let client = AuthorizationClient::from_transport(
http.base_url().as_str(),
http.middleware_client(),
)?;
Ok(Self { http, client })
}
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
}
pub fn with_token_source(mut self, provider: TokenSource) -> Self {
self.http = self.http.with_token_source(provider);
self
}
pub async fn approve_installation(
&self,
installation_id: String,
) -> Result<ReviewResponse, CallError<AuthorizationError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client
.approve_installation_http(auth_header, installation_id),
)
.await
.map_err(CallError::transport)?
}
pub async fn grant_role(
&self,
project_id: String,
request: GrantRoleRequest,
) -> Result<GrantResponse, CallError<AuthorizationError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client
.grant_role_http(auth_header, project_id, request),
)
.await
.map_err(CallError::transport)?
}
pub async fn list_grants(
&self,
project_id: String,
request: ListGrantsRequest,
) -> Result<GrantPage, CallError<AuthorizationError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client
.list_grants_http(auth_header, project_id, request),
)
.await
.map_err(CallError::transport)?
}
pub fn list_grants_list(
&self,
project_id: String,
request: ListGrantsRequest,
) -> crate::List<'_, Grant> {
let options = crate::pagination::PageOptions {
token: request.page_token.clone(),
size: request.page_size,
};
crate::List::new(move |options| {
let project_id = ToOwned::to_owned(&project_id);
let mut request = request.clone();
request.page_token = options.token;
request.page_size = options.size;
Box::pin(async move {
let page = self.list_grants(project_id, request).await?;
Ok(crate::Page {
items: page.items,
next_page_token: page.next_page_token,
})
})
})
.with_options(options)
}
pub async fn read_grant(
&self,
grant_id: String,
) -> Result<Grant, CallError<AuthorizationError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client.read_grant_http(auth_header, grant_id),
)
.await
.map_err(CallError::transport)?
}
pub async fn read_installation(
&self,
installation_id: String,
) -> Result<InstallationResponse, CallError<AuthorizationError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client
.read_installation_http(auth_header, installation_id),
)
.await
.map_err(CallError::transport)?
}
pub async fn reject_installation(
&self,
installation_id: String,
) -> Result<ReviewResponse, CallError<AuthorizationError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client
.reject_installation_http(auth_header, installation_id),
)
.await
.map_err(CallError::transport)?
}
pub async fn review_installation(
&self,
installation_id: String,
request: ReviewRequest,
) -> Result<ReviewResponse, CallError<AuthorizationError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client
.review_installation_http(auth_header, installation_id, request),
)
.await
.map_err(CallError::transport)?
}
pub async fn revoke_grant(
&self,
grant_id: String,
) -> Result<(), CallError<AuthorizationError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client.revoke_grant_http(auth_header, grant_id),
)
.await
.map_err(CallError::transport)?
}
}