exedev 0.1.0

Official Rust SDK for exe.dev: create VMs, run commands on them, and run every exe.dev command
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
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
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
// Code generated by "go run ./cmd/gensdkrs" in the exe.dev repository. DO NOT EDIT.

//! The JSON exe.dev returns, as Rust types.
//!
//! Methods whose command reports JSON in a known shape return these. They
//! are `#[non_exhaustive]`, as the server may add fields and values; an
//! enum's `Other` variant holds one this SDK does not know.

#![allow(missing_docs)] // The server's types document what needs it.

use std::collections::BTreeMap;

use serde::{Deserialize, Serialize};

/// A VM as returned by `ls --json`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct VMRecord {
    pub vm_name: String,
    pub ssh_dest: String,
    pub https_url: String,
    pub status: String,
    pub region: String,
    pub region_display: String,

    /// Absent when the VM has no tags.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub tags: Option<Vec<String>>,

    /// The VM's comment, if it has one.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub comment: Option<String>,

    /// When the VM was created, in RFC 3339 format.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub created_at: Option<String>,

    /// Absent from VMs you do not own.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub egress_policy: Option<EgressPolicy>,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct VMListResponse {
    pub vms: Vec<VMRecord>,
}

/// An SSH key as listed by `whoami`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct WhoamiSSHKey {
    /// The key's name, if it has one.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,
    pub public_key: String,
    pub fingerprint: String,

    /// Whether this is the key making the request.
    pub current: bool,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct WhoamiResponse {
    pub email: String,
    pub region: String,
    pub region_display: String,
    pub ssh_keys: Vec<WhoamiSSHKey>,
}

/// One sample of a VM's resource usage, as returned by `stat`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct StatPoint {
    pub timestamp: String,
    pub vm_name: String,
    pub cpu_cores: f64,
    pub cpu_nominal: f64,
    pub mem_used_bytes: i64,
    pub mem_total_bytes: i64,
    pub disk_size_gb: f64,
    pub disk_used_gb: f64,
    pub disk_logical_used_gb: f64,
    pub fs_used_gb: f64,
    pub fs_total_gb: f64,
    pub fs_free_gb: f64,
    pub fs_available_gb: f64,
    pub network_tx_mbps: f64,
    pub network_rx_mbps: f64,
    pub io_read_mbps: f64,
    pub io_write_mbps: f64,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct StatResponse {
    pub name: String,
    pub status: String,

    /// The window the points cover, e.g. "24h".
    pub range: String,

    /// Usage samples, or null if there are none yet (e.g. a new VM).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub points: Option<Vec<StatPoint>>,
}

/// The response to `new`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct NewResponse {
    pub vm_name: String,
    pub tags: Vec<String>,
    pub ssh_command: String,
    pub ssh_dest: String,
    pub ssh_host: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub ssh_user: Option<String>,
    pub ssh_port: i64,
    pub https_url: String,
    pub proxy_port: i64,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub shelley_url: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub vscode_url: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub xterm_url: Option<String>,

    /// The `.comment()` the VM was created with; absent when there is none.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub comment: Option<String>,

    /// When the VM was created, as in `ls`.
    pub created_at: String,
    pub egress_policy: EgressPolicy,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub pool_id: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub standalone: Option<bool>,

    /// Set when the VM was created but a later setup step failed.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub error: Option<String>,
}

/// The response to `cp`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct CpResponse {
    /// The new VM's name.
    pub name: String,

    /// The new VM is still booting.
    pub state: String,

    /// The VM it is a copy of.
    pub source: String,

    /// The new VM's SSH destination, like ssh\_dest in `ls`.
    pub ssh: String,
    pub ssh_host: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub ssh_user: Option<String>,
    pub https_url: String,

    /// The copy's tags: the source's, unless `.copy_tags(false)`.
    pub tags: Vec<String>,

    /// The copy's comment, which is the source's; absent when there is none.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub comment: Option<String>,

    /// When the copy was created, as in `ls`; absent if that is unknown.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub created_at: Option<String>,

    /// The source's, unless `.egress()` says otherwise.
    pub egress_policy: EgressPolicy,

    /// How long the copy took, in seconds.
    pub elapsed: f64,

    /// The pool the new VM is in, if any.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub pool_id: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub pool_name: Option<String>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub standalone: Option<bool>,
}

