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 `oauth2_clients` management namespace (CONTRACT §27.1).
//!
//! Registered OAuth2/OIDC clients -- the registration half of what §12, §21
//! and §26 then speak to.

#![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 `oauth2_clients` namespace handle.
///
/// Registered OAuth2/OIDC clients -- the registration half of what §12, §21
/// and §26 then speak to.
///
/// 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 Oauth2Clients<'c> {
    pub(crate) client: &'c AxiamClient,
    pub(crate) scope: Scope,
}

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

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

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

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

    /// `POST /api/v1/oauth2-clients`
    /// **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::CreateOAuth2ClientRequest,
    ) -> Result<models::OAuth2ClientCreatedResponse, AxiamError> {
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "oauth2_clients.create",
            verb: Verb::Post,
            path_template: "/api/v1/oauth2-clients",
            path: "/api/v1/oauth2-clients".to_string(),
            query: &query,
        };
        let wire: models::OAuth2ClientCreatedResponseWire =
            self.client.management_send(call, Some(body)).await?;
        Ok(models::OAuth2ClientCreatedResponse::from(wire))
    }

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

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

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

    /// `POST /api/v1/oauth2-clients/registration-tokens`
    /// **Returns secret material, once.** `initial_access_token` 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_registration_token(
        &self,
        body: &models::CreateRegistrationTokenRequest,
    ) -> Result<models::CreateRegistrationTokenResponse, AxiamError> {
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "oauth2_clients.create_registration_token",
            verb: Verb::Post,
            path_template: "/api/v1/oauth2-clients/registration-tokens",
            path: "/api/v1/oauth2-clients/registration-tokens".to_string(),
            query: &query,
        };
        let wire: models::CreateRegistrationTokenResponseWire =
            self.client.management_send(call, Some(body)).await?;
        Ok(models::CreateRegistrationTokenResponse::from(wire))
    }

    /// `GET /api/v1/oauth2-clients/registration-tokens`
    pub async fn list_registration_tokens(
        &self,
    ) -> Result<Vec<models::RegistrationTokenResponse>, AxiamError> {
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "oauth2_clients.list_registration_tokens",
            verb: Verb::Get,
            path_template: "/api/v1/oauth2-clients/registration-tokens",
            path: "/api/v1/oauth2-clients/registration-tokens".to_string(),
            query: &query,
        };
        self.client
            .management_send::<_, Vec<models::RegistrationTokenResponse>>(call, None::<&()>)
            .await
    }
}