foundation_deployment_docker 0.1.3

Docker Engine API v1.53 client over DynNetClient + valtron (bollard-free)
//! Auto-generated API module for docker init.
//!
//! Generated by `cargo run --bin ewe_platform gen_api`.
//! DO NOT EDIT MANUALLY.
//!
//! Feature flag: `docker_init `

#![cfg(feature = "docker_init")]
#![allow(clippy::too_many_arguments, clippy::type_complexity)]
#![allow(
    clippy::missing_errors_doc,
    clippy::doc_markdown,
    clippy::useless_format
)]
#![allow(unused_imports)]

use foundation_macros::JsonHash;
use foundation_netio::shared::client::http_client::HttpClient;
use foundation_netio::{DynNetClient, PreparedRequestBuilder};
use serde::{Deserialize, Serialize};

use super::shared::ApiResponse;

// =============================================================================
// TYPE DECLARATIONS
// =============================================================================

/// `SwarmInitRequest` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct SwarmInitRequest {
    /// `AdvertiseAddr` property.
    #[serde(rename = "AdvertiseAddr")]
    pub advertise_addr: Option<String>,
    /// `DataPathAddr` property.
    #[serde(rename = "DataPathAddr")]
    pub data_path_addr: Option<String>,
    /// `DataPathPort` property.
    #[serde(rename = "DataPathPort")]
    pub data_path_port: Option<i64>,
    /// `DefaultAddrPool` property.
    #[serde(rename = "DefaultAddrPool")]
    pub default_addr_pool: Option<Vec<String>>,
    /// `ForceNewCluster` property.
    #[serde(rename = "ForceNewCluster")]
    pub force_new_cluster: Option<bool>,
    /// `ListenAddr` property.
    #[serde(rename = "ListenAddr")]
    pub listen_addr: Option<String>,
    /// `Spec` property.
    #[serde(rename = "Spec")]
    pub spec: Option<SwarmSpec>,
    /// `SubnetSize` property.
    #[serde(rename = "SubnetSize")]
    pub subnet_size: Option<i64>,
}

/// `SwarmSpec` type.
///
/// Same shape as `super::shared::SwarmSpecShape`.
pub type SwarmSpec = super::shared::SwarmSpecShape;

// =============================================================================
// ARGS TYPES (per-endpoint)
// =============================================================================

/// Arguments for [`SwarmInit_request`].
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct SwarmInitArgs {
    /// Request body.
    pub body: SwarmInitRequest,
}

// =============================================================================
// CLIENT FUNCTIONS (per-endpoint)
// =============================================================================

// -----------------------------------------------------------------------------
// POST /swarm/init
// -----------------------------------------------------------------------------

/// POST /swarm/init.
///
/// Takes a client and args, builds the request, optionally applies
/// modifications, then sends it via `send_async().await`.
///
/// # Arguments
///
/// * `client` - HTTP client for making the request: a `DynNetClient`, or an `ApiClient` carrying the `BodyLimits` the response is read under
/// * `args` - Request arguments (path params, query params, body)
/// * `builder_mod` - Optional closure to modify the request builder (e.g., add headers)
///
/// # Example
///
/// ```ignore
/// let response = swarm_init_request(client.clone(), &args, Some(|b: &mut PreparedRequestBuilder| {
///     b.header("X-Custom-Header", "value");
/// })).await?;
/// ```
pub async fn swarm_init_request<F>(
    client: impl Into<super::shared::ApiClient>,
    args: &SwarmInitArgs,
    base_url: &str,
    builder_mod: Option<F>,
) -> Result<ApiResponse<serde_json::Value>, super::shared::ApiError>
where
    F: FnOnce(&mut PreparedRequestBuilder),
{
    let path = format!("/swarm/init",);
    let endpoint_url = format!("{}{}", base_url, path);

    let mut builder = PreparedRequestBuilder::post(&endpoint_url)
        .map_err(|e| super::shared::ApiError::RequestBuildFailed(e.to_string()))?;

    builder = builder
        .body_json(&args.body)
        .map_err(|e| super::shared::ApiError::RequestBuildFailed(e.to_string()))?;

    if let Some(f) = builder_mod {
        f(&mut builder);
    }

    super::shared::send_json(client.into(), builder.build()).await
}