/// The response to `rm`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct RmResponse {
    pub deleted: Vec<String>,

    /// Includes not\_found.
    pub failed: Vec<String>,

    /// Missing, or not visible to this token. Absent from older servers.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub not_found: Option<Vec<String>>,

    /// Why each failed VM was not deleted. Absent from older servers.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub errors: Option<BTreeMap<String, String>>,
}

/// The response to `restart`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct RestartResponse {
    pub status: String,
    pub vm_name: String,
}

/// The response to `rename`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct RenameResponse {
    pub status: String,
    pub old_name: String,
    pub new_name: String,

    /// Where to reach the VM under its new name, as ls reports them.
    pub ssh_dest: String,
    pub https_url: String,
}

/// The response to `pause`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PauseResponse {
    pub vm_name: String,
    pub status: String,
}

/// The response to `resume`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ResumeResponse {
    pub vm_name: String,
    pub status: String,

    /// "true" when the VM booted from disk instead of restoring its RAM
    /// snapshot, so its in-memory state is gone. A string, not a boolean.
    ///
    #[serde(with = "bool_string")]
    pub cold_booted: bool,
}

/// A request to grow a VM's disk past its self-serve limit.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct DiskResizeRequest {
    pub status: DiskResizeStatus,
    pub requested_disk_bytes: i64,

    /// RFC 3339.
    pub requested_at: String,

    /// RFC 3339; absent while pending.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub resolved_at: Option<String>,
}

/// The response to `resize`. Each group of fields is present only when the
/// command changed (or requested) that resource. Sizes are in bytes.
///
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ResizeResponse {
    pub vm_name: String,

    /// Whether the VM must restart to take on its new size: memory, or vCPUs
    /// that could not be added while it runs, or a grown disk, whose
    /// filesystem grows at boot. With `.memory()` or `.cpu()` this includes such a
    /// change from an earlier resize still waiting for a restart. False for a
    /// stopped VM, which starts with its new size.
    ///
    pub restart_required: bool,

    /// With `.memory()` or `.cpu()`.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub old_memory: Option<i64>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub new_memory: Option<i64>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub old_cpus: Option<i64>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub new_cpus: Option<i64>,

    /// With `.disk()` within the self-serve limit: the disk has grown.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub disk_old_bytes: Option<i64>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub disk_new_bytes: Option<i64>,

    /// With `.disk()` above the self-serve limit: support must approve the size,
    /// and the disk stays at disk\_capacity\_bytes until then.
    ///
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub disk_resize_pending_approval: Option<bool>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub disk_capacity_bytes: Option<i64>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub requested_disk_bytes: Option<i64>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub self_serve_max_disk_bytes: Option<i64>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub approval_max_disk_bytes: Option<i64>,

    /// Why approval is needed: "per\_vm" (the VM's limit) or "host".
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub approval_reasons: Option<Vec<String>>,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub disk_resize_request: Option<DiskResizeRequest>,
}

/// The response to `egress`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EgressResponse {
    pub vm_name: String,
    pub egress_policy: EgressPolicy,
}

/// The response to `ssh-key generate-api-key`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct GenerateAPIKeyResponse {
    pub label: String,

    /// The API key, for the Authorization header: Bearer \<token\>.
    pub token: String,

    /// Where the key works: exe.dev's API, or one VM's HTTPS endpoints.
    pub namespace: String,

    /// The fingerprint of the key's SSH key, as in `ssh-key list`.
    pub fingerprint: String,

    /// When the key expires, in RFC 3339 format; absent if it does not.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub expires_at: Option<String>,

    /// The CIDR ranges the key can be used from; absent if from anywhere.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub ips: Option<Vec<String>>,
}

/// The response to `comment`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct CommentResponse {
    pub vm_name: String,

    /// The comment as stored; "" when cleared.
    pub comment: String,
}

