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 `service_accounts` management namespace (CONTRACT §27.1).
//!
//! Machine identities, their secrets, and the certificate a device-bound one
//! authenticates with.

#![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 `service_accounts` namespace handle.
///
/// Machine identities, their secrets, and the certificate a device-bound one
/// authenticates with.
///
/// 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 ServiceAccounts<'c> {
    pub(crate) client: &'c AxiamClient,
    pub(crate) scope: Scope,
}

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

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

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

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

    /// `POST /api/v1/service-accounts`
    /// **Returns secret material, once.** `client_secret` 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 create(
        &self,
        body: &models::CreateServiceAccountRequest,
    ) -> Result<models::ServiceAccountCreatedResponse, AxiamError> {
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "service_accounts.create",
            verb: Verb::Post,
            path_template: "/api/v1/service-accounts",
            path: "/api/v1/service-accounts".to_string(),
            query: &query,
        };
        let wire: models::ServiceAccountCreatedResponseWire =
            self.client.management_send(call, Some(body)).await?;
        Ok(models::ServiceAccountCreatedResponse::from(wire))
    }

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

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

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

    /// `POST /api/v1/service-accounts/{sa_id}/rotate-secret`
    /// **Returns secret material, once.** `client_secret` 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 rotate_secret(
        &self,
        sa_id: Uuid,
    ) -> Result<models::RotateSecretResponse, AxiamError> {
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "service_accounts.rotate_secret",
            verb: Verb::Post,
            path_template: "/api/v1/service-accounts/{sa_id}/rotate-secret",
            path: format!("/api/v1/service-accounts/{sa_id}/rotate-secret"),
            query: &query,
        };
        let wire: models::RotateSecretResponseWire =
            self.client.management_send(call, None::<&()>).await?;
        Ok(models::RotateSecretResponse::from(wire))
    }

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

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

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