#![allow(clippy::too_many_arguments)]
use uuid::Uuid;
use crate::AxiamError;
use crate::client::AxiamClient;
use crate::management::models;
use crate::management::request::{Call, Verb};
use crate::management::scope::Scope;
#[derive(Clone, Copy)]
pub struct Scopes<'c> {
pub(crate) client: &'c AxiamClient,
pub(crate) scope: Scope,
}
impl std::fmt::Debug for Scopes<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Scopes")
.field("scope", &self.scope)
.finish()
}
}
impl<'c> Scopes<'c> {
pub(crate) fn new(client: &'c AxiamClient) -> Self {
Self {
client,
scope: Scope::default(),
}
}
pub async fn list(&self, resource_id: Uuid) -> Result<Vec<models::Scope>, AxiamError> {
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "scopes.list",
verb: Verb::Get,
path_template: "/api/v1/resources/{resource_id}/scopes",
path: format!("/api/v1/resources/{resource_id}/scopes"),
query: &query,
};
self.client
.management_send::<_, Vec<models::Scope>>(call, None::<&()>)
.await
}
pub async fn create(
&self,
resource_id: Uuid,
body: &models::CreateScopeRequest,
) -> Result<models::Scope, AxiamError> {
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "scopes.create",
verb: Verb::Post,
path_template: "/api/v1/resources/{resource_id}/scopes",
path: format!("/api/v1/resources/{resource_id}/scopes"),
query: &query,
};
self.client
.management_send::<_, models::Scope>(call, Some(body))
.await
}
pub async fn get(
&self,
resource_id: Uuid,
scope_id: Uuid,
) -> Result<models::Scope, AxiamError> {
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "scopes.get",
verb: Verb::Get,
path_template: "/api/v1/resources/{resource_id}/scopes/{scope_id}",
path: format!("/api/v1/resources/{resource_id}/scopes/{scope_id}"),
query: &query,
};
self.client
.management_send::<_, models::Scope>(call, None::<&()>)
.await
}
pub async fn update(
&self,
resource_id: Uuid,
scope_id: Uuid,
body: &models::UpdateScopeRequest,
) -> Result<models::Scope, AxiamError> {
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "scopes.update",
verb: Verb::Put,
path_template: "/api/v1/resources/{resource_id}/scopes/{scope_id}",
path: format!("/api/v1/resources/{resource_id}/scopes/{scope_id}"),
query: &query,
};
self.client
.management_send::<_, models::Scope>(call, Some(body))
.await
}
pub async fn delete(&self, resource_id: Uuid, scope_id: Uuid) -> Result<(), AxiamError> {
let query: Vec<(&'static str, String)> = Vec::new();
let call = Call {
operation: "scopes.delete",
verb: Verb::Delete,
path_template: "/api/v1/resources/{resource_id}/scopes/{scope_id}",
path: format!("/api/v1/resources/{resource_id}/scopes/{scope_id}"),
query: &query,
};
self.client
.management_send_no_content(call, None::<&()>)
.await
}
}