komodo_client 2.1.1

Client for the Komodo build and deployment system
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
use clap::Parser;
use mogh_resolver::Resolve;
use serde::{Deserialize, Serialize};
use typeshare::typeshare;

use crate::{
  api::execute::KomodoExecuteRequest,
  entities::{
    docker::node::{NodeSpecAvailabilityEnum, NodeSpecRoleEnum},
    update::Update,
  },
};

// ========
// = Node =
// ========

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/RemoveSwarmNodes",
  description = "Remove swarm nodes.",
  request_body(content = RemoveSwarmNodes),
  responses(
    (status = 200, description = "The update", body = Update),
  ),
)]
pub fn remove_swarm_nodes() {}

/// `docker node rm [OPTIONS] NODE [NODE...]`
///
/// https://docs.docker.com/reference/cli/docker/node/rm/
#[typeshare]
#[derive(
  Serialize, Deserialize, Debug, Clone, PartialEq, Resolve, Parser,
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(mogh_error::Error)]
pub struct RemoveSwarmNodes {
  /// Name or id
  pub swarm: String,
  /// Node names or ids to remove
  pub nodes: Vec<String>,
  /// Force remove a node from the swarm
  #[serde(default)]
  #[arg(long, short, default_value_t = false)]
  pub force: bool,
}

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/UpdateSwarmNode",
  description = "Update a swarm node's availability, labels, and role.",
  request_body(content = UpdateSwarmNode),
  responses(
    (status = 200, description = "The update", body = Update),
  ),
)]
pub fn update_swarm_node() {}

/// `docker node update [OPTIONS] NODE`
///
/// https://docs.docker.com/reference/cli/docker/node/update/
#[typeshare]
#[derive(
  Serialize, Deserialize, Debug, Clone, PartialEq, Resolve, Parser,
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(mogh_error::Error)]
pub struct UpdateSwarmNode {
  /// Name or id
  pub swarm: String,
  /// Node hostname or id
  pub node: String,
  /// Update the node's availability: 'active', 'pause', or 'drain'
  #[arg(long, short = 'a')]
  pub availability: Option<NodeSpecAvailabilityEnum>,
  /// Add labels to node (`key=value`).
  #[arg(long, short = 'l')]
  pub label_add: Option<Vec<String>>,
  /// Add labels to node (`key=value`). (alias: `lr`)
  #[arg(long, alias = "lr")]
  pub label_rm: Option<Vec<String>>,
  /// Update the node's role: 'worker' or 'manager'
  #[arg(long, short = 'r')]
  pub role: Option<NodeSpecRoleEnum>,
}

// =========
// = Stack =
// =========

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/RemoveSwarmStacks",
  description = "Remove swarm stacks.",
  request_body(content = RemoveSwarmStacks),
  responses(
    (status = 200, description = "The update", body = Update),
  ),
)]
pub fn remove_swarm_stacks() {}

/// `docker stack rm [OPTIONS] STACK [STACK...]`
///
/// https://docs.docker.com/reference/cli/docker/stack/rm/
#[typeshare]
#[derive(
  Serialize, Deserialize, Debug, Clone, PartialEq, Resolve, Parser,
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(mogh_error::Error)]
pub struct RemoveSwarmStacks {
  /// Name or id
  pub swarm: String,
  /// Node names to remove
  pub stacks: Vec<String>,
  /// Do not wait for stack removal
  #[serde(default = "default_detach")]
  #[arg(long, short, default_value_t = default_detach())]
  pub detach: bool,
}

fn default_detach() -> bool {
  true
}

// ===========
// = Service =
// ===========

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/RemoveSwarmServices",
  description = "Remove swarm services.",
  request_body(content = RemoveSwarmServices),
  responses(
    (status = 200, description = "The update", body = Update),
  ),
)]
pub fn remove_swarm_services() {}

/// `docker service rm SERVICE [SERVICE...]`
///
/// https://docs.docker.com/reference/cli/docker/service/rm/
#[typeshare]
#[derive(
  Serialize, Deserialize, Debug, Clone, PartialEq, Resolve, Parser,
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(mogh_error::Error)]
pub struct RemoveSwarmServices {
  /// Name or id
  pub swarm: String,
  /// Service names or ids
  pub services: Vec<String>,
}

// ==========
// = Config =
// ==========

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/CreateSwarmConfig",
  description = "Create a swarm config.",
  request_body(content = CreateSwarmConfig),
  responses(
    (status = 200, description = "The update", body = Update),
  ),
)]
pub fn create_swarm_config() {}

/// `docker config create [OPTIONS] CONFIG file|-`
///
/// https://docs.docker.com/reference/cli/docker/config/create/
#[typeshare]
#[derive(
  Serialize, Deserialize, Debug, Clone, PartialEq, Resolve, Parser,
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(mogh_error::Error)]
pub struct CreateSwarmConfig {
  /// Name or id
  pub swarm: String,
  /// The name of the config to create
  pub name: String,
  /// The data to store in the config
  pub data: String,
  /// Docker labels to give the config
  #[serde(default)]
  pub labels: Vec<String>,
  /// Optional custom template driver
  pub template_driver: Option<String>,
}

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/RotateSwarmConfig",
  description = "Rotate a swarm config.",
  request_body(content = RotateSwarmConfig),
  responses(
    (status = 200, description = "The update", body = Update),
  ),
)]
pub fn rotate_swarm_config() {}

