foundation_deployment_docker 0.1.3

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

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

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

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

/// `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;

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

/// `Service` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct Service {
    /// `CreatedAt` property.
    #[serde(rename = "CreatedAt")]
    pub created_at: Option<String>,
    /// `Endpoint` property.
    #[serde(rename = "Endpoint")]
    pub endpoint: Option<std::collections::HashMap<String, serde_json::Value>>,
    /// `ID` property.
    #[serde(rename = "ID")]
    pub id: Option<String>,
    /// `JobStatus` property.
    #[serde(rename = "JobStatus")]
    pub job_status: Option<std::collections::HashMap<String, serde_json::Value>>,
    /// `ServiceStatus` property.
    #[serde(rename = "ServiceStatus")]
    pub service_status: Option<std::collections::HashMap<String, serde_json::Value>>,
    /// `Spec` property.
    #[serde(rename = "Spec")]
    pub spec: Option<ServiceSpec>,
    /// `UpdateStatus` property.
    #[serde(rename = "UpdateStatus")]
    pub update_status: Option<std::collections::HashMap<String, serde_json::Value>>,
    /// `UpdatedAt` property.
    #[serde(rename = "UpdatedAt")]
    pub updated_at: Option<String>,
    /// `Version` property.
    #[serde(rename = "Version")]
    pub version: Option<ObjectVersion>,
}

/// `ServiceSpec` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct ServiceSpec {
    /// `EndpointSpec` property.
    #[serde(rename = "EndpointSpec")]
    pub endpoint_spec: Option<EndpointSpec>,
    /// `Labels` property.
    #[serde(rename = "Labels")]
    pub labels: Option<serde_json::Value>,
    /// `Mode` property.
    #[serde(rename = "Mode")]
    pub mode: Option<std::collections::HashMap<String, serde_json::Value>>,
    /// `Name` property.
    #[serde(rename = "Name")]
    pub name: Option<String>,
    /// `Networks` property.
    #[serde(rename = "Networks")]
    pub networks: Option<Vec<NetworkAttachmentConfig>>,
    /// `RollbackConfig` property.
    #[serde(rename = "RollbackConfig")]
    pub rollback_config: Option<std::collections::HashMap<String, serde_json::Value>>,
    /// `TaskTemplate` property.
    #[serde(rename = "TaskTemplate")]
    pub task_template: Option<TaskSpec>,
    /// `UpdateConfig` property.
    #[serde(rename = "UpdateConfig")]
    pub update_config: Option<std::collections::HashMap<String, serde_json::Value>>,
}

/// `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>,
}

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

/// Arguments for [`ServiceList_request`].
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct ServiceListArgs {
    /// Query parameter: `filters`.
    pub filters: Option<String>,
    /// Query parameter: `status`.
    pub status: Option<String>,
}

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

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

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

// -----------------------------------------------------------------------------
// GET /services
// -----------------------------------------------------------------------------

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

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

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

// -----------------------------------------------------------------------------
// GET /services/{id}
// -----------------------------------------------------------------------------

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

    builder = builder.query("insertDefaults", args.insert_defaults.as_deref());

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

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

// -----------------------------------------------------------------------------
// DELETE /services/{id}
// -----------------------------------------------------------------------------

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

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

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