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 `users` management namespace (CONTRACT §27.1).
//!
//! Users within the client's tenant, and the administrative side of their
//! second factor and lockout state.

#![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 `users` namespace handle.
///
/// Users within the client's tenant, and the administrative side of their
/// second factor and lockout state.
///
/// 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 Users<'c> {
    pub(crate) client: &'c AxiamClient,
    pub(crate) scope: Scope,
}

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

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

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

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

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

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

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

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

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

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

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

    /// `POST /api/v1/users/{user_id}/unlock`
    /// 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 unlock(&self, user_id: Uuid) -> Result<models::UserResponse, AxiamError> {
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "users.unlock",
            verb: Verb::Post,
            path_template: "/api/v1/users/{user_id}/unlock",
            path: format!("/api/v1/users/{user_id}/unlock"),
            query: &query,
        };
        self.client
            .management_send::<_, models::UserResponse>(call, None::<&()>)
            .await
    }

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

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