fundaia 0.7.2

Command line for the Fundaia deployment platform: projects, services, variables, deployments, logs and metrics
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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
// Some of these fields are decoded and never read. That is the point: this
// module is the wire contract written down, and a field that is dropped from
// the struct is a field the next command has to rediscover from the server's
// source. The cost of keeping them is one `#[allow]`; the cost of trimming them
// to whatever is used today is paid every time the tool grows a subcommand.
#![allow(dead_code)]

use serde::{Deserialize, Serialize};

/// The DTOs the server sends, as much of each as this tool reads.
///
/// Deliberately partial. Every struct here is `deny_unknown_fields`-free so the
/// server can grow a field without breaking an installed binary — a CLI is the
/// one client that is never redeployed alongside the API, and a strict decoder
/// would turn every additive change into a support question.

#[derive(Debug, Deserialize)]
pub struct ProjectsPage {
    pub projects: Vec<Project>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Project {
    pub id: String,
    pub slug: String,
    pub name: String,
    #[serde(default)]
    pub environment_name: String,
    #[serde(default)]
    pub service_count: u32,
    #[serde(default)]
    pub online_count: u32,
    #[serde(default)]
    pub services: Vec<Service>,
}

#[derive(Debug, Deserialize)]
pub struct ServicesPage {
    pub services: Vec<Service>,
    #[serde(default)]
    pub edges: Vec<Edge>,
}

#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Service {
    /// The service-environment id: what every other endpoint is keyed on.
    pub id: String,
    pub service_id: String,
    pub name: String,
    pub slug: String,
    pub kind: String,
    pub state: String,
    #[serde(default)]
    pub brand: Option<String>,
    #[serde(default)]
    pub host: Option<String>,
    #[serde(default)]
    pub repo_full_name: Option<String>,
    #[serde(default)]
    pub last_deployment_number: Option<u32>,
}

#[derive(Debug, Clone, Deserialize)]
pub struct Edge {
    pub from: String,
    pub to: String,
    pub label: String,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ServiceDetail {
    pub service: ServiceIdentity,
    pub environment: ServiceEnvironment,
    #[serde(default)]
    pub domains: Vec<Domain>,
    #[serde(default)]
    pub active_deployment: Option<Deployment>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ServiceIdentity {
    pub id: String,
    pub name: String,
    pub slug: String,
    pub kind: String,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ServiceEnvironment {
    pub id: String,
    pub state: String,
    #[serde(default)]
    pub memory_mb: u32,
    #[serde(default)]
    pub cpus: f32,
    #[serde(default)]
    pub sleep_enabled: bool,
    #[serde(default)]
    pub container_port: Option<u32>,
    #[serde(default)]
    pub health_path: Option<String>,
    #[serde(default)]
    pub adopted: bool,
}

#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Deployment {
    pub id: String,
    pub number: u32,
    pub status: String,
    pub trigger: String,
    #[serde(default)]
    pub commit_sha: Option<String>,
    #[serde(default)]
    pub commit_subject: Option<String>,
    #[serde(default)]
    pub failure_message: Option<String>,
    pub created_at: String,
    #[serde(default)]
    pub finished_at: Option<String>,
}

#[derive(Debug, Deserialize)]
pub struct DeploymentsPage {
    pub deployments: Vec<Deployment>,
}

#[derive(Debug, Deserialize)]
pub struct DeploymentAccepted {
    pub deployment: Deployment,
}

#[derive(Debug, Deserialize)]
pub struct DeploymentDetail {
    pub deployment: Deployment,
    pub pipeline: Pipeline,
}

#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Pipeline {
    pub stages: Vec<Stage>,
    #[serde(default)]
    pub current_stage_id: Option<String>,
    pub finished: bool,
    pub succeeded: bool,
}

#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Stage {
    pub id: String,
    pub label: String,
    pub state: String,
    #[serde(default)]
    pub started_at: Option<String>,
    #[serde(default)]
    pub finished_at: Option<String>,
    #[serde(default)]
    pub failure_message: Option<String>,
}