/// The response to `tag`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct TagResponse {
    pub vm_name: String,

    /// All of the VM's tags after the change.
    pub tags: Vec<String>,
}

/// `domain add` registered the domain.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct DomainAdded {
    pub vm_name: String,
    pub domain: String,
    pub wildcard: bool,

    /// With a wildcard certificate: the base it covers.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub wildcard_base: Option<String>,

    /// For a `*.<base>` pattern.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub pattern: Option<bool>,
}

/// `domain add` found that the domain's DNS does not point to the VM. Nothing
/// was added: point it at `expected` and run the command again.
///
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct DomainAddDNSMismatch {
    pub error: String,
    pub vm_name: String,
    pub domain: String,
    pub expected: String,
}

/// `domain add --wildcard` found no ACME challenge delegation. Nothing was
/// added: CNAME `delegation_name` to `delegation_target` and run the command
/// again.
///
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct DomainAddDelegationMissing {
    pub error: String,
    pub vm_name: String,
    pub domain: String,
    pub wildcard_base: String,
    pub delegation_name: String,
    pub delegation_target: String,
}

/// The response to `domain add`. A DNS problem is not an exception: the
/// command succeeds with an `error` field, so check `"error" in result`.
///
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
#[non_exhaustive]
pub enum DomainAddResponse {
    /// A [`DomainAddDelegationMissing`].
    DomainAddDelegationMissing(DomainAddDelegationMissing),
    /// A [`DomainAddDNSMismatch`].
    DomainAddDNSMismatch(DomainAddDNSMismatch),
    /// A [`DomainAdded`].
    DomainAdded(DomainAdded),
    /// A response this SDK does not know.
    Other(serde_json::Value),
}

/// The response to `domain rm`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct DomainRmResponse {
    pub vm_name: String,
    pub domain: String,
    pub removed: bool,
}

/// An email share in `share show`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ShareUser {
    pub email: String,

    /// "pending" until the recipient has an account.
    pub status: ShareUserStatus,

    /// RFC 3339, or "" when unknown.
    pub invited_at: String,

    /// "root" also grants shell access.
    pub share_level: ShareLevel,
}

/// A share link in `share show`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ShareLink {
    pub token: String,

    /// RFC 3339, or "" when unknown.
    pub created_at: String,
    pub use_count: i64,

    /// RFC 3339; null until first use.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub last_used_at: Option<String>,
}

/// A team share in `share show`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ShareTeam {
    pub team_id: String,
    pub team_name: String,
}

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ShareSSOClaim {
    pub name: String,
    pub value: String,
}

/// A VM's SSO share in `share show`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ShareSSO {
    pub active: bool,

    /// The identity provider, while active.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub issuer: Option<String>,
    pub claim: ShareSSOClaim,
}

/// The response to `share show`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ShareShowResponse {
    pub vm_name: String,

    /// Whether the VM's web port is public or requires a login.
    pub status: Visibility,

    /// The port inside the VM that the web URL forwards to.
    pub port: i64,
    pub url: String,
    pub users: Vec<ShareUser>,
    pub links: Vec<ShareLink>,
    pub teams: Vec<ShareTeam>,

    /// team\_ssh && team\_shelley.
    pub team_access: bool,
    pub team_ssh: bool,
    pub team_shelley: bool,

    /// Present, and true, when exe.dev support has root access.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub support_has_root: Option<bool>,

    /// Present, and true, when the proxy forwards the SSO access token.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub forward_access_token: Option<bool>,

    /// Present when the VM has an SSO share.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub sso: Option<ShareSSO>,
}

/// `share port <vm>` without a port: the VM's web route.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ShareRoute {
    pub vm_name: String,

    /// The port inside the VM that the web URL forwards to.
    pub port: i64,
    pub share: Visibility,
}

/// The changed route: `share port <vm> <port>`, `share set-public`, `share set-private`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ShareRouteUpdate {
    pub vm_name: String,

    /// The port inside the VM that the web URL forwards to.
    pub port: i64,
    pub share: Visibility,
    pub status: String,

    /// team\_ssh && team\_shelley.
    pub team_access: bool,
    pub team_ssh: bool,
    pub team_shelley: bool,
}

