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
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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
use mogh_resolver::Resolve;
use serde::{Deserialize, Serialize};
use typeshare::typeshare;

use crate::entities::{
  SearchCombinator, U64,
  docker::{
    container::Container, service::SwarmService, stack::SwarmStack,
  },
  stack::{
    Stack, StackActionState, StackListItem, StackQuery, StackService,
  },
  update::Log,
};

use super::KomodoReadRequest;

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/GetStack",
  description = "Get a specific stack.",
  request_body(content = GetStack),
  responses(
    (status = 200, description = "The stack", body = crate::entities::stack::StackSchema),
  ),
)]
pub fn get_stack() {}

/// Get a specific stack. Response: [Stack].
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(GetStackResponse)]
#[error(mogh_error::Error)]
pub struct GetStack {
  /// Id or name
  #[serde(alias = "id", alias = "name")]
  pub stack: String,
}

#[typeshare]
pub type GetStackResponse = Stack;

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/ListStackServices",
  description = "Lists a specific stacks services (the containers).",
  request_body(content = ListStackServices),
  responses(
    (status = 200, description = "The list of services", body = ListStackServicesResponse),
  ),
)]
pub fn list_stack_services() {}

/// Lists a specific stacks services (the containers). Response: [ListStackServicesResponse].
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListStackServicesResponse)]
#[error(mogh_error::Error)]
pub struct ListStackServices {
  /// Id or name
  #[serde(alias = "id", alias = "name")]
  pub stack: String,
}

#[typeshare]
pub type ListStackServicesResponse = Vec<StackService>;

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/InspectStackContainer",
  description = "Inspect a docker container associated with a Stack.",
  request_body(content = InspectStackContainer),
  responses(
    (status = 200, description = "The container", body = InspectStackContainerResponse),
  ),
)]
pub fn inspect_stack_container() {}

/// Inspect a docker container associated with a Stack.
/// Response: [Container].
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(InspectStackContainerResponse)]
#[error(mogh_error::Error)]
pub struct InspectStackContainer {
  /// Id or name
  #[serde(alias = "id", alias = "name")]
  pub stack: String,
  /// The service name to inspect
  pub service: String,
}

#[typeshare]
pub type InspectStackContainerResponse = Container;

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/InspectStackSwarmService",
  description = "Inspect a swarm service associated with a Stack.",
  request_body(content = InspectStackSwarmService),
  responses(
    (status = 200, description = "The swarm service", body = InspectStackSwarmServiceResponse),
  ),
)]
pub fn inspect_stack_swarm_service() {}

/// Inspect a swarm service associated with a Stack.
/// Response: [SwarmService].
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(InspectStackSwarmServiceResponse)]
#[error(mogh_error::Error)]
pub struct InspectStackSwarmService {
  /// Id or name
  #[serde(alias = "id", alias = "name")]
  pub stack: String,
  /// The service name to inspect
  pub service: String,
}

#[typeshare]
pub type InspectStackSwarmServiceResponse = SwarmService;

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/InspectStackSwarmInfo",
  description = "Inspect swarm info associated with a Stack.",
  request_body(content = InspectStackSwarmInfo),
  responses(
    (status = 200, description = "The swarm info", body = InspectStackSwarmInfoResponse),
  ),
)]
pub fn inspect_stack_swarm_info() {}

/// Inspect swarm info associated with a Stack.
/// Response: [SwarmStack].
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(InspectStackSwarmInfoResponse)]
#[error(mogh_error::Error)]
pub struct InspectStackSwarmInfo {
  /// Id or name
  #[serde(alias = "id", alias = "name")]
  pub stack: String,
}

#[typeshare]
pub type InspectStackSwarmInfoResponse = SwarmStack;

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/GetStackLog",
  description = "Get a stack's logs. Filter down included services.",
  request_body(content = GetStackLog),
  responses(
    (status = 200, description = "The stack log", body = GetStackLogResponse),
  ),
)]
pub fn get_stack_log() {}

/// Get a stack's logs. Filter down included services. Response: [GetStackLogResponse].
///
/// Note. This call will hit the underlying server directly for most up to date log.
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(GetStackLogResponse)]
#[error(mogh_error::Error)]
pub struct GetStackLog {
  /// Id or name
  #[serde(alias = "id", alias = "name")]
  pub stack: String,
  /// Filter the logs to only ones from specific services.
  /// If empty, will include logs from all services.
  pub services: Vec<String>,
  /// The number of lines of the log tail to include.
  /// Default: 100.
  /// Max: 5000.
  #[serde(default = "default_tail")]
  pub tail: U64,
  /// Enable `--timestamps`
  #[serde(default)]
  pub timestamps: bool,
}

fn default_tail() -> u64 {
  50
}

#[typeshare]
pub type GetStackLogResponse = Log;

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/SearchStackLog",
  description = "Search the stack log's tail using `grep`.",
  request_body(content = SearchStackLog),
  responses(
    (status = 200, description = "The search results", body = SearchStackLogResponse),
  ),
)]
pub fn search_stack_log() {}

