pub mod delegated;
pub mod types;
#[allow(unused_imports)]
use types::*;
#[derive(Clone)]
pub struct PermissionsClient {
client: crate::client::Client,
}
impl PermissionsClient {
pub fn new(client: crate::client::Client) -> Self {
PermissionsClient { client }
}
pub async fn archive_permission(
&self,
permission_id: String,
body: ArchivePermissionRequest,
) -> Result<ArchivePermissionResponse, crate::error::Error> {
let path = format!(
"/permissions/{}/archive",
urlencoding::encode(&permission_id)
);
let body = serde_json::to_value(&body)?;
self.client
.request::<ArchivePermissionResponse>(reqwest::Method::PUT, &path, Some(&body), true)
.await
}
pub async fn list_permission_assignments(
&self,
permission_id: String,
query: Option<ListPermissionAssignmentsQuery>,
) -> Result<ListPermissionAssignmentsResponse, crate::error::Error> {
let mut path = format!(
"/permissions/{}/assignments",
urlencoding::encode(&permission_id)
);
if let Some(query) = &query {
let mut q: Vec<String> = Vec::new();
if let Some(v) = &query.limit {
q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
}
if let Some(v) = &query.pagination_token {
q.push(format!(
"paginationToken={}",
urlencoding::encode(&v.to_string())
));
}
if !q.is_empty() {
path.push('?');
path.push_str(&q.join("&"));
}
}
self.client
.request::<ListPermissionAssignmentsResponse>(reqwest::Method::GET, &path, None, false)
.await
}
pub async fn assign_permission(
&self,
permission_id: String,
body: AssignPermissionRequest,
) -> Result<AssignPermissionResponse, crate::error::Error> {
let path = format!(
"/permissions/{}/assignments",
urlencoding::encode(&permission_id)
);
let body = serde_json::to_value(&body)?;
self.client
.request::<AssignPermissionResponse>(reqwest::Method::POST, &path, Some(&body), true)
.await
}
pub async fn list_permissions(
&self,
query: Option<ListPermissionsQuery>,
) -> Result<ListPermissionsResponse, crate::error::Error> {
let mut path = String::from("/permissions");
if let Some(query) = &query {
let mut q: Vec<String> = Vec::new();
if let Some(v) = &query.limit {
q.push(format!("limit={}", urlencoding::encode(&v.to_string())));
}
if let Some(v) = &query.pagination_token {
q.push(format!(
"paginationToken={}",
urlencoding::encode(&v.to_string())
));
}
if !q.is_empty() {
path.push('?');
path.push_str(&q.join("&"));
}
}
self.client
.request::<ListPermissionsResponse>(reqwest::Method::GET, &path, None, false)
.await
}
pub async fn create_permission(
&self,
body: CreatePermissionRequest,
) -> Result<CreatePermissionResponse, crate::error::Error> {
let path = String::from("/permissions");
let body = serde_json::to_value(&body)?;
self.client
.request::<CreatePermissionResponse>(reqwest::Method::POST, &path, Some(&body), true)
.await
}
pub async fn revoke_permission(
&self,
permission_id: String,
assignment_id: String,
query: Option<RevokePermissionQuery>,
) -> Result<(), crate::error::Error> {
let mut path = format!(
"/permissions/{}/assignments/{}",
urlencoding::encode(&permission_id),
urlencoding::encode(&assignment_id)
);
if let Some(query) = &query {
let mut q: Vec<String> = Vec::new();
if let Some(v) = &query.force {
q.push(format!("force={}", urlencoding::encode(&v.to_string())));
}
if !q.is_empty() {
path.push('?');
path.push_str(&q.join("&"));
}
}
self.client
.request_no_content(reqwest::Method::DELETE, &path, None, true)
.await
}
pub async fn get_permission(
&self,
permission_id: String,
) -> Result<GetPermissionResponse, crate::error::Error> {
let path = format!("/permissions/{}", urlencoding::encode(&permission_id));
self.client
.request::<GetPermissionResponse>(reqwest::Method::GET, &path, None, false)
.await
}
pub async fn update_permission(
&self,
permission_id: String,
body: UpdatePermissionRequest,
) -> Result<UpdatePermissionResponse, crate::error::Error> {
let path = format!("/permissions/{}", urlencoding::encode(&permission_id));
let body = serde_json::to_value(&body)?;
self.client
.request::<UpdatePermissionResponse>(reqwest::Method::PUT, &path, Some(&body), true)
.await
}
}