#[derive(Debug, Deserialize)]
pub struct VariablesPage {
    pub variables: Vec<Variable>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Variable {
    pub id: String,
    pub key: String,
    pub kind: String,
    #[serde(default)]
    pub preview: Option<String>,
    #[serde(default)]
    pub write_only: bool,
    /// Set once it is sealed: no value comes back and no write is accepted.
    #[serde(default)]
    pub sealed_at: Option<String>,
}

impl Variable {
    pub fn is_sealed(&self) -> bool {
        self.sealed_at.is_some()
    }
}

#[derive(Debug, Deserialize)]
pub struct RevealedVariable {
    pub value: String,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BackupsPage {
    #[serde(default)]
    pub schedules: Vec<String>,
    /// When the next scheduled copy is owed. Null when no schedule is on.
    #[serde(default)]
    pub next_at: Option<String>,
    /// False for a service with no volume, which has nothing to copy.
    #[serde(default)]
    pub supported: bool,
    #[serde(default)]
    pub backups: Vec<Backup>,
}

#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Backup {
    pub id: String,
    /// Null for a copy somebody asked for, which is what exempts it from retention.
    #[serde(default)]
    pub schedule: Option<String>,
    pub status: String,
    #[serde(default)]
    pub size_bytes: u64,
    #[serde(default)]
    pub locked: bool,
    #[serde(default)]
    pub failure_message: Option<String>,
    pub created_at: String,
}

#[derive(Debug, Deserialize)]
pub struct BackupTaken {
    pub backup: Backup,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BackupSchedules {
    #[serde(default)]
    pub schedules: Vec<String>,
}

#[derive(Debug, Deserialize)]
pub struct DomainsPage {
    pub domains: Vec<Domain>,
}

#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Domain {
    pub id: String,
    pub host: String,
    pub kind: String,
    pub state: String,
    #[serde(default)]
    pub dns_instructions: Option<String>,
    /// False while the service is private: the name is kept, nothing serves it.
    ///
    /// Defaulted to true so this tool keeps working against an instance older
    /// than the switch, where every domain it can see is a serving one.
    #[serde(default = "enabled_by_default")]
    pub enabled: bool,
    pub url: String,
}

fn enabled_by_default() -> bool {
    true
}

#[derive(Debug, Deserialize)]
pub struct UsagePage {
    pub samples: Vec<UsageSample>,
}

#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct UsageSample {
    pub at: String,
    pub cpu_millicores: u32,
    pub memory_bytes: u64,
    pub memory_limit_bytes: u64,
}

#[derive(Debug, Deserialize)]
pub struct LogPage {
    pub lines: Vec<LogLine>,
}

#[derive(Debug, Clone, Deserialize)]
pub struct LogLine {
    pub sequence: u64,
    /// Absent from an older server; the column is held blank rather than
    /// shifting everything left for a log that predates it.
    #[serde(default)]
    pub at: Option<String>,
    #[serde(default)]
    pub stream: String,
    #[serde(default)]
    pub level: String,
    pub message: String,
}

/// One state change off `/api/infra/stream`.
///
/// Every field but `kind` is optional because the endpoint carries several
/// shapes down one socket — a deployment moving, a variable being written, a
/// colleague opening a field — and a client that refused to parse the ones it
/// does not draw would stop working the day a sixth is added.
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct InfraEvent {
    pub kind: String,
    #[serde(default)]
    pub project_id: String,
    #[serde(default)]
    pub service_environment_id: Option<String>,
    #[serde(default)]
    pub deployment_id: Option<String>,
    #[serde(default)]
    pub status: Option<String>,
    #[serde(default)]
    pub state: Option<String>,
    #[serde(default)]
    pub trigger: Option<String>,
    #[serde(default)]
    pub number: Option<u32>,
    #[serde(default)]
    pub service_name: Option<String>,
    #[serde(default)]
    pub commit_sha: Option<String>,
    #[serde(default)]
    pub commit_subject: Option<String>,
    /// The variable's name on a `variable-changed`. Never its value.
    #[serde(default)]
    pub key: Option<String>,
    #[serde(default)]
    pub action: Option<String>,
}

#[derive(Debug, Deserialize)]
pub struct ConnectionCandidates {
    pub candidates: Vec<ConnectionCandidate>,
}

#[derive(Debug, Deserialize)]
pub struct ConnectionCandidate {
    pub id: String,
    pub name: String,
    pub summary: String,
}

