axiam-sdk 1.2.2

Official Rust client SDK for AXIAM IAM
Documentation
// @generated by tools/gen_management.py from management-registry.json and
// openapi.json. DO NOT EDIT -- your changes will be overwritten. Regenerate
// with `tools/gen_management.py`; CI verifies the committed output is current.

//! The `scopes` management namespace (CONTRACT §27.1).
//!
//! Sub-resource granularity, always addressed under their resource.

#![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;

/// The `scopes` namespace handle.
///
/// Sub-resource granularity, always addressed under their resource.
///
/// Acquiring one performs no I/O and allocates nothing meaningful (§27.2 rule
/// 1); it borrows the client and cannot outlive it.
#[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(),
        }
    }

    /// `GET /api/v1/resources/{resource_id}/scopes`
    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
    }

    /// `POST /api/v1/resources/{resource_id}/scopes`
    /// Not retried on failure (§27.4 rule 8): every write on this surface is
    /// issued exactly once, including the ones that look idempotent.
    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
    }

    /// `GET /api/v1/resources/{resource_id}/scopes/{scope_id}`
    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
    }

    /// `PUT /api/v1/resources/{resource_id}/scopes/{scope_id}`
    /// Not retried on failure (§27.4 rule 8): every write on this surface is
    /// issued exactly once, including the ones that look idempotent.
    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
    }

    /// `DELETE /api/v1/resources/{resource_id}/scopes/{scope_id}`
    /// Not retried on failure (§27.4 rule 8): every write on this surface is
    /// issued exactly once, including the ones that look idempotent.
    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
    }
}