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 `settings` management namespace (CONTRACT §27.1).
//!
//! Effective settings, and the organization/tenant layers they resolve from.

#![allow(clippy::too_many_arguments)]

use uuid::Uuid;

use crate::AxiamError;
use crate::client::AxiamClient;
use crate::management::models;
use crate::management::request::{Call, Verb};
use crate::management::scope::Scope;

/// The `settings` namespace handle.
///
/// Effective settings, and the organization/tenant layers they resolve from.
///
/// 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 Settings<'c> {
    pub(crate) client: &'c AxiamClient,
    pub(crate) scope: Scope,
}

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

impl<'c> Settings<'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
    }

    /// Address a different tenant than the client's own.
    ///
    /// §27.4 rule 3: the client's `tenant_id` is the default.
    #[must_use]
    pub fn for_tenant(mut self, tenant_id: Uuid) -> Self {
        self.scope.tenant_id = Some(tenant_id);
        self
    }

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

    /// `PUT /api/v1/organizations/{org_id}/settings`
    /// **This is a replacement, not a patch** (§27.4 rule 5). Its required fields
    /// must all be given, and what you do not carry over from a prior read is not
    /// preserved: an optional member left `None` is omitted, and the server
    /// applies that member's default rather than keeping the stored value --
    /// unless a note below says otherwise. 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_org(
        &self,
        body: &models::SetOrgSettings,
    ) -> Result<models::SecuritySettings, AxiamError> {
        let org_id = self.scope.org(self.client, "settings.set_org")?;
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "settings.set_org",
            verb: Verb::Put,
            path_template: "/api/v1/organizations/{org_id}/settings",
            path: format!("/api/v1/organizations/{org_id}/settings"),
            query: &query,
        };
        self.client
            .management_send::<_, models::SecuritySettings>(call, Some(body))
            .await
    }

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

    /// `PUT /api/v1/settings`
    /// 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_effective(
        &self,
        body: &models::TenantSettingsOverride,
    ) -> Result<models::SecuritySettings, AxiamError> {
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "settings.set_effective",
            verb: Verb::Put,
            path_template: "/api/v1/settings",
            path: "/api/v1/settings".to_string(),
            query: &query,
        };
        self.client
            .management_send::<_, models::SecuritySettings>(call, Some(body))
            .await
    }

    /// `GET /api/v1/tenants/{tenant_id}/settings`
    pub async fn get_tenant_override(&self) -> Result<models::TenantSettingsOverride, AxiamError> {
        let tenant_id = self
            .scope
            .tenant(self.client, "settings.get_tenant_override")?;
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "settings.get_tenant_override",
            verb: Verb::Get,
            path_template: "/api/v1/tenants/{tenant_id}/settings",
            path: format!("/api/v1/tenants/{tenant_id}/settings"),
            query: &query,
        };
        self.client
            .management_send::<_, models::TenantSettingsOverride>(call, None::<&()>)
            .await
    }

    /// `PUT /api/v1/tenants/{tenant_id}/settings`
    /// 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_tenant_override(
        &self,
        body: &models::TenantSettingsOverride,
    ) -> Result<models::TenantSettingsOverride, AxiamError> {
        let tenant_id = self
            .scope
            .tenant(self.client, "settings.set_tenant_override")?;
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "settings.set_tenant_override",
            verb: Verb::Put,
            path_template: "/api/v1/tenants/{tenant_id}/settings",
            path: format!("/api/v1/tenants/{tenant_id}/settings"),
            query: &query,
        };
        self.client
            .management_send::<_, models::TenantSettingsOverride>(call, Some(body))
            .await
    }

    /// `DELETE /api/v1/tenants/{tenant_id}/settings`
    /// 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_tenant_override(&self) -> Result<(), AxiamError> {
        let tenant_id = self
            .scope
            .tenant(self.client, "settings.delete_tenant_override")?;
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "settings.delete_tenant_override",
            verb: Verb::Delete,
            path_template: "/api/v1/tenants/{tenant_id}/settings",
            path: format!("/api/v1/tenants/{tenant_id}/settings"),
            query: &query,
        };
        self.client
            .management_send_no_content(call, None::<&()>)
            .await
    }
}