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 `federation` management namespace (CONTRACT §27.1).
//!
//! Upstream IdP configuration and the per-user links it produces.

#![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 `federation` namespace handle.
///
/// Upstream IdP configuration and the per-user links it produces.
///
/// 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 Federation<'c> {
    pub(crate) client: &'c AxiamClient,
    pub(crate) scope: Scope,
}

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

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

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

    /// Walk `federation.list_configs` 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_configs_all(
        &self,
        start: PageRequest,
    ) -> Result<Vec<models::FederationConfigResponse>, AxiamError> {
        collect_pages(start, |p| self.list_configs(p)).await
    }

    /// `POST /api/v1/federation-configs`
    /// 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_config(
        &self,
        body: &models::CreateFederationConfigRequest,
    ) -> Result<models::FederationConfigResponse, AxiamError> {
        let body = models::CreateFederationConfigRequestWire::from(body);
        let body = &body;
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "federation.create_config",
            verb: Verb::Post,
            path_template: "/api/v1/federation-configs",
            path: "/api/v1/federation-configs".to_string(),
            query: &query,
        };
        self.client
            .management_send::<_, models::FederationConfigResponse>(call, Some(body))
            .await
    }

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

    /// `PUT /api/v1/federation-configs/{id}`
    ///
    /// A sparse body (§27.15 note 8): a member left `None` is not sent and stays
    /// as stored. `metadata_url`, `idp_signing_cert_pem`,
    /// `idp_metadata_signing_cert_pem`, `provider_slug`, the three OAuth2
    /// endpoints, `apple_team_id`, `apple_key_id` and `button_icon` set to
    /// `Some(None)` are sent as `null` and **clear** the value -- still held to
    /// the relational rules: an `OAuth2` configuration's three endpoints cannot
    /// be cleared (`400`), and the two Apple ids clear only together. The other
    /// members cannot be cleared. `allow_sha1_signatures` and
    /// `idp_metadata_signing_cert_pem` apply to SAML configurations only (`400`
    /// otherwise).
    /// 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_config(
        &self,
        id: Uuid,
        body: &models::UpdateFederationConfigRequest,
    ) -> Result<models::FederationConfigResponse, AxiamError> {
        let body = models::UpdateFederationConfigRequestWire::from(body);
        let body = &body;
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "federation.update_config",
            verb: Verb::Put,
            path_template: "/api/v1/federation-configs/{id}",
            path: format!("/api/v1/federation-configs/{id}"),
            query: &query,
        };
        self.client
            .management_send::<_, models::FederationConfigResponse>(call, Some(body))
            .await
    }

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

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

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

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

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