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 `ca_certificates` management namespace (CONTRACT §27.1).
//!
//! Organization CAs and the per-tenant signing CAs chained beneath them.

#![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 `ca_certificates` namespace handle.
///
/// Organization CAs and the per-tenant signing CAs chained beneath them.
///
/// 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 CaCertificates<'c> {
    pub(crate) client: &'c AxiamClient,
    pub(crate) scope: Scope,
}

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

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

    /// Address a different organization than the client's own.
    ///
    /// §27.4 rule 3: the client's `org_id` is the default, and a platform-admin
    /// token legitimately overrides it.
    #[must_use]
    pub fn in_org(mut self, org_id: Uuid) -> Self {
        self.scope.org_id = Some(org_id);
        self
    }

    /// `GET /api/v1/organizations/{org_id}/ca-certificates`
    pub async fn list(&self, page: PageRequest) -> Result<Page<models::CaCertificate>, AxiamError> {
        let org_id = self.scope.org(self.client, "ca_certificates.list")?;
        let query = page.query();
        let call = Call {
            operation: "ca_certificates.list",
            verb: Verb::Get,
            path_template: "/api/v1/organizations/{org_id}/ca-certificates",
            path: format!("/api/v1/organizations/{org_id}/ca-certificates"),
            query: &query,
        };
        self.client
            .management_send::<_, Page<models::CaCertificate>>(call, None::<&()>)
            .await
    }

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

    /// `POST /api/v1/organizations/{org_id}/ca-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::CreateCaCertificateRequest,
    ) -> Result<models::GeneratedCaCertificate, AxiamError> {
        let org_id = self.scope.org(self.client, "ca_certificates.generate")?;
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "ca_certificates.generate",
            verb: Verb::Post,
            path_template: "/api/v1/organizations/{org_id}/ca-certificates",
            path: format!("/api/v1/organizations/{org_id}/ca-certificates"),
            query: &query,
        };
        let wire: models::GeneratedCaCertificateWire =
            self.client.management_send(call, Some(body)).await?;
        Ok(models::GeneratedCaCertificate::from(wire))
    }

    /// `POST /api/v1/organizations/{org_id}/ca-certificates/import`
    /// 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 import_ca(
        &self,
        body: &models::ImportCaCertificateRequest,
    ) -> Result<models::CaCertificate, AxiamError> {
        let org_id = self.scope.org(self.client, "ca_certificates.import_ca")?;
        let body = models::ImportCaCertificateRequestWire::from(body);
        let body = &body;
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "ca_certificates.import_ca",
            verb: Verb::Post,
            path_template: "/api/v1/organizations/{org_id}/ca-certificates/import",
            path: format!("/api/v1/organizations/{org_id}/ca-certificates/import"),
            query: &query,
        };
        self.client
            .management_send::<_, models::CaCertificate>(call, Some(body))
            .await
    }

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

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

    /// `POST /api/v1/organizations/{org_id}/ca-certificates/{id}/migrate-custody`
    /// 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 migrate_custody(
        &self,
        id: Uuid,
    ) -> Result<models::MigrateCustodyResponse, AxiamError> {
        let org_id = self
            .scope
            .org(self.client, "ca_certificates.migrate_custody")?;
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "ca_certificates.migrate_custody",
            verb: Verb::Post,
            path_template: "/api/v1/organizations/{org_id}/ca-certificates/{id}/migrate-custody",
            path: format!("/api/v1/organizations/{org_id}/ca-certificates/{id}/migrate-custody"),
            query: &query,
        };
        self.client
            .management_send::<_, models::MigrateCustodyResponse>(call, None::<&()>)
            .await
    }

    /// `PUT /api/v1/organizations/{org_id}/ca-certificates/{id}/mtls-trust-
    /// anchor`
    /// **This is a replacement, not a patch** (§27.4 rule 5). Every field of the
    /// body is required, and what you do not carry over from a prior read is not
    /// preserved -- it is overwritten. Read first, change the field you mean,
    /// send the whole thing back.
    /// 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 set_mtls_trust_anchor(
        &self,
        id: Uuid,
        body: &models::SetMtlsTrustAnchor,
    ) -> Result<models::MtlsTrustAnchorResponse, AxiamError> {
        let org_id = self
            .scope
            .org(self.client, "ca_certificates.set_mtls_trust_anchor")?;
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "ca_certificates.set_mtls_trust_anchor",
            verb: Verb::Put,
            path_template: "/api/v1/organizations/{org_id}/ca-certificates/{id}/mtls-trust-anchor",
            path: format!("/api/v1/organizations/{org_id}/ca-certificates/{id}/mtls-trust-anchor"),
            query: &query,
        };
        self.client
            .management_send::<_, models::MtlsTrustAnchorResponse>(call, Some(body))
            .await
    }

    /// `GET /api/v1/organizations/{org_id}/tenants/{tenant_id}/signing-cas`
    pub async fn list_signing_cas(
        &self,
        tenant_id: Uuid,
        page: PageRequest,
    ) -> Result<Page<models::CaCertificate>, AxiamError> {
        let org_id = self
            .scope
            .org(self.client, "ca_certificates.list_signing_cas")?;
        let query = page.query();
        let call = Call {
            operation: "ca_certificates.list_signing_cas",
            verb: Verb::Get,
            path_template: "/api/v1/organizations/{org_id}/tenants/{tenant_id}/signing-cas",
            path: format!("/api/v1/organizations/{org_id}/tenants/{tenant_id}/signing-cas"),
            query: &query,
        };
        self.client
            .management_send::<_, Page<models::CaCertificate>>(call, None::<&()>)
            .await
    }

    /// Walk `ca_certificates.list_signing_cas` 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_signing_cas_all(
        &self,
        tenant_id: Uuid,
        start: PageRequest,
    ) -> Result<Vec<models::CaCertificate>, AxiamError> {
        collect_pages(start, |p| self.list_signing_cas(tenant_id, p)).await
    }

    /// `POST /api/v1/organizations/{org_id}/tenants/{tenant_id}/signing-cas`
    /// **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_signing_ca(
        &self,
        tenant_id: Uuid,
        body: &models::CreateIntermediateCaRequest,
    ) -> Result<models::GeneratedCaCertificate, AxiamError> {
        let org_id = self
            .scope
            .org(self.client, "ca_certificates.generate_signing_ca")?;
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "ca_certificates.generate_signing_ca",
            verb: Verb::Post,
            path_template: "/api/v1/organizations/{org_id}/tenants/{tenant_id}/signing-cas",
            path: format!("/api/v1/organizations/{org_id}/tenants/{tenant_id}/signing-cas"),
            query: &query,
        };
        let wire: models::GeneratedCaCertificateWire =
            self.client.management_send(call, Some(body)).await?;
        Ok(models::GeneratedCaCertificate::from(wire))
    }

    /// `POST /api/v1/organizations/{org_id}/tenants/{tenant_id}/signing-cas/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_signing_ca_csr(
        &self,
        tenant_id: Uuid,
        body: &models::SignIntermediateCsrRequest,
    ) -> Result<models::CaCertificate, AxiamError> {
        let org_id = self
            .scope
            .org(self.client, "ca_certificates.sign_signing_ca_csr")?;
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "ca_certificates.sign_signing_ca_csr",
            verb: Verb::Post,
            path_template: "/api/v1/organizations/{org_id}/tenants/{tenant_id}/signing-cas/sign-csr",
            path: format!(
                "/api/v1/organizations/{org_id}/tenants/{tenant_id}/signing-cas/sign-csr"
            ),
            query: &query,
        };
        self.client
            .management_send::<_, models::CaCertificate>(call, Some(body))
            .await
    }
}