foundation_deployment_docker 0.1.2

Docker Engine API v1.53 client over DynNetClient + valtron (bollard-free)
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
//! 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_netio::{DynNetClient, PreparedRequestBuilder};
use foundation_netio::shared::client::http_client::HttpClient;
use serde::{Deserialize, Serialize};
use foundation_macros::JsonHash;

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

use super::shared::ApiResponse;

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

/// `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<TaskState>,
    /// Timestamp property.
    #[serde(rename = "Timestamp")]
    pub timestamp: Option<String>,
}

/// `Mount` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct Mount {
    /// BindOptions property.
    #[serde(rename = "BindOptions")]
    pub bind_options: Option<std::collections::HashMap<String, serde_json::Value>>,
    /// Consistency property.
    #[serde(rename = "Consistency")]
    pub consistency: Option<String>,
    /// ImageOptions property.
    #[serde(rename = "ImageOptions")]
    pub image_options: Option<std::collections::HashMap<String, serde_json::Value>>,
    /// ReadOnly property.
    #[serde(rename = "ReadOnly")]
    pub read_only: Option<bool>,
    /// Source property.
    #[serde(rename = "Source")]
    pub source: Option<String>,
    /// Target property.
    #[serde(rename = "Target")]
    pub target: Option<String>,
    /// TmpfsOptions property.
    #[serde(rename = "TmpfsOptions")]
    pub tmpfs_options: Option<std::collections::HashMap<String, serde_json::Value>>,
    /// Type property.
    #[serde(rename = "Type")]
    pub r#type: Option<serde_json::Value>,
    /// VolumeOptions property.
    #[serde(rename = "VolumeOptions")]
    pub volume_options: Option<std::collections::HashMap<String, serde_json::Value>>,
}

/// `EndpointPortConfig` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct EndpointPortConfig {
    /// Name property.
    #[serde(rename = "Name")]
    pub name: Option<String>,
    /// Protocol property.
    #[serde(rename = "Protocol")]
    pub protocol: Option<String>,
    /// PublishMode property.
    #[serde(rename = "PublishMode")]
    pub publish_mode: Option<String>,
    /// PublishedPort property.
    #[serde(rename = "PublishedPort")]
    pub published_port: Option<i64>,
    /// TargetPort property.
    #[serde(rename = "TargetPort")]
    pub target_port: Option<i64>,
}

/// `ResourceObject` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct ResourceObject {
    /// GenericResources property.
    #[serde(rename = "GenericResources")]
    pub generic_resources: Option<Vec<std::collections::HashMap<String, serde_json::Value>>>,
    /// MemoryBytes property.
    #[serde(rename = "MemoryBytes")]
    pub memory_bytes: Option<i64>,
    /// NanoCPUs property.
    #[serde(rename = "NanoCPUs")]
    pub nano_cp_us: Option<i64>,
}

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

/// `HealthConfig` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct HealthConfig {
    /// Interval property.
    #[serde(rename = "Interval")]
    pub interval: Option<i64>,
    /// Retries property.
    #[serde(rename = "Retries")]
    pub retries: Option<i64>,
    /// StartInterval property.
    #[serde(rename = "StartInterval")]
    pub start_interval: Option<i64>,
    /// StartPeriod property.
    #[serde(rename = "StartPeriod")]
    pub start_period: Option<i64>,
    /// Test property.
    #[serde(rename = "Test")]
    pub test: Option<Vec<String>>,
    /// Timeout property.
    #[serde(rename = "Timeout")]
    pub timeout: Option<i64>,
}

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

/// `TaskState` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct TaskState {
    #[serde(flatten)]
    pub data: std::collections::HashMap<String, serde_json::Value>,
}

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

/// `GenericResources` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct GenericResources {
    #[serde(flatten)]
    pub data: std::collections::HashMap<String, serde_json::Value>,
}

/// `PluginPrivilege` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct PluginPrivilege {
    /// Description property.
    #[serde(rename = "Description")]
    pub description: Option<String>,
    /// Name property.
    #[serde(rename = "Name")]
    pub name: Option<String>,
    /// Value property.
    #[serde(rename = "Value")]
    pub value: Option<Vec<String>>,
}

/// `Limit` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct Limit {
    /// MemoryBytes property.
    #[serde(rename = "MemoryBytes")]
    pub memory_bytes: Option<i64>,
    /// NanoCPUs property.
    #[serde(rename = "NanoCPUs")]
    pub nano_cp_us: Option<i64>,
    /// Pids property.
    #[serde(rename = "Pids")]
    pub pids: Option<i64>,
}

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

/// `NetworkAttachmentConfig` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct NetworkAttachmentConfig {
    /// Aliases property.
    #[serde(rename = "Aliases")]
    pub aliases: Option<Vec<String>>,
    /// DriverOpts property.
    #[serde(rename = "DriverOpts")]
    pub driver_opts: Option<serde_json::Value>,
    /// Target property.
    #[serde(rename = "Target")]
    pub target: Option<String>,
}

/// `Platform` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct Platform {
    /// Architecture property.
    #[serde(rename = "Architecture")]
    pub architecture: Option<String>,
    /// OS property.
    #[serde(rename = "OS")]
    pub os: Option<String>,
}

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

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

/// Arguments for [`TaskInspect_request`].
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct TaskInspectArgs {
    /// Path parameter: `id`.
    pub id: String,
}

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

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

/// GET /tasks.
///
/// 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 = 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: DynNetClient,
    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);
    }

    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: serde_json::Value = 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 })
}

// -----------------------------------------------------------------------------
// GET /tasks/{id}
// -----------------------------------------------------------------------------

/// GET /tasks/{id}.
///
/// 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 = 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: DynNetClient,
    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);
    }

    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: Task = 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 })
}