foundation_deployment_docker 0.1.3

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

#![cfg(feature = "docker_nodes")]
#![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};

// Import shared types used by this module
use super::shared::ObjectVersion;

use super::shared::ApiResponse;

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

/// `EngineDescription` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct EngineDescription {
    /// `EngineVersion` property.
    #[serde(rename = "EngineVersion")]
    pub engine_version: Option<String>,
    /// `Labels` property.
    #[serde(rename = "Labels")]
    pub labels: Option<serde_json::Value>,
    /// `Plugins` property.
    #[serde(rename = "Plugins")]
    pub plugins: Option<Vec<std::collections::HashMap<String, serde_json::Value>>>,
}

/// `GenericResources` type.
pub type GenericResources = Vec<std::collections::HashMap<String, serde_json::Value>>;

/// `ManagerStatus` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct ManagerStatus {
    /// `Addr` property.
    #[serde(rename = "Addr")]
    pub addr: Option<String>,
    /// `Leader` property.
    #[serde(rename = "Leader")]
    pub leader: Option<bool>,
    /// `Reachability` property.
    #[serde(rename = "Reachability")]
    pub reachability: Option<String>,
}

/// `Node` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct Node {
    /// `CreatedAt` property.
    #[serde(rename = "CreatedAt")]
    pub created_at: Option<String>,
    /// `Description` property.
    #[serde(rename = "Description")]
    pub description: Option<NodeDescription>,
    /// `ID` property.
    #[serde(rename = "ID")]
    pub id: Option<String>,
    /// `ManagerStatus` property.
    #[serde(rename = "ManagerStatus")]
    pub manager_status: Option<ManagerStatus>,
    /// `Spec` property.
    #[serde(rename = "Spec")]
    pub spec: Option<NodeSpec>,
    /// `Status` property.
    #[serde(rename = "Status")]
    pub status: Option<NodeStatus>,
    /// `UpdatedAt` property.
    #[serde(rename = "UpdatedAt")]
    pub updated_at: Option<String>,
    /// `Version` property.
    #[serde(rename = "Version")]
    pub version: Option<ObjectVersion>,
}

/// `NodeDescription` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct NodeDescription {
    /// `Engine` property.
    #[serde(rename = "Engine")]
    pub engine: Option<EngineDescription>,
    /// `Hostname` property.
    #[serde(rename = "Hostname")]
    pub hostname: Option<String>,
    /// `Platform` property.
    #[serde(rename = "Platform")]
    pub platform: Option<Platform>,
    /// `Resources` property.
    #[serde(rename = "Resources")]
    pub resources: Option<ResourceObject>,
    /// `TLSInfo` property.
    #[serde(rename = "TLSInfo")]
    pub tls_info: Option<TLSInfo>,
}

/// `NodeSpec` type.
///
/// Same shape as `super::shared::NodeSpecShape`.
pub type NodeSpec = super::shared::NodeSpecShape;

/// `NodeState` type.
pub type NodeState = String;

/// `NodeStatus` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct NodeStatus {
    /// `Addr` property.
    #[serde(rename = "Addr")]
    pub addr: Option<String>,
    /// `Message` property.
    #[serde(rename = "Message")]
    pub message: Option<String>,
    /// `State` property.
    #[serde(rename = "State")]
    pub state: Option<String>,
}

/// `Platform` type.
///
/// Same shape as `super::shared::ArchitectureOsObject`.
pub type Platform = super::shared::ArchitectureOsObject;

/// `Reachability` type.
pub type Reachability = String;

/// `ResourceObject` type.
///
/// Same shape as `super::shared::GenericResourcesMemoryBytesNanoCpUsObject`.
pub type ResourceObject = super::shared::GenericResourcesMemoryBytesNanoCpUsObject;

/// `TLSInfo` type.
///
/// Same shape as `super::shared::CertIssuerPublicKeyCertIssuerSubjectTrustRootObject`.
pub type TLSInfo = super::shared::CertIssuerPublicKeyCertIssuerSubjectTrustRootObject;

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

/// Arguments for [`NodeList_request`].
///
/// Same shape as `super::shared::FiltersArgs`.
pub type NodeListArgs = super::shared::FiltersArgs;

/// Arguments for [`NodeInspect_request`].
///
/// Same shape as `super::shared::IdArgs`.
pub type NodeInspectArgs = super::shared::IdArgs;

/// Arguments for [`NodeDelete_request`].
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct NodeDeleteArgs {
    /// Path parameter: `id`.
    pub id: String,
    /// Query parameter: `force`.
    pub force: Option<String>,
}

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

// -----------------------------------------------------------------------------
// GET /nodes
// -----------------------------------------------------------------------------

/// GET /nodes.
///
/// 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 = node_list_request(client.clone(), &args, Some(|b: &mut PreparedRequestBuilder| {
///     b.header("X-Custom-Header", "value");
/// })).await?;
/// ```
pub async fn node_list_request<F>(
    client: impl Into<super::shared::ApiClient>,
    args: &NodeListArgs,
    base_url: &str,
    builder_mod: Option<F>,
) -> Result<ApiResponse<serde_json::Value>, super::shared::ApiError>
where
    F: FnOnce(&mut PreparedRequestBuilder),
{
    let path = format!("/nodes",);
    let endpoint_url = format!("{}{}", base_url, path);

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

    builder = builder.query("filters", args.filters.as_deref());

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

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

// -----------------------------------------------------------------------------
// GET /nodes/{id}
// -----------------------------------------------------------------------------

/// GET /nodes/{id}.
///
/// 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 = node_inspect_request(client.clone(), &args, Some(|b: &mut PreparedRequestBuilder| {
///     b.header("X-Custom-Header", "value");
/// })).await?;
/// ```
pub async fn node_inspect_request<F>(
    client: impl Into<super::shared::ApiClient>,
    args: &NodeInspectArgs,
    base_url: &str,
    builder_mod: Option<F>,
) -> Result<ApiResponse<Node>, super::shared::ApiError>
where
    F: FnOnce(&mut PreparedRequestBuilder),
{
    let path = format!("/nodes/{}", args.id,);
    let endpoint_url = format!("{}{}", base_url, path);

    let mut builder = PreparedRequestBuilder::get(&endpoint_url)
        .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
}

// -----------------------------------------------------------------------------
// DELETE /nodes/{id}
// -----------------------------------------------------------------------------

/// DELETE /nodes/{id}.
///
/// 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 = node_delete_request(client.clone(), &args, Some(|b: &mut PreparedRequestBuilder| {
///     b.header("X-Custom-Header", "value");
/// })).await?;
/// ```
pub async fn node_delete_request<F>(
    client: impl Into<super::shared::ApiClient>,
    args: &NodeDeleteArgs,
    base_url: &str,
    builder_mod: Option<F>,
) -> Result<ApiResponse<()>, super::shared::ApiError>
where
    F: FnOnce(&mut PreparedRequestBuilder),
{
    let path = format!("/nodes/{}", args.id,);
    let endpoint_url = format!("{}{}", base_url, path);

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

    builder = builder.query("force", args.force.as_deref());

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

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