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 `roles` management namespace (CONTRACT §27.1).
//!
//! Roles, their permission sets, and their assignment to users and groups.

#![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 `roles` namespace handle.
///
/// Roles, their permission sets, and their assignment to users and groups.
///
/// 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 Roles<'c> {
    pub(crate) client: &'c AxiamClient,
    pub(crate) scope: Scope,
}

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

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

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

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

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

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

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

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

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

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

    /// `DELETE /api/v1/roles/{role_id}/users/{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 unassign_from_user(
        &self,
        role_id: Uuid,
        user_id: Uuid,
        resource_id: Option<&str>,
    ) -> Result<(), AxiamError> {
        let mut query: Vec<(&'static str, String)> = Vec::new();
        if let Some(v) = resource_id {
            query.push(("resource_id", v.to_string()));
        }
        let call = Call {
            operation: "roles.unassign_from_user",
            verb: Verb::Delete,
            path_template: "/api/v1/roles/{role_id}/users/{user_id}",
            path: format!("/api/v1/roles/{role_id}/users/{user_id}"),
            query: &query,
        };
        self.client
            .management_send_no_content(call, None::<&()>)
            .await
    }

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

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

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

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

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

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

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

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

    /// `DELETE /api/v1/roles/{role_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 unassign_from_service_account(
        &self,
        role_id: Uuid,
        service_account_id: Uuid,
        resource_id: Option<&str>,
    ) -> Result<(), AxiamError> {
        let mut query: Vec<(&'static str, String)> = Vec::new();
        if let Some(v) = resource_id {
            query.push(("resource_id", v.to_string()));
        }
        let call = Call {
            operation: "roles.unassign_from_service_account",
            verb: Verb::Delete,
            path_template: "/api/v1/roles/{role_id}/service-accounts/{service_account_id}",
            path: format!("/api/v1/roles/{role_id}/service-accounts/{service_account_id}"),
            query: &query,
        };
        self.client
            .management_send_no_content(call, None::<&()>)
            .await
    }
}