foundation_deployment_docker 0.1.3

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

#![cfg(feature = "docker_tasks")]
#![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
// =============================================================================

/// `ContainerStatus` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct ContainerStatus {
    /// `ContainerID` property.
    #[serde(rename = "ContainerID")]
    pub container_id: Option<String>,
    /// `ExitCode` property.
    #[serde(rename = "ExitCode")]
    pub exit_code: Option<i64>,
    /// `PID` property.
    #[serde(rename = "PID")]
    pub pid: Option<i64>,
}

/// `EndpointPortConfig` type.
///
/// Same shape as `super::shared::EndpointPortConfigShape`.
pub type EndpointPortConfig = super::shared::EndpointPortConfigShape;

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

/// `HealthConfig` type.
///
/// Same shape as `super::shared::HealthConfigShape`.
pub type HealthConfig = super::shared::HealthConfigShape;

/// `Limit` type.
///
/// Same shape as `super::shared::MemoryBytesNanoCpUsPidsObject`.
pub type Limit = super::shared::MemoryBytesNanoCpUsPidsObject;

/// `Mount` type.
///
/// Same shape as `super::shared::MountShape`.
pub type Mount = super::shared::MountShape;

/// `NetworkAttachmentConfig` type.
///
/// Same shape as `super::shared::AliasesDriverOptsTargetObject`.
pub type NetworkAttachmentConfig = super::shared::AliasesDriverOptsTargetObject;

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

/// `PluginPrivilege` type.
///
/// Same shape as `super::shared::DescriptionNameValueObject`.
pub type PluginPrivilege = super::shared::DescriptionNameValueObject;

/// `PortStatus` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct PortStatus {
    /// `Ports` property.
    #[serde(rename = "Ports")]
    pub ports: Option<Vec<EndpointPortConfig>>,
}

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

/// `Task` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct Task {
    /// `AssignedGenericResources` property.
    #[serde(rename = "AssignedGenericResources")]
    pub assigned_generic_resources:
        Option<Vec<std::collections::HashMap<String, serde_json::Value>>>,
    /// `CreatedAt` property.
    #[serde(rename = "CreatedAt")]
    pub created_at: Option<String>,
    /// `DesiredState` property.
    #[serde(rename = "DesiredState")]
    pub desired_state: Option<String>,
    /// `ID` property.
    #[serde(rename = "ID")]
    pub id: Option<String>,
    /// `JobIteration` property.
    #[serde(rename = "JobIteration")]
    pub job_iteration: Option<ObjectVersion>,
    /// `Labels` property.
    #[serde(rename = "Labels")]
    pub labels: Option<serde_json::Value>,
    /// `Name` property.
    #[serde(rename = "Name")]
    pub name: Option<String>,
    /// `NodeID` property.
    #[serde(rename = "NodeID")]
    pub node_id: Option<String>,
    /// `ServiceID` property.
    #[serde(rename = "ServiceID")]
    pub service_id: Option<String>,
    /// `Slot` property.
    #[serde(rename = "Slot")]
    pub slot: Option<i64>,
    /// `Spec` property.
    #[serde(rename = "Spec")]
    pub spec: Option<TaskSpec>,
    /// `Status` property.
    #[serde(rename = "Status")]
    pub status: Option<TaskStatus>,
    /// `UpdatedAt` property.
    #[serde(rename = "UpdatedAt")]
    pub updated_at: Option<String>,
    /// `Version` property.
    #[serde(rename = "Version")]
    pub version: Option<ObjectVersion>,
}

/// `TaskSpec` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct TaskSpec {
    /// `ContainerSpec` property.
    #[serde(rename = "ContainerSpec")]
    pub container_spec: Option<std::collections::HashMap<String, serde_json::Value>>,
    /// `ForceUpdate` property.
    #[serde(rename = "ForceUpdate")]
    pub force_update: Option<i64>,
    /// `LogDriver` property.
    #[serde(rename = "LogDriver")]
    pub log_driver: Option<std::collections::HashMap<String, serde_json::Value>>,
    /// `NetworkAttachmentSpec` property.
    #[serde(rename = "NetworkAttachmentSpec")]
    pub network_attachment_spec: Option<std::collections::HashMap<String, serde_json::Value>>,
    /// `Networks` property.
    #[serde(rename = "Networks")]
    pub networks: Option<Vec<NetworkAttachmentConfig>>,
    /// `Placement` property.
    #[serde(rename = "Placement")]
    pub placement: Option<std::collections::HashMap<String, serde_json::Value>>,
    /// `PluginSpec` property.
    #[serde(rename = "PluginSpec")]
    pub plugin_spec: Option<std::collections::HashMap<String, serde_json::Value>>,
    /// `Resources` property.
    #[serde(rename = "Resources")]
    pub resources: Option<std::collections::HashMap<String, serde_json::Value>>,
    /// `RestartPolicy` property.
    #[serde(rename = "RestartPolicy")]
    pub restart_policy: Option<std::collections::HashMap<String, serde_json::Value>>,
    /// `Runtime` property.
    #[serde(rename = "Runtime")]
    pub runtime: Option<String>,
}

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

/// `TaskStatus` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct TaskStatus {
    /// `ContainerStatus` property.
    #[serde(rename = "ContainerStatus")]
    pub container_status: Option<ContainerStatus>,
    /// `Err` property.
    #[serde(rename = "Err")]
    pub err: Option<String>,
    /// `Message` property.
    #[serde(rename = "Message")]
    pub message: Option<String>,
    /// `PortStatus` property.
    #[serde(rename = "PortStatus")]
    pub port_status: Option<PortStatus>,
    /// `State` property.
    #[serde(rename = "State")]
    pub state: Option<String>,
    /// `Timestamp` property.
    #[serde(rename = "Timestamp")]
    pub timestamp: Option<String>,
}

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

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

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

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

// -----------------------------------------------------------------------------
// GET /tasks
// -----------------------------------------------------------------------------

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

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