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 `tenants` management namespace (CONTRACT §27.1).
//!
//! Tenants within an organization -- the isolation boundary every other
//! namespace is scoped to.

#![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 `tenants` namespace handle.
///
/// Tenants within an organization -- the isolation boundary every other
/// namespace is scoped to.
///
/// 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 Tenants<'c> {
    pub(crate) client: &'c AxiamClient,
    pub(crate) scope: Scope,
}

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

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

    /// Address a different organization than the client's own.
    ///
    /// §27.4 rule 3: the client's `org_id` is the default, and a platform-admin
    /// token legitimately overrides it.
    #[must_use]
    pub fn in_org(mut self, org_id: Uuid) -> Self {
        self.scope.org_id = Some(org_id);
        self
    }

    /// `GET /api/v1/organizations/{org_id}/tenants`
    pub async fn list(&self, page: PageRequest) -> Result<Page<models::Tenant>, AxiamError> {
        let org_id = self.scope.org(self.client, "tenants.list")?;
        let query = page.query();
        let call = Call {
            operation: "tenants.list",
            verb: Verb::Get,
            path_template: "/api/v1/organizations/{org_id}/tenants",
            path: format!("/api/v1/organizations/{org_id}/tenants"),
            query: &query,
        };
        self.client
            .management_send::<_, Page<models::Tenant>>(call, None::<&()>)
            .await
    }

    /// Walk `tenants.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::Tenant>, AxiamError> {
        collect_pages(start, |p| self.list(p)).await
    }

    /// `POST /api/v1/organizations/{org_id}/tenants`
    /// 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::CreateTenantRequest,
    ) -> Result<models::Tenant, AxiamError> {
        let org_id = self.scope.org(self.client, "tenants.create")?;
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "tenants.create",
            verb: Verb::Post,
            path_template: "/api/v1/organizations/{org_id}/tenants",
            path: format!("/api/v1/organizations/{org_id}/tenants"),
            query: &query,
        };
        self.client
            .management_send::<_, models::Tenant>(call, Some(body))
            .await
    }

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

    /// `PUT /api/v1/organizations/{org_id}/tenants/{tenant_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,
        tenant_id: Uuid,
        body: &models::UpdateTenant,
    ) -> Result<models::Tenant, AxiamError> {
        let org_id = self.scope.org(self.client, "tenants.update")?;
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "tenants.update",
            verb: Verb::Put,
            path_template: "/api/v1/organizations/{org_id}/tenants/{tenant_id}",
            path: format!("/api/v1/organizations/{org_id}/tenants/{tenant_id}"),
            query: &query,
        };
        self.client
            .management_send::<_, models::Tenant>(call, Some(body))
            .await
    }

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

    /// `POST /api/v1/organizations/{org_id}/tenants/{tenant_id}/audit-export`
    /// 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 export_audit(&self, tenant_id: Uuid) -> Result<(), AxiamError> {
        let org_id = self.scope.org(self.client, "tenants.export_audit")?;
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "tenants.export_audit",
            verb: Verb::Post,
            path_template: "/api/v1/organizations/{org_id}/tenants/{tenant_id}/audit-export",
            path: format!("/api/v1/organizations/{org_id}/tenants/{tenant_id}/audit-export"),
            query: &query,
        };
        self.client
            .management_send_no_content(call, None::<&()>)
            .await
    }
}