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 `audit` management namespace (CONTRACT §27.1).
//!
//! Append-only audit log, read-only by construction.

#![allow(clippy::too_many_arguments)]

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 `audit` namespace handle.
///
/// Append-only audit log, read-only by construction.
///
/// 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 Audit<'c> {
    pub(crate) client: &'c AxiamClient,
    pub(crate) scope: Scope,
}

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

/// Optional filters for `audit.list`.
///
/// Every field is `None` by default; construct with `..Default::default()`
/// and set only what you mean to filter on.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct AuditListFilter {
    /// Filter on `actor_id`.
    pub actor_id: Option<String>,
    /// Filter on `action`.
    pub action: Option<String>,
    /// Filter on `outcome`.
    pub outcome: Option<String>,
    /// Filter on `resource_id`.
    pub resource_id: Option<String>,
    /// Filter on `from`.
    pub from: Option<String>,
    /// Filter on `to`.
    pub to: Option<String>,
}

/// Optional filters for `audit.list_system`.
///
/// Every field is `None` by default; construct with `..Default::default()`
/// and set only what you mean to filter on.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct AuditListSystemFilter {
    /// Filter on `actor_id`.
    pub actor_id: Option<String>,
    /// Filter on `action`.
    pub action: Option<String>,
    /// Filter on `outcome`.
    pub outcome: Option<String>,
    /// Filter on `resource_id`.
    pub resource_id: Option<String>,
    /// Filter on `from`.
    pub from: Option<String>,
    /// Filter on `to`.
    pub to: Option<String>,
}

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

    /// `GET /api/v1/audit-logs`
    pub async fn list(
        &self,
        filter: &AuditListFilter,
        page: PageRequest,
    ) -> Result<Page<models::AuditLogEntry>, AxiamError> {
        let mut query = page.query();
        if let Some(v) = filter.actor_id.as_deref() {
            query.push(("actor_id", v.to_string()));
        }
        if let Some(v) = filter.action.as_deref() {
            query.push(("action", v.to_string()));
        }
        if let Some(v) = filter.outcome.as_deref() {
            query.push(("outcome", v.to_string()));
        }
        if let Some(v) = filter.resource_id.as_deref() {
            query.push(("resource_id", v.to_string()));
        }
        if let Some(v) = filter.from.as_deref() {
            query.push(("from", v.to_string()));
        }
        if let Some(v) = filter.to.as_deref() {
            query.push(("to", v.to_string()));
        }
        let call = Call {
            operation: "audit.list",
            verb: Verb::Get,
            path_template: "/api/v1/audit-logs",
            path: "/api/v1/audit-logs".to_string(),
            query: &query,
        };
        self.client
            .management_send::<_, Page<models::AuditLogEntry>>(call, None::<&()>)
            .await
    }

    /// Walk `audit.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,
        filter: &AuditListFilter,
        start: PageRequest,
    ) -> Result<Vec<models::AuditLogEntry>, AxiamError> {
        collect_pages(start, |p| self.list(filter, p)).await
    }

    /// `GET /api/v1/audit-logs/system`
    pub async fn list_system(
        &self,
        filter: &AuditListSystemFilter,
        page: PageRequest,
    ) -> Result<Page<models::AuditLogEntry>, AxiamError> {
        let mut query = page.query();
        if let Some(v) = filter.actor_id.as_deref() {
            query.push(("actor_id", v.to_string()));
        }
        if let Some(v) = filter.action.as_deref() {
            query.push(("action", v.to_string()));
        }
        if let Some(v) = filter.outcome.as_deref() {
            query.push(("outcome", v.to_string()));
        }
        if let Some(v) = filter.resource_id.as_deref() {
            query.push(("resource_id", v.to_string()));
        }
        if let Some(v) = filter.from.as_deref() {
            query.push(("from", v.to_string()));
        }
        if let Some(v) = filter.to.as_deref() {
            query.push(("to", v.to_string()));
        }
        let call = Call {
            operation: "audit.list_system",
            verb: Verb::Get,
            path_template: "/api/v1/audit-logs/system",
            path: "/api/v1/audit-logs/system".to_string(),
            query: &query,
        };
        self.client
            .management_send::<_, Page<models::AuditLogEntry>>(call, None::<&()>)
            .await
    }

    /// Walk `audit.list_system` 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_system_all(
        &self,
        filter: &AuditListSystemFilter,
        start: PageRequest,
    ) -> Result<Vec<models::AuditLogEntry>, AxiamError> {
        collect_pages(start, |p| self.list_system(filter, p)).await
    }
}