/// The response to `share port`: the route, or the updated route when given a port.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
#[non_exhaustive]
pub enum SharePortResponse {
    /// A [`ShareRouteUpdate`].
    ShareRouteUpdate(ShareRouteUpdate),
    /// A [`ShareRoute`].
    ShareRoute(ShareRoute),
    /// A response this SDK does not know.
    Other(serde_json::Value),
}

/// `share add <vm> <email>`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ShareInvite {
    pub status: String,
    pub vm_name: String,
    pub shared_with: String,
    pub url: String,

    /// "Invitation sent", or "Share created" when no email was sent.
    pub message: String,
}

/// `share add <vm> team` or `share remove <vm> team`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ShareTeamChange {
    pub status: String,
    pub vm_name: String,
    pub team_name: String,
}

/// A share change described in words: `share remove <vm> <email>`,
/// `share remove-link`, and `share add <vm> team` when already shared.
///
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ShareMessage {
    pub status: String,
    pub vm_name: String,
    pub message: String,
}

/// `share add|remove <vm> <email> --root`: the recipient's resulting access.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ShareRootChange {
    pub status: String,
    pub vm_name: String,
    pub shared_with: String,

    /// "root" after `share add`; "web" after `share remove`, which keeps web access.
    pub share_level: ShareLevel,
}

/// `share add|remove <vm> team --root`: the team's resulting access.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ShareTeamRootChange {
    pub status: String,
    pub vm_name: String,
    pub team_access: bool,
    pub team_ssh: bool,
    pub team_shelley: bool,
}

/// The response to `share add`, which depends on its arguments.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
#[non_exhaustive]
pub enum ShareAddResponse {
    /// A [`ShareInvite`].
    ShareInvite(ShareInvite),
    /// A [`ShareTeamRootChange`].
    ShareTeamRootChange(ShareTeamRootChange),
    /// A [`ShareRootChange`].
    ShareRootChange(ShareRootChange),
    /// A [`ShareTeamChange`].
    ShareTeamChange(ShareTeamChange),
    /// A [`ShareMessage`].
    ShareMessage(ShareMessage),
    /// A response this SDK does not know.
    Other(serde_json::Value),
}

/// The response to `share remove`, which depends on its arguments.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
#[non_exhaustive]
pub enum ShareRemoveResponse {
    /// A [`ShareTeamRootChange`].
    ShareTeamRootChange(ShareTeamRootChange),
    /// A [`ShareRootChange`].
    ShareRootChange(ShareRootChange),
    /// A [`ShareTeamChange`].
    ShareTeamChange(ShareTeamChange),
    /// A [`ShareMessage`].
    ShareMessage(ShareMessage),
    /// A response this SDK does not know.
    Other(serde_json::Value),
}

/// The response to `share add-link`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ShareLinkCreated {
    pub status: String,
    pub vm_name: String,
    pub token: String,

    /// The link to give out.
    pub url: String,
}

/// `share receive-email <vm>` without on/off: the current settings.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ReceiveEmailStatus {
    pub vm_name: String,
    pub email_enabled: bool,
    pub email_address: String,

    /// Who the VM may reply to.
    pub reply_policy: ReplyPolicy,
}

/// `share receive-email <vm> on|off`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ReceiveEmailChange {
    pub status: String,
    pub vm_name: String,
    pub email_enabled: bool,

    /// Present when enabled.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub email_address: Option<String>,

    /// Who the VM may reply to.
    pub reply_policy: ReplyPolicy,
}

/// The response to `share receive-email`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
#[non_exhaustive]
pub enum ShareReceiveEmailResponse {
    /// A [`ReceiveEmailChange`].
    ReceiveEmailChange(ReceiveEmailChange),
    /// A [`ReceiveEmailStatus`].
    ReceiveEmailStatus(ReceiveEmailStatus),
    /// A response this SDK does not know.
    Other(serde_json::Value),
}

/// `shelley install` installed Shelley and restarted it.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ShelleyInstalled {
    pub vm_name: String,
    pub status: String,

    /// Where any previous binary was backed up to; reported even if there was none.
    pub backup: String,
}