#[derive(Debug, Deserialize)]
pub struct ConnectionMade {
    pub connection: Connection,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Connection {
    pub provider_name: String,
    pub keys: Vec<String>,
    pub summary: String,
}

#[derive(Debug, Deserialize)]
pub struct TemplatesPage {
    pub templates: Vec<Template>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Template {
    pub key: String,
    pub display_name: String,
    pub image: String,
}

/// The three steps of letting a terminal in, as the server describes them.
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct StartedAuthorization {
    pub user_code: String,
    pub device_secret: String,
    pub verification_uri: String,
    pub verification_uri_complete: String,
    pub interval_seconds: u64,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct CollectedAuthorization {
    pub status: String,
    #[serde(default)]
    pub token: Option<String>,
}

/// What the instance calls itself, so a stale binary can say so.
#[derive(Debug, Deserialize)]
pub struct ServerVersion {
    pub platform: String,
    #[serde(default)]
    pub revision: Option<String>,
    #[serde(default)]
    pub modules: std::collections::BTreeMap<String, String>,
}

#[derive(Debug, Deserialize)]
pub struct Principal {
    pub principal: Option<PrincipalIdentity>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PrincipalIdentity {
    pub id: String,
    pub display_name: String,
}

/// The one thing this tool sends that is not a bare field or two.
#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct NewService {
    pub name: String,
    pub source_kind: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub repo_full_name: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub branch: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub image: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub template_key: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub kind: Option<String>,
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub connect_to: Vec<String>,
}

// ------------------------------------------------------------- workspaces

#[derive(Debug, Deserialize)]
pub struct WorkspacesPage {
    pub workspaces: Vec<Workspace>,
}

/// A place several people share, holding several projects.
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Workspace {
    pub id: String,
    pub name: String,
    pub slug: String,
    /// What the caller is in it. Null for the instance owner, who is in none.
    #[serde(default)]
    pub role: Option<String>,
}

#[derive(Debug, Deserialize)]
pub struct MembersPage {
    pub members: Vec<Member>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Member {
    pub user_id: String,
    pub role: String,
    #[serde(default)]
    pub display_name: Option<String>,
    #[serde(default)]
    pub github_login: Option<String>,
    #[serde(default)]
    pub email: Option<String>,
}

#[derive(Debug, Deserialize)]
pub struct InvitationsPage {
    pub invitations: Vec<Invitation>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Invitation {
    pub id: String,
    pub email: String,
    pub role: String,
    pub status: String,
}

/// What creating one answers with, link included.
///
/// The link comes back so the terminal can print it: a person running this over
/// SSH is often the same person who would otherwise have to go and find the
/// email, and delivery is the part most likely to be slow or unconfigured.
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SentInvitation {
    pub accept_url: String,
}

#[derive(Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct NewInvitation {
    pub email: String,
    pub role: String,
}

// ------------------------------------------------------- settings & capacity

/// What the machine has left.
///
/// Numbers rather than a verdict: the terminal asking is usually about to
/// decide how big to make the next service.
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Capacity {
    pub total_memory_mb: u64,
    pub reserved_memory_mb: u64,
    pub committed_memory_mb: u64,
    pub available_memory_mb: u64,
    pub ports_in_use: u32,
    pub ports_total: u32,
    pub remaining_at_default_size: u32,
    pub running_low: bool,
}

/// The result of turning bucket encryption on or off.
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EncryptionOutcome {
    pub enabled: bool,
    pub buckets: Vec<String>,
    /// Objects rewritten so what was already stored is covered too.
    pub re_encrypted: u32,
}

/// What a service answers on after publishing it, or taking it off.
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ExposureOutcome {
    pub domains: Vec<Domain>,
}

/// A PATCH of a service's settings: absent keys are left alone.
#[derive(Debug, Default, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct SettingsPatch {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub memory_mb: Option<u32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub replicas: Option<u32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub root_directory: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub start_command: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub health_path: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub restart_policy: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sleep_enabled: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub auto_deploy: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cache_enabled: Option<bool>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cache_ttl_seconds: Option<u32>,
}

#[derive(Debug, Deserialize)]
pub struct VolumesPage {
    pub volumes: Vec<Volume>,
}

#[derive(Debug, Deserialize)]
pub struct VolumeAttached {
    pub volume: Volume,
}

/// A directory that outlives the container it is mounted into.
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Volume {
    pub id: String,
    pub name: String,
    pub mount_path: String,
    /// False until the next deployment picks it up, which is why attaching says
    /// so rather than pretending the service already has it.
    #[serde(default)]
    pub mounted: bool,
    #[serde(default)]
    pub created_at: Option<String>,
}

/// The Containerfile a service builds with, and how it was arrived at.
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Recipe {
    /// Which strategy wrote it: `nixpacks`, `dockerfile`, `static`…
    pub builder: String,
    /// `generated` until somebody edits it, and `edited` for ever after.
    pub source: String,
    pub containerfile: String,
    #[serde(default)]
    pub exposed_port: Option<u32>,
    #[serde(default)]
    pub notes: Vec<String>,
    #[serde(default)]
    pub warnings: Vec<String>,
}

#[derive(Debug, Deserialize)]
pub struct EditedRecipe {
    pub source: String,
}

#[derive(Debug, Deserialize)]
pub struct ProjectCreated {
    pub project: Project,
}

#[derive(Debug, Deserialize)]
pub struct Disconnected {
    /// How many variable references stopped existing, which is what a
    /// connection was made of in the first place.
    #[serde(default)]
    pub removed: u32,
}

#[derive(Debug, Deserialize)]
pub struct ImportedVariables {
    #[serde(default)]
    pub imported: u32,
}

/// One line of a `.env` on its way to the server.
#[derive(Debug, Serialize)]
pub struct VariableDraft {
    pub key: String,
    pub value: String,
    pub secret: bool,
}