/// https://docs.docker.com/engine/swarm/configs/#example-rotate-a-config
///
/// Swarm configs / secrets are immutable after creation.
/// This making updating values awkward when you have services actively using them.
/// The following steps allows for config rotation while minimizing downtime.
///
/// 1. Query for all services using the config
///    - If not in use by any services, can simply `remove` and `create` the config.
///    - Otherwise, continue with following steps
/// 2. `Create` config `{config}-tmp` using provided data
/// 3. `Update` services to use `tmp` config
/// 4. `Remove` and `create` the actual config. This is now possible because services are using the tmp config.
/// 5. `Update` services to use actual (not `tmp`) config again.
#[typeshare]
#[derive(
  Serialize, Deserialize, Debug, Clone, PartialEq, Resolve, Parser,
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(mogh_error::Error)]
pub struct RotateSwarmConfig {
  /// Name or id
  pub swarm: String,
  /// Config name
  pub config: String,
  /// The new config data as a string
  pub data: String,
}

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/RemoveSwarmConfigs",
  description = "Remove swarm configs.",
  request_body(content = RemoveSwarmConfigs),
  responses(
    (status = 200, description = "The update", body = Update),
  ),
)]
pub fn remove_swarm_configs() {}

/// `docker config rm CONFIG [CONFIG...]`
///
/// https://docs.docker.com/reference/cli/docker/config/rm/
#[typeshare]
#[derive(
  Serialize, Deserialize, Debug, Clone, PartialEq, Resolve, Parser,
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(mogh_error::Error)]
pub struct RemoveSwarmConfigs {
  /// Name or id
  pub swarm: String,
  /// Config names or ids
  pub configs: Vec<String>,
}

// ==========
// = Secret =
// ==========

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/CreateSwarmSecret",
  description = "Create a swarm secret.",
  request_body(content = CreateSwarmSecret),
  responses(
    (status = 200, description = "The update", body = Update),
  ),
)]
pub fn create_swarm_secret() {}

/// `docker config create [OPTIONS] CONFIG file|-`
///
/// https://docs.docker.com/reference/cli/docker/config/create/
#[typeshare]
#[derive(
  Serialize, Deserialize, Debug, Clone, PartialEq, Resolve, Parser,
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(mogh_error::Error)]
pub struct CreateSwarmSecret {
  /// Name or id
  pub swarm: String,
  /// The name of the secret to create
  pub name: String,
  /// The data to store in the secret
  pub data: String,
  /// Optional custom secret driver
  pub driver: Option<String>,
  /// Docker labels to give the secret
  #[serde(default)]
  pub labels: Vec<String>,
  /// Optional custom template driver
  pub template_driver: Option<String>,
}

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/RotateSwarmSecret",
  description = "Rotate a swarm secret.",
  request_body(content = RotateSwarmSecret),
  responses(
    (status = 200, description = "The update", body = Update),
  ),
)]
pub fn rotate_swarm_secret() {}

/// https://docs.docker.com/engine/swarm/secrets/#example-rotate-a-secret
///
/// Swarm configs / secrets are immutable after creation.
/// This making updating values awkward when you have services actively using them.
/// The following steps allows for secret rotation while minimizing downtime.
///
/// 1. Query for all services using the secret
///    - If not in use by any services, can simply `remove` and `create` the secret.
///    - Otherwise, continue with following steps
/// 2. `Create` secret `{secret}-tmp` using provided data
/// 3. `Update` services to use `tmp` secret
/// 4. `Remove` and `create` the actual secret. This is now possible because services are using the tmp secret.
/// 5. `Update` services to use actual (not `tmp`) secret again.
#[typeshare]
#[derive(
  Serialize, Deserialize, Debug, Clone, PartialEq, Resolve, Parser,
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(mogh_error::Error)]
pub struct RotateSwarmSecret {
  /// Name or id
  pub swarm: String,
  /// Secret name
  pub secret: String,
  /// The new secret data as a string
  pub data: String,
}

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/RemoveSwarmSecrets",
  description = "Remove swarm secrets.",
  request_body(content = RemoveSwarmSecrets),
  responses(
    (status = 200, description = "The update", body = Update),
  ),
)]
pub fn remove_swarm_secrets() {}

/// `docker secret rm SECRET [SECRET...]`
///
/// https://docs.docker.com/reference/cli/docker/secret/rm/
#[typeshare]
#[derive(
  Serialize, Deserialize, Debug, Clone, PartialEq, Resolve, Parser,
)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoExecuteRequest)]
#[response(Update)]
#[error(mogh_error::Error)]
pub struct RemoveSwarmSecrets {
  /// Name or id
  pub swarm: String,
  /// Secret names or ids
  pub secrets: Vec<String>,
}