/// `shelley install` did nothing: the VM's image did not opt into Shelley.
/// Install it by hand from `download_url`.
///
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ShelleyNotInstalled {
    pub error: String,
    pub message: String,
    pub download_url: String,
    pub arch: String,
}

/// The response to `shelley install`. Check `"error" in result`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
#[non_exhaustive]
pub enum ShelleyInstallResponse {
    /// A [`ShelleyNotInstalled`].
    ShelleyNotInstalled(ShelleyNotInstalled),
    /// A [`ShelleyInstalled`].
    ShelleyInstalled(ShelleyInstalled),
    /// A response this SDK does not know.
    Other(serde_json::Value),
}

/// What a VM may reach: "all" of the internet, or only exe.dev's "integrations".
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum EgressPolicy {
    /// `integrations`
    Integrations,
    /// `all`
    All,
    /// A value this SDK does not know.
    Other(String),
}

impl EgressPolicy {
    /// The value, as exe.dev writes it.
    pub fn as_str(&self) -> &str {
        match self {
            Self::Integrations => "integrations",
            Self::All => "all",
            Self::Other(s) => s,
        }
    }
}

impl std::fmt::Display for EgressPolicy {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.as_str())
    }
}

impl From<&str> for EgressPolicy {
    fn from(s: &str) -> Self {
        match s {
            "integrations" => Self::Integrations,
            "all" => Self::All,
            _ => Self::Other(s.to_string()),
        }
    }
}

impl Serialize for EgressPolicy {
    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
        s.serialize_str(self.as_str())
    }
}

impl<'de> Deserialize<'de> for EgressPolicy {
    fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
        Ok(Self::from(String::deserialize(d)?.as_str()))
    }
}

/// One of `pending`, `approved`, `rejected`, `superseded`, `cancelled`.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum DiskResizeStatus {
    /// `pending`
    Pending,
    /// `approved`
    Approved,
    /// `rejected`
    Rejected,
    /// `superseded`
    Superseded,
    /// `cancelled`
    Cancelled,
    /// A value this SDK does not know.
    Other(String),
}

impl DiskResizeStatus {
    /// The value, as exe.dev writes it.
    pub fn as_str(&self) -> &str {
        match self {
            Self::Pending => "pending",
            Self::Approved => "approved",
            Self::Rejected => "rejected",
            Self::Superseded => "superseded",
            Self::Cancelled => "cancelled",
            Self::Other(s) => s,
        }
    }
}

impl std::fmt::Display for DiskResizeStatus {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.as_str())
    }
}

impl From<&str> for DiskResizeStatus {
    fn from(s: &str) -> Self {
        match s {
            "pending" => Self::Pending,
            "approved" => Self::Approved,
            "rejected" => Self::Rejected,
            "superseded" => Self::Superseded,
            "cancelled" => Self::Cancelled,
            _ => Self::Other(s.to_string()),
        }
    }
}

impl Serialize for DiskResizeStatus {
    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
        s.serialize_str(self.as_str())
    }
}

impl<'de> Deserialize<'de> for DiskResizeStatus {
    fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
        Ok(Self::from(String::deserialize(d)?.as_str()))
    }
}

/// One of `pending`, `active`.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ShareUserStatus {
    /// `pending`
    Pending,
    /// `active`
    Active,
    /// A value this SDK does not know.
    Other(String),
}

impl ShareUserStatus {
    /// The value, as exe.dev writes it.
    pub fn as_str(&self) -> &str {
        match self {
            Self::Pending => "pending",
            Self::Active => "active",
            Self::Other(s) => s,
        }
    }
}

impl std::fmt::Display for ShareUserStatus {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.as_str())
    }
}

impl From<&str> for ShareUserStatus {
    fn from(s: &str) -> Self {
        match s {
            "pending" => Self::Pending,
            "active" => Self::Active,
            _ => Self::Other(s.to_string()),
        }
    }
}

impl Serialize for ShareUserStatus {
    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
        s.serialize_str(self.as_str())
    }
}

