foundation_deployment_docker 0.1.0

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

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

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

use super::shared::ApiResponse;

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

/// `EventActor` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct EventActor {
    /// Attributes property.
    #[serde(rename = "Attributes")]
    pub attributes: Option<serde_json::Value>,
    /// ID property.
    #[serde(rename = "ID")]
    pub id: Option<String>,
}

/// `EventMessage` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct EventMessage {
    /// Action property.
    #[serde(rename = "Action")]
    pub action: Option<String>,
    /// Actor property.
    #[serde(rename = "Actor")]
    pub actor: Option<EventActor>,
    /// Type property.
    #[serde(rename = "Type")]
    pub r#type: Option<String>,
    /// scope property.
    pub scope: Option<String>,
    /// time property.
    pub time: Option<i64>,
    /// timeNano property.
    #[serde(rename = "timeNano")]
    pub time_nano: Option<i64>,
}

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

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

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

// -----------------------------------------------------------------------------
// GET /events
// -----------------------------------------------------------------------------

/// GET /events.
///
/// Takes a `DynNetClient` and args, builds the request, optionally applies
/// modifications, then sends it via `send_async().await`.
///
/// # Arguments
///
/// * `client` - HTTP client for making the request
/// * `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 = system_events_request(client.clone(), &args, Some(|b: &mut PreparedRequestBuilder| {
///     b.header("X-Custom-Header", "value");
/// })).await?;
/// ```
pub async fn system_events_request<F>(
    client: DynNetClient,
    args: &SystemEventsArgs,
    base_url: &str,
    builder_mod: Option<F>,
) -> Result<ApiResponse<EventMessage>, super::shared::ApiError>
where
    F: FnOnce(&mut PreparedRequestBuilder),
{
    let path = format!("/events",
    );
    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("since", args.since.as_deref());
    builder = builder.query("until", args.until.as_deref());
    builder = builder.query("filters", args.filters.as_deref());

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

    let response = client.send_async(builder.build()).await
        .map_err(|e| super::shared::ApiError::RequestSendFailed(e.to_string()))?;

    let status: usize = response.get_status().into();
    let headers = response.get_headers_ref().clone();
    if status < 200 || status >= 300 {
        return Err(super::shared::ApiError::HttpStatus { code: status as u16, headers, body: None });
    }
    let body_bytes = foundation_netio::shared::client::body_reader::collect_bytes_from_send_safe(response.take_body());
    let parsed: EventMessage = serde_json::from_slice(&body_bytes).map_err(|e: serde_json::Error| super::shared::ApiError::ParseFailed(e.to_string()))?;
    Ok(ApiResponse { status: status as u16, headers, body: parsed })
}