/// Search the stack log's tail using `grep`. All lines go to stdout.
/// Response: [SearchStackLogResponse].
///
/// Note. This call will hit the underlying server directly for most up to date log.
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(SearchStackLogResponse)]
#[error(mogh_error::Error)]
pub struct SearchStackLog {
  /// Id or name
  #[serde(alias = "id", alias = "name")]
  pub stack: String,
  /// Filter the logs to only ones from specific services.
  /// If empty, will include logs from all services.
  pub services: Vec<String>,
  /// The terms to search for.
  pub terms: Vec<String>,
  /// When searching for multiple terms, can use `AND` or `OR` combinator.
  ///
  /// - `AND`: Only include lines with **all** terms present in that line.
  /// - `OR`: Include lines that have one or more matches in the terms.
  #[serde(default)]
  pub combinator: SearchCombinator,
  /// Invert the results, ie return all lines that DON'T match the terms / combinator.
  #[serde(default)]
  pub invert: bool,
  /// Enable `--timestamps`
  #[serde(default)]
  pub timestamps: bool,
}

#[typeshare]
pub type SearchStackLogResponse = Log;

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/ListCommonStackExtraArgs",
  description = "Gets a list of existing values used as extra args across other stacks.",
  request_body(content = ListCommonStackExtraArgs),
  responses(
    (status = 200, description = "The list of extra args", body = ListCommonStackExtraArgsResponse),
  ),
)]
pub fn list_common_stack_extra_args() {}

/// Gets a list of existing values used as extra args across other stacks.
/// Useful to offer suggestions. Response: [ListCommonStackExtraArgsResponse]
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListCommonStackExtraArgsResponse)]
#[error(mogh_error::Error)]
pub struct ListCommonStackExtraArgs {
  /// optional structured query to filter stacks.
  #[serde(default)]
  pub query: StackQuery,
}

#[typeshare]
pub type ListCommonStackExtraArgsResponse = Vec<String>;

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/ListCommonStackBuildExtraArgs",
  description = "Gets a list of existing values used as build extra args across other stacks.",
  request_body(content = ListCommonStackBuildExtraArgs),
  responses(
    (status = 200, description = "The list of build extra args", body = ListCommonStackBuildExtraArgsResponse),
  ),
)]
pub fn list_common_stack_build_extra_args() {}

/// Gets a list of existing values used as build extra args across other stacks.
/// Useful to offer suggestions. Response: [ListCommonStackBuildExtraArgsResponse]
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListCommonStackBuildExtraArgsResponse)]
#[error(mogh_error::Error)]
pub struct ListCommonStackBuildExtraArgs {
  /// optional structured query to filter stacks.
  #[serde(default)]
  pub query: StackQuery,
}

#[typeshare]
pub type ListCommonStackBuildExtraArgsResponse = Vec<String>;

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/ListStacks",
  description = "List stacks matching optional query.",
  request_body(content = ListStacks),
  responses(
    (status = 200, description = "The list of stacks", body = ListStacksResponse),
  ),
)]
pub fn list_stacks() {}

/// List stacks matching optional query. Response: [ListStacksResponse].
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Default, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListStacksResponse)]
#[error(mogh_error::Error)]
pub struct ListStacks {
  /// optional structured query to filter stacks.
  #[serde(default)]
  pub query: StackQuery,
}

#[typeshare]
pub type ListStacksResponse = Vec<StackListItem>;

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/ListFullStacks",
  description = "List stacks matching optional query.",
  request_body(content = ListFullStacks),
  responses(
    (status = 200, description = "The list of stacks", body = ListFullStacksResponse),
  ),
)]
pub fn list_full_stacks() {}

/// List stacks matching optional query. Response: [ListFullStacksResponse].
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Default, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(ListFullStacksResponse)]
#[error(mogh_error::Error)]
pub struct ListFullStacks {
  /// optional structured query to filter stacks.
  #[serde(default)]
  pub query: StackQuery,
}

#[typeshare]
pub type ListFullStacksResponse = Vec<Stack>;

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/GetStackActionState",
  description = "Get current action state for the stack.",
  request_body(content = GetStackActionState),
  responses(
    (status = 200, description = "The stack action state", body = GetStackActionStateResponse),
  ),
)]
pub fn get_stack_action_state() {}

/// Get current action state for the stack. Response: [StackActionState].
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(GetStackActionStateResponse)]
#[error(mogh_error::Error)]
pub struct GetStackActionState {
  /// Id or name
  #[serde(alias = "id", alias = "name")]
  pub stack: String,
}

#[typeshare]
pub type GetStackActionStateResponse = StackActionState;

//

#[cfg(feature = "utoipa")]
#[utoipa::path(
  post,
  path = "/GetStacksSummary",
  description = "Gets a summary of data relating to all syncs.",
  request_body(content = GetStacksSummary),
  responses(
    (status = 200, description = "The stacks summary", body = GetStacksSummaryResponse),
  ),
)]
pub fn get_stacks_summary() {}

/// Gets a summary of data relating to all syncs.
/// Response: [GetStacksSummaryResponse].
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Resolve)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
#[empty_traits(KomodoReadRequest)]
#[response(GetStacksSummaryResponse)]
#[error(mogh_error::Error)]
pub struct GetStacksSummary {}

/// Response for [GetStacksSummary]
#[typeshare]
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
pub struct GetStacksSummaryResponse {
  /// The total number of stacks
  pub total: u32,
  /// The number of stacks with Running state.
  pub running: u32,
  /// The number of stacks with Stopped or Paused state.
  pub stopped: u32,
  /// The number of stacks with Down state.
  pub down: u32,
  /// The number of stacks with Unhealthy or Restarting or Dead or Created or Removing state.
  pub unhealthy: u32,
  /// The number of stacks with Unknown state.
  pub unknown: u32,
}