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 `network` management namespace (CONTRACT §27.1).
//!
//! A tenant's network segments and the RADIUS reply profile each owns (RADIUS
//! Live profile): a segment is a node of the reserved /network subtree of the
//! resource tree (kind, VLAN, Filter-Id envelope, placement rank), and its
//! profile is the typed `axiam-radius-reply/1` record a decision renders.
//! Every write is conditional on the `version` the caller read and passes the
//! server's write gate. The tenant's Session-Timeout cap is one more row of
//! it (get_policy, replace_policy): lowering it is always allowed, raising it
//! is allowed and audited. The decision route FreeRADIUS calls is not in this
//! registry.

#![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 `network` namespace handle.
///
/// A tenant's network segments and the RADIUS reply profile each owns (RADIUS
/// Live profile): a segment is a node of the reserved /network subtree of the
/// resource tree (kind, VLAN, Filter-Id envelope, placement rank), and its
/// profile is the typed `axiam-radius-reply/1` record a decision renders.
/// Every write is conditional on the `version` the caller read and passes the
/// server's write gate. The tenant's Session-Timeout cap is one more row of
/// it (get_policy, replace_policy): lowering it is always allowed, raising it
/// is allowed and audited. The decision route FreeRADIUS calls is not in this
/// registry.
///
/// 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 Network<'c> {
    pub(crate) client: &'c AxiamClient,
    pub(crate) scope: Scope,
}

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

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

    /// `GET /api/v1/network/segments`
    pub async fn list_segments(
        &self,
        site: Option<&str>,
        page: PageRequest,
    ) -> Result<Page<models::NetworkSegmentResponse>, AxiamError> {
        let mut query = page.query();
        if let Some(v) = site {
            query.push(("site", v.to_string()));
        }
        let call = Call {
            operation: "network.list_segments",
            verb: Verb::Get,
            path_template: "/api/v1/network/segments",
            path: "/api/v1/network/segments".to_string(),
            query: &query,
        };
        self.client
            .management_send::<_, Page<models::NetworkSegmentResponse>>(call, None::<&()>)
            .await
    }

    /// Walk `network.list_segments` 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_segments_all(
        &self,
        site: Option<&str>,
        start: PageRequest,
    ) -> Result<Vec<models::NetworkSegmentResponse>, AxiamError> {
        collect_pages(start, |p| self.list_segments(site, p)).await
    }

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

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

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

    /// `DELETE /api/v1/network/segments/{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_segment(&self, id: Uuid, version: i64) -> Result<(), AxiamError> {
        let query: Vec<(&'static str, String)> = vec![("version", version.to_string())];
        let call = Call {
            operation: "network.delete_segment",
            verb: Verb::Delete,
            path_template: "/api/v1/network/segments/{id}",
            path: format!("/api/v1/network/segments/{id}"),
            query: &query,
        };
        self.client
            .management_send_no_content(call, None::<&()>)
            .await
    }

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

    /// Walk `network.list_profiles` 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_profiles_all(
        &self,
        start: PageRequest,
    ) -> Result<Vec<models::NetworkReplyProfile>, AxiamError> {
        collect_pages(start, |p| self.list_profiles(p)).await
    }

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

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

    /// `PUT /api/v1/network/profiles/{segment_id}`
    /// **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 replace_profile(
        &self,
        segment_id: Uuid,
        body: &models::ReplaceNetworkReplyProfileRequest,
    ) -> Result<models::NetworkReplyProfile, AxiamError> {
        let query: Vec<(&'static str, String)> = Vec::new();
        let call = Call {
            operation: "network.replace_profile",
            verb: Verb::Put,
            path_template: "/api/v1/network/profiles/{segment_id}",
            path: format!("/api/v1/network/profiles/{segment_id}"),
            query: &query,
        };
        self.client
            .management_send::<_, models::NetworkReplyProfile>(call, Some(body))
            .await
    }

    /// `DELETE /api/v1/network/profiles/{segment_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_profile(&self, segment_id: Uuid, version: i64) -> Result<(), AxiamError> {
        let query: Vec<(&'static str, String)> = vec![("version", version.to_string())];
        let call = Call {
            operation: "network.delete_profile",
            verb: Verb::Delete,
            path_template: "/api/v1/network/profiles/{segment_id}",
            path: format!("/api/v1/network/profiles/{segment_id}"),
            query: &query,
        };
        self.client
            .management_send_no_content(call, None::<&()>)
            .await
    }

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

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