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 `certificates` management namespace (CONTRACT §27.1).
//!
//! End-entity X.509 certificates -- the ones issued to users, services and
//! IoT devices.

#![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 `certificates` namespace handle.
///
/// End-entity X.509 certificates -- the ones issued to users, services and
/// IoT devices.
///
/// 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 Certificates<'c> {
    pub(crate) client: &'c AxiamClient,
    pub(crate) scope: Scope,
}

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

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

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

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

    /// `POST /api/v1/certificates`
    /// **Returns secret material, once.** `private_key_pem` is returned by this
    /// call and by no other; no later `get` will return it again. Discarding the
    /// result destroys the credential (§27.5 rule 3).
    /// 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 generate(
        &self,
        body: &models::CreateCertificateRequest,
    ) -> Result<models::GeneratedCertificate, AxiamError> {
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "certificates.generate",
            verb: Verb::Post,
            path_template: "/api/v1/certificates",
            path: "/api/v1/certificates".to_string(),
            query: &query,
        };
        let wire: models::GeneratedCertificateWire =
            self.client.management_send(call, Some(body)).await?;
        Ok(models::GeneratedCertificate::from(wire))
    }

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

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

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