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 `groups` management namespace (CONTRACT §27.1).
//!
//! Named collections of users. Roles assigned to a group are inherited by
//! every member.

#![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 `groups` namespace handle.
///
/// Named collections of users. Roles assigned to a group are inherited by
/// every member.
///
/// 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 Groups<'c> {
    pub(crate) client: &'c AxiamClient,
    pub(crate) scope: Scope,
}

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

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

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

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

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

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

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

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

    /// `GET /api/v1/groups/{group_id}/members`
    pub async fn list_members(
        &self,
        group_id: Uuid,
        page: PageRequest,
    ) -> Result<Page<models::UserResponse>, AxiamError> {
        let query = page.query();
        let call = Call {
            operation: "groups.list_members",
            verb: Verb::Get,
            path_template: "/api/v1/groups/{group_id}/members",
            path: format!("/api/v1/groups/{group_id}/members"),
            query: &query,
        };
        self.client
            .management_send::<_, Page<models::UserResponse>>(call, None::<&()>)
            .await
    }

    /// Walk `groups.list_members` 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_members_all(
        &self,
        group_id: Uuid,
        start: PageRequest,
    ) -> Result<Vec<models::UserResponse>, AxiamError> {
        collect_pages(start, |p| self.list_members(group_id, p)).await
    }

    /// `POST /api/v1/groups/{group_id}/members`
    /// 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 add_member(
        &self,
        group_id: Uuid,
        body: &models::AddMemberRequest,
    ) -> Result<(), AxiamError> {
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "groups.add_member",
            verb: Verb::Post,
            path_template: "/api/v1/groups/{group_id}/members",
            path: format!("/api/v1/groups/{group_id}/members"),
            query: &query,
        };
        self.client
            .management_send_no_content(call, Some(body))
            .await
    }

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

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

    /// `GET /api/v1/groups/{group_id}/service-accounts`
    pub async fn list_service_accounts(
        &self,
        group_id: Uuid,
        page: PageRequest,
    ) -> Result<Page<models::ServiceAccountResponse>, AxiamError> {
        let query = page.query();
        let call = Call {
            operation: "groups.list_service_accounts",
            verb: Verb::Get,
            path_template: "/api/v1/groups/{group_id}/service-accounts",
            path: format!("/api/v1/groups/{group_id}/service-accounts"),
            query: &query,
        };
        self.client
            .management_send::<_, Page<models::ServiceAccountResponse>>(call, None::<&()>)
            .await
    }

    /// Walk `groups.list_service_accounts` 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_service_accounts_all(
        &self,
        group_id: Uuid,
        start: PageRequest,
    ) -> Result<Vec<models::ServiceAccountResponse>, AxiamError> {
        collect_pages(start, |p| self.list_service_accounts(group_id, p)).await
    }

    /// `POST /api/v1/groups/{group_id}/service-accounts`
    /// 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 add_service_account(
        &self,
        group_id: Uuid,
        body: &models::AddServiceAccountMemberRequest,
    ) -> Result<(), AxiamError> {
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "groups.add_service_account",
            verb: Verb::Post,
            path_template: "/api/v1/groups/{group_id}/service-accounts",
            path: format!("/api/v1/groups/{group_id}/service-accounts"),
            query: &query,
        };
        self.client
            .management_send_no_content(call, Some(body))
            .await
    }

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