impl<'de> Deserialize<'de> for ShareUserStatus {
    fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
        Ok(Self::from(String::deserialize(d)?.as_str()))
    }
}

/// One of `web`, `root`.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ShareLevel {
    /// `web`
    Web,
    /// `root`
    Root,
    /// A value this SDK does not know.
    Other(String),
}

impl ShareLevel {
    /// The value, as exe.dev writes it.
    pub fn as_str(&self) -> &str {
        match self {
            Self::Web => "web",
            Self::Root => "root",
            Self::Other(s) => s,
        }
    }
}

impl std::fmt::Display for ShareLevel {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.as_str())
    }
}

impl From<&str> for ShareLevel {
    fn from(s: &str) -> Self {
        match s {
            "web" => Self::Web,
            "root" => Self::Root,
            _ => Self::Other(s.to_string()),
        }
    }
}

impl Serialize for ShareLevel {
    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
        s.serialize_str(self.as_str())
    }
}

impl<'de> Deserialize<'de> for ShareLevel {
    fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
        Ok(Self::from(String::deserialize(d)?.as_str()))
    }
}

/// One of `public`, `private`.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Visibility {
    /// `public`
    Public,
    /// `private`
    Private,
    /// A value this SDK does not know.
    Other(String),
}

impl Visibility {
    /// The value, as exe.dev writes it.
    pub fn as_str(&self) -> &str {
        match self {
            Self::Public => "public",
            Self::Private => "private",
            Self::Other(s) => s,
        }
    }
}

impl std::fmt::Display for Visibility {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.as_str())
    }
}

impl From<&str> for Visibility {
    fn from(s: &str) -> Self {
        match s {
            "public" => Self::Public,
            "private" => Self::Private,
            _ => Self::Other(s.to_string()),
        }
    }
}

impl Serialize for Visibility {
    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
        s.serialize_str(self.as_str())
    }
}

impl<'de> Deserialize<'de> for Visibility {
    fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
        Ok(Self::from(String::deserialize(d)?.as_str()))
    }
}

/// One of `all`, `known`, `owner`, `none`.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ReplyPolicy {
    /// `all`
    All,
    /// `known`
    Known,
    /// `owner`
    Owner,
    /// `none`
    None,
    /// A value this SDK does not know.
    Other(String),
}

impl ReplyPolicy {
    /// The value, as exe.dev writes it.
    pub fn as_str(&self) -> &str {
        match self {
            Self::All => "all",
            Self::Known => "known",
            Self::Owner => "owner",
            Self::None => "none",
            Self::Other(s) => s,
        }
    }
}

impl std::fmt::Display for ReplyPolicy {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(self.as_str())
    }
}

impl From<&str> for ReplyPolicy {
    fn from(s: &str) -> Self {
        match s {
            "all" => Self::All,
            "known" => Self::Known,
            "owner" => Self::Owner,
            "none" => Self::None,
            _ => Self::Other(s.to_string()),
        }
    }
}

impl Serialize for ReplyPolicy {
    fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
        s.serialize_str(self.as_str())
    }
}

impl<'de> Deserialize<'de> for ReplyPolicy {
    fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
        Ok(Self::from(String::deserialize(d)?.as_str()))
    }
}

/// A boolean the server writes as the string "true" or "false".
mod bool_string {
        use serde::{Deserialize, Deserializer, Serializer};

        pub fn serialize<S: Serializer>(value: &bool, s: S) -> Result<S::Ok, S::Error> {
                s.serialize_str(if *value { "true" } else { "false" })
            }

            pub fn deserialize<'de, D: Deserializer<'de>>(d: D) -> Result<bool, D::Error> {
                    #[derive(Deserialize)]
                    #[serde(untagged)]
                    enum Repr {
                            Bool(bool),
                            String(String),
                        }
                        match Repr::deserialize(d)? {
                                Repr::Bool(b) => Ok(b),
                                Repr::String(s) if s == "true" => Ok(true),
                                Repr::String(s) if s == "false" => Ok(false),
                                Repr::String(s) => Err(serde::de::Error::custom(format!("expected \"true\" or \"false\", not {s:?}"))),
                            }
                        }
                }