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 `resources` management namespace (CONTRACT §27.1).
//!
//! The resource hierarchy role assignments cascade down.

#![allow(clippy::too_many_arguments)]

use uuid::Uuid;

use crate::AxiamError;
use crate::client::AxiamClient;
use crate::management::models;
use crate::management::page::{Page, PageRequest, collect_pages};
use crate::management::request::{Call, Verb};
use crate::management::scope::Scope;

/// The `resources` namespace handle.
///
/// The resource hierarchy role assignments cascade down.
///
/// 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 Resources<'c> {
    pub(crate) client: &'c AxiamClient,
    pub(crate) scope: Scope,
}

impl std::fmt::Debug for Resources<'_> {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("Resources")
            .field("scope", &self.scope)
            .finish()
    }
}

impl<'c> Resources<'c> {
    pub(crate) fn new(client: &'c AxiamClient) -> Self {
        Self {
            client,
            scope: Scope::default(),
        }
    }

    /// `GET /api/v1/resources`
    pub async fn list(&self, page: PageRequest) -> Result<Page<models::Resource>, AxiamError> {
        let query = page.query();
        let call = Call {
            operation: "resources.list",
            verb: Verb::Get,
            path_template: "/api/v1/resources",
            path: "/api/v1/resources".to_string(),
            query: &query,
        };
        self.client
            .management_send::<_, Page<models::Resource>>(call, None::<&()>)
            .await
    }

    /// Walk `resources.list` to exhaustion, concatenating every page.
    ///
    /// The auto-paging form §27.4 rule 4 requires. It stops on an empty page even
    /// if `total` disagrees, so a misreporting server costs one wasted request
    /// rather than an unbounded loop.
    pub async fn list_all(&self, start: PageRequest) -> Result<Vec<models::Resource>, AxiamError> {
        collect_pages(start, |p| self.list(p)).await
    }

    /// `POST /api/v1/resources`
    /// 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,
        body: &models::CreateResourceRequest,
    ) -> Result<models::Resource, AxiamError> {
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "resources.create",
            verb: Verb::Post,
            path_template: "/api/v1/resources",
            path: "/api/v1/resources".to_string(),
            query: &query,
        };
        self.client
            .management_send::<_, models::Resource>(call, Some(body))
            .await
    }

    /// `GET /api/v1/resources/{resource_id}`
    pub async fn get(&self, resource_id: Uuid) -> Result<models::Resource, AxiamError> {
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "resources.get",
            verb: Verb::Get,
            path_template: "/api/v1/resources/{resource_id}",
            path: format!("/api/v1/resources/{resource_id}"),
            query: &query,
        };
        self.client
            .management_send::<_, models::Resource>(call, None::<&()>)
            .await
    }

    /// `PUT /api/v1/resources/{resource_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,
        body: &models::UpdateResourceRequest,
    ) -> Result<models::Resource, AxiamError> {
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "resources.update",
            verb: Verb::Put,
            path_template: "/api/v1/resources/{resource_id}",
            path: format!("/api/v1/resources/{resource_id}"),
            query: &query,
        };
        self.client
            .management_send::<_, models::Resource>(call, Some(body))
            .await
    }

    /// `DELETE /api/v1/resources/{resource_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) -> Result<(), AxiamError> {
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "resources.delete",
            verb: Verb::Delete,
            path_template: "/api/v1/resources/{resource_id}",
            path: format!("/api/v1/resources/{resource_id}"),
            query: &query,
        };
        self.client
            .management_send_no_content(call, None::<&()>)
            .await
    }

    /// `GET /api/v1/resources/{resource_id}/children`
    pub async fn list_children(
        &self,
        resource_id: Uuid,
    ) -> Result<Vec<models::Resource>, AxiamError> {
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "resources.list_children",
            verb: Verb::Get,
            path_template: "/api/v1/resources/{resource_id}/children",
            path: format!("/api/v1/resources/{resource_id}/children"),
            query: &query,
        };
        self.client
            .management_send::<_, Vec<models::Resource>>(call, None::<&()>)
            .await
    }

    /// `GET /api/v1/resources/{resource_id}/ancestors`
    pub async fn list_ancestors(
        &self,
        resource_id: Uuid,
    ) -> Result<Vec<models::Resource>, AxiamError> {
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "resources.list_ancestors",
            verb: Verb::Get,
            path_template: "/api/v1/resources/{resource_id}/ancestors",
            path: format!("/api/v1/resources/{resource_id}/ancestors"),
            query: &query,
        };
        self.client
            .management_send::<_, Vec<models::Resource>>(call, None::<&()>)
            .await
    }
}