spiral-sdk 0.1.9

Rust SDK for Spiral resource and table APIs
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
// Generated by tools/service-contracts/rust.py. Do not edit.
#![doc = "Generated transport-independent contract objects."]

use std::collections::BTreeMap;
use std::error::Error as StdError;
use std::fmt::{self, Display, Formatter};

use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_json::Value;
use spiral_contract::error::{ErrorEnvelope, ServiceError};
use spiral_contract::strict::{DeserializeStrict, Strict};
use uuid::Uuid;

/// A role granted to a principal in one Project.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Grant {
    /// Contract field conditions.
    #[serde(rename = "conditions")]
    pub conditions: BTreeMap<String, String>,
    /// Contract field id.
    #[serde(rename = "id")]
    pub id: String,
    /// Contract field principal.
    #[serde(rename = "principal")]
    pub principal: String,
    /// Contract field projectId.
    #[serde(rename = "projectId")]
    pub project_id: String,
    /// Contract field role.
    #[serde(rename = "role")]
    pub role: Role,
}
impl<'de> DeserializeStrict<'de> for Grant {
    fn deserialize_strict<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        #[derive(Deserialize)]
        #[serde(deny_unknown_fields)]
        struct __Wire {
            #[serde(rename = "conditions")]
            conditions: Strict<BTreeMap<String, String>>,
            #[serde(rename = "id")]
            id: Strict<String>,
            #[serde(rename = "principal")]
            principal: Strict<String>,
            #[serde(rename = "projectId")]
            project_id: Strict<String>,
            #[serde(rename = "role")]
            role: Strict<Role>,
        }
        let wire = __Wire::deserialize(deserializer)?;
        Ok(Self {
            conditions: wire.conditions.0,
            id: wire.id.0,
            principal: wire.principal.0,
            project_id: wire.project_id.0,
            role: wire.role.0,
        })
    }
}

/// One live page of Grant records, ordered by ID. Continuations expire after one hour and bind the
/// credential, operation, filters and page size.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GrantPage {
    /// Contract field items.
    #[serde(rename = "items")]
    pub items: Vec<Grant>,
    /// Contract field nextPageToken.
    #[serde(rename = "nextPageToken")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub next_page_token: Option<String>,
}
impl<'de> DeserializeStrict<'de> for GrantPage {
    fn deserialize_strict<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        #[derive(Deserialize)]
        #[serde(deny_unknown_fields)]
        struct __Wire {
            #[serde(rename = "items")]
            items: Strict<Vec<Grant>>,
            #[serde(rename = "nextPageToken")]
            #[serde(default)]
            next_page_token: Strict<Option<String>>,
        }
        let wire = __Wire::deserialize(deserializer)?;
        Ok(Self {
            items: wire.items.0,
            next_page_token: wire.next_page_token.0,
        })
    }
}

/// The created Project role grant.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GrantResponse {
    /// Contract field grant.
    #[serde(rename = "grant")]
    pub grant: Grant,
}
impl<'de> DeserializeStrict<'de> for GrantResponse {
    fn deserialize_strict<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        #[derive(Deserialize)]
        #[serde(deny_unknown_fields)]
        struct __Wire {
            #[serde(rename = "grant")]
            grant: Strict<Grant>,
        }
        let wire = __Wire::deserialize(deserializer)?;
        Ok(Self {
            grant: wire.grant.0,
        })
    }
}

/// A Project role and the principal receiving it.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct GrantRoleRequest {
    /// Contract field principal.
    #[serde(rename = "principal")]
    pub principal: Principal,
    /// Contract field role.
    #[serde(rename = "role")]
    pub role: Role,
}
impl<'de> DeserializeStrict<'de> for GrantRoleRequest {
    fn deserialize_strict<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        #[derive(Deserialize)]
        #[serde(deny_unknown_fields)]
        struct __Wire {
            #[serde(rename = "principal")]
            principal: Strict<Principal>,
            #[serde(rename = "role")]
            role: Strict<Role>,
        }
        let wire = __Wire::deserialize(deserializer)?;
        Ok(Self {
            principal: wire.principal.0,
            role: wire.role.0,
        })
    }
}

/// One batch of resource permission edges reviewed together.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Installation {
    /// Contract field createdAt.
    #[serde(rename = "createdAt")]
    pub created_at: String,
    /// Contract field createdBy.
    #[serde(rename = "createdBy")]
    pub created_by: String,
    /// Contract field id.
    #[serde(rename = "id")]
    pub id: String,
    /// Contract field resourceMounts.
    #[serde(rename = "resourceMounts")]
    pub resource_mounts: Vec<ResourceMount>,
    /// Contract field source.
    #[serde(rename = "source")]
    pub source: String,
}
impl<'de> DeserializeStrict<'de> for Installation {
    fn deserialize_strict<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        #[derive(Deserialize)]
        #[serde(deny_unknown_fields)]
        struct __Wire {
            #[serde(rename = "createdAt")]
            created_at: Strict<String>,
            #[serde(rename = "createdBy")]
            created_by: Strict<String>,
            #[serde(rename = "id")]
            id: Strict<String>,
            #[serde(rename = "resourceMounts")]
            resource_mounts: Strict<Vec<ResourceMount>>,
            #[serde(rename = "source")]
            source: Strict<String>,
        }
        let wire = __Wire::deserialize(deserializer)?;
        Ok(Self {
            created_at: wire.created_at.0,
            created_by: wire.created_by.0,
            id: wire.id.0,
            resource_mounts: wire.resource_mounts.0,
            source: wire.source.0,
        })
    }
}

/// The installation and its resource permission edges.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct InstallationResponse {
    /// Contract field installation.
    #[serde(rename = "installation")]
    pub installation: Installation,
}
impl<'de> DeserializeStrict<'de> for InstallationResponse {
    fn deserialize_strict<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        #[derive(Deserialize)]
        #[serde(deny_unknown_fields)]
        struct __Wire {
            #[serde(rename = "installation")]
            installation: Strict<Installation>,
        }
        let wire = __Wire::deserialize(deserializer)?;
        Ok(Self {
            installation: wire.installation.0,
        })
    }
}

/// Continuation and optional exact principal-address filter. Page size defaults to 100 and must be
/// 1..=1000. Continuations expire after one hour and bind the credential, filters and page size.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ListGrantsRequest {
    /// Contract field pageSize.
    #[serde(rename = "pageSize")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub page_size: Option<u32>,
    /// Contract field pageToken.
    #[serde(rename = "pageToken")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub page_token: Option<String>,
    /// Contract field principal.
    #[serde(rename = "principal")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub principal: Option<String>,
}
impl<'de> DeserializeStrict<'de> for ListGrantsRequest {
    fn deserialize_strict<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        #[derive(Deserialize)]
        #[serde(deny_unknown_fields)]
        struct __Wire {
            #[serde(rename = "pageSize")]
            #[serde(default)]
            page_size: Strict<Option<u32>>,
            #[serde(rename = "pageToken")]
            #[serde(default)]
            page_token: Strict<Option<String>>,
            #[serde(rename = "principal")]
            #[serde(default)]
            principal: Strict<Option<String>>,
        }
        let wire = __Wire::deserialize(deserializer)?;
        Ok(Self {
            page_size: wire.page_size.0,
            page_token: wire.page_token.0,
            principal: wire.principal.0,
        })
    }
}

/// Whether to approve or reject a requested resource permission edge.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum MountDecision {
    /// A known contract value.
    Approve,
    /// A known contract value.
    Reject,
    /// A value introduced by a newer server.
    Unknown(String),
}
impl Serialize for MountDecision {
    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        serializer.serialize_str(match self {
            Self::Approve => "approve",
            Self::Reject => "reject",
            Self::Unknown(value) => value,
        })
    }
}
impl<'de> Deserialize<'de> for MountDecision {
    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        Ok(match String::deserialize(deserializer)?.as_str() {
            "approve" => Self::Approve,
            "reject" => Self::Reject,
            value => Self::Unknown(value.to_owned()),
        })
    }
}
impl<'de> DeserializeStrict<'de> for MountDecision {
    fn deserialize_strict<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        #[derive(Deserialize)]
        enum __Known {
            #[serde(rename = "approve")]
            Approve,
            #[serde(rename = "reject")]
            Reject,
        }
        Ok(match __Known::deserialize(deserializer)? {
            __Known::Approve => Self::Approve,
            __Known::Reject => Self::Reject,
        })
    }
}

/// Lifecycle status of a resource permission edge.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum MountStatus {
    /// A known contract value.
    Requested,
    /// A known contract value.
    Approved,
    /// A known contract value.
    Rejected,
    /// A known contract value.
    Revoked,
    /// A known contract value.
    Detached,
    /// A value introduced by a newer server.
    Unknown(String),
}
impl Serialize for MountStatus {
    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        serializer.serialize_str(match self {
            Self::Requested => "requested",
            Self::Approved => "approved",
            Self::Rejected => "rejected",
            Self::Revoked => "revoked",
            Self::Detached => "detached",
            Self::Unknown(value) => value,
        })
    }
}
impl<'de> Deserialize<'de> for MountStatus {
    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        Ok(match String::deserialize(deserializer)?.as_str() {
            "requested" => Self::Requested,
            "approved" => Self::Approved,
            "rejected" => Self::Rejected,
            "revoked" => Self::Revoked,
            "detached" => Self::Detached,
            value => Self::Unknown(value.to_owned()),
        })
    }
}
impl<'de> DeserializeStrict<'de> for MountStatus {
    fn deserialize_strict<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        #[derive(Deserialize)]
        enum __Known {
            #[serde(rename = "requested")]
            Requested,
            #[serde(rename = "approved")]
            Approved,
            #[serde(rename = "rejected")]
            Rejected,
            #[serde(rename = "revoked")]
            Revoked,
            #[serde(rename = "detached")]
            Detached,
        }
        Ok(match __Known::deserialize(deserializer)? {
            __Known::Requested => Self::Requested,
            __Known::Approved => Self::Approved,
            __Known::Rejected => Self::Rejected,
            __Known::Revoked => Self::Revoked,
            __Known::Detached => Self::Detached,
        })
    }
}

/// Match an Organization membership role.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct OrganizationRolePrincipal {
    /// Contract field organizationId.
    #[serde(rename = "organizationId")]
    pub organization_id: String,
    /// Contract field role.
    #[serde(rename = "role")]
    pub role: String,
}
impl<'de> DeserializeStrict<'de> for OrganizationRolePrincipal {
    fn deserialize_strict<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        #[derive(Deserialize)]
        #[serde(deny_unknown_fields)]
        struct __Wire {
            #[serde(rename = "organizationId")]
            organization_id: Strict<String>,
            #[serde(rename = "role")]
            role: Strict<String>,
        }
        let wire = __Wire::deserialize(deserializer)?;
        Ok(Self {
            organization_id: wire.organization_id.0,
            role: wire.role.0,
        })
    }
}

/// Match a user acting in an Organization.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct OrganizationUserPrincipal {
    /// Contract field organizationId.
    #[serde(rename = "organizationId")]
    pub organization_id: String,
    /// Contract field userId.
    #[serde(rename = "userId")]
    pub user_id: String,
}
impl<'de> DeserializeStrict<'de> for OrganizationUserPrincipal {
    fn deserialize_strict<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        #[derive(Deserialize)]
        #[serde(deny_unknown_fields)]
        struct __Wire {
            #[serde(rename = "organizationId")]
            organization_id: Strict<String>,
            #[serde(rename = "userId")]
            user_id: Strict<String>,
        }
        let wire = __Wire::deserialize(deserializer)?;
        Ok(Self {
            organization_id: wire.organization_id.0,
            user_id: wire.user_id.0,
        })
    }
}

/// The identity or membership role that receives a Project role.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Principal {
    /// A known union arm.
    OrganizationRole(OrganizationRolePrincipal),
    /// A known union arm.
    OrganizationUser(OrganizationUserPrincipal),
    /// A known union arm.
    Workload(WorkloadPrincipal),
    /// An unknown discriminator and its complete wire object.
    Unknown { tag: String, value: Value },
}
impl Serialize for Principal {
    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        match self {
            Self::OrganizationRole(value) => {
                let mut object = serde_json::Map::new();
                object.insert("type".into(), Value::String("organizationRole".into()));
                object.insert(
                    "organizationRole".into(),
                    serde_json::to_value(value).map_err(serde::ser::Error::custom)?,
                );
                Value::Object(object).serialize(serializer)
            }
            Self::OrganizationUser(value) => {
                let mut object = serde_json::Map::new();
                object.insert("type".into(), Value::String("organizationUser".into()));
                object.insert(
                    "organizationUser".into(),
                    serde_json::to_value(value).map_err(serde::ser::Error::custom)?,
                );
                Value::Object(object).serialize(serializer)
            }
            Self::Workload(value) => {
                let mut object = serde_json::Map::new();
                object.insert("type".into(), Value::String("workload".into()));
                object.insert(
                    "workload".into(),
                    serde_json::to_value(value).map_err(serde::ser::Error::custom)?,
                );
                Value::Object(object).serialize(serializer)
            }
            Self::Unknown { tag, value } => {
                if value.get("type").and_then(Value::as_str) != Some(tag.as_str()) {
                    return Err(serde::ser::Error::custom(
                        "unknown union discriminator mismatch",
                    ));
                }
                value.serialize(serializer)
            }
        }
    }
}
impl<'de> Deserialize<'de> for Principal {
    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        let value = Value::deserialize(deserializer)?;
        let tag = value
            .get("type")
            .and_then(Value::as_str)
            .ok_or_else(|| serde::de::Error::custom("union requires type"))?;
        match tag {
            "organizationRole" => Ok(Self::OrganizationRole(
                serde_json::from_value(
                    value
                        .get("organizationRole")
                        .cloned()
                        .ok_or_else(|| serde::de::Error::custom("union requires matching arm"))?,
                )
                .map_err(serde::de::Error::custom)?,
            )),
            "organizationUser" => Ok(Self::OrganizationUser(
                serde_json::from_value(
                    value
                        .get("organizationUser")
                        .cloned()
                        .ok_or_else(|| serde::de::Error::custom("union requires matching arm"))?,
                )
                .map_err(serde::de::Error::custom)?,
            )),
            "workload" => Ok(Self::Workload(
                serde_json::from_value(
                    value
                        .get("workload")
                        .cloned()
                        .ok_or_else(|| serde::de::Error::custom("union requires matching arm"))?,
                )
                .map_err(serde::de::Error::custom)?,
            )),
            tag => Ok(Self::Unknown {
                tag: tag.to_owned(),
                value,
            }),
        }
    }
}
impl<'de> DeserializeStrict<'de> for Principal {
    fn deserialize_strict<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        #[derive(Deserialize)]
        enum __Tag0 {
            #[serde(rename = "organizationRole")]
            Value,
        }
        #[derive(Deserialize)]
        #[serde(deny_unknown_fields)]
        struct __Arm0 {
            #[serde(rename = "type")]
            _tag: __Tag0,
            #[serde(rename = "organizationRole")]
            value: Strict<OrganizationRolePrincipal>,
        }
        #[derive(Deserialize)]
        enum __Tag1 {
            #[serde(rename = "organizationUser")]
            Value,
        }
        #[derive(Deserialize)]
        #[serde(deny_unknown_fields)]
        struct __Arm1 {
            #[serde(rename = "type")]
            _tag: __Tag1,
            #[serde(rename = "organizationUser")]
            value: Strict<OrganizationUserPrincipal>,
        }
        #[derive(Deserialize)]
        enum __Tag2 {
            #[serde(rename = "workload")]
            Value,
        }
        #[derive(Deserialize)]
        #[serde(deny_unknown_fields)]
        struct __Arm2 {
            #[serde(rename = "type")]
            _tag: __Tag2,
            #[serde(rename = "workload")]
            value: Strict<WorkloadPrincipal>,
        }
        #[derive(Deserialize)]
        #[serde(untagged)]
        enum __Known {
            OrganizationRole(Box<__Arm0>),
            OrganizationUser(Box<__Arm1>),
            Workload(Box<__Arm2>),
        }
        Ok(match __Known::deserialize(deserializer)? {
            __Known::OrganizationRole(arm) => Self::OrganizationRole(arm.value.0),
            __Known::OrganizationUser(arm) => Self::OrganizationUser(arm.value.0),
            __Known::Workload(arm) => Self::Workload(arm.value.0),
        })
    }
}

/// A permission edge between two resources, with its decision and audit metadata.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ResourceMount {
    /// Contract field createdAt.
    #[serde(rename = "createdAt")]
    pub created_at: String,
    /// Contract field createdBy.
    #[serde(rename = "createdBy")]
    pub created_by: String,
    /// Contract field id.
    #[serde(rename = "id")]
    pub id: String,
    /// Contract field installationId.
    #[serde(rename = "installationId")]
    pub installation_id: String,
    /// Contract field permission.
    #[serde(rename = "permission")]
    pub permission: String,
    /// Contract field source.
    #[serde(rename = "source")]
    pub source: String,
    /// Contract field status.
    #[serde(rename = "status")]
    pub status: MountStatus,
    /// Contract field statusChangedAt.
    #[serde(rename = "statusChangedAt")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub status_changed_at: Option<String>,
    /// Contract field statusChangedBy.
    #[serde(rename = "statusChangedBy")]
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub status_changed_by: Option<String>,
    /// Contract field target.
    #[serde(rename = "target")]
    pub target: String,
}
impl<'de> DeserializeStrict<'de> for ResourceMount {
    fn deserialize_strict<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        #[derive(Deserialize)]
        #[serde(deny_unknown_fields)]
        struct __Wire {
            #[serde(rename = "createdAt")]
            created_at: Strict<String>,
            #[serde(rename = "createdBy")]
            created_by: Strict<String>,
            #[serde(rename = "id")]
            id: Strict<String>,
            #[serde(rename = "installationId")]
            installation_id: Strict<String>,
            #[serde(rename = "permission")]
            permission: Strict<String>,
            #[serde(rename = "source")]
            source: Strict<String>,
            #[serde(rename = "status")]
            status: Strict<MountStatus>,
            #[serde(rename = "statusChangedAt")]
            #[serde(default)]
            status_changed_at: Strict<Option<String>>,
            #[serde(rename = "statusChangedBy")]
            #[serde(default)]
            status_changed_by: Strict<Option<String>>,
            #[serde(rename = "target")]
            target: Strict<String>,
        }
        let wire = __Wire::deserialize(deserializer)?;
        Ok(Self {
            created_at: wire.created_at.0,
            created_by: wire.created_by.0,
            id: wire.id.0,
            installation_id: wire.installation_id.0,
            permission: wire.permission.0,
            source: wire.source.0,
            status: wire.status.0,
            status_changed_at: wire.status_changed_at.0,
            status_changed_by: wire.status_changed_by.0,
            target: wire.target.0,
        })
    }
}

/// Decisions keyed by resource mount ID. Omitted edges remain requested.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ReviewRequest {
    /// Contract field decisions.
    #[serde(rename = "decisions")]
    pub decisions: BTreeMap<String, MountDecision>,
}
impl<'de> DeserializeStrict<'de> for ReviewRequest {
    fn deserialize_strict<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        #[derive(Deserialize)]
        #[serde(deny_unknown_fields)]
        struct __Wire {
            #[serde(rename = "decisions")]
            decisions: Strict<BTreeMap<String, MountDecision>>,
        }
        let wire = __Wire::deserialize(deserializer)?;
        Ok(Self {
            decisions: wire.decisions.0,
        })
    }
}

/// The resource permission edges transitioned by this decision.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ReviewResponse {
    /// Contract field resourceMounts.
    #[serde(rename = "resourceMounts")]
    pub resource_mounts: Vec<ResourceMount>,
}
impl<'de> DeserializeStrict<'de> for ReviewResponse {
    fn deserialize_strict<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        #[derive(Deserialize)]
        #[serde(deny_unknown_fields)]
        struct __Wire {
            #[serde(rename = "resourceMounts")]
            resource_mounts: Strict<Vec<ResourceMount>>,
        }
        let wire = __Wire::deserialize(deserializer)?;
        Ok(Self {
            resource_mounts: wire.resource_mounts.0,
        })
    }
}

/// Project authorization role.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Role {
    /// A known contract value.
    Admin,
    /// A known contract value.
    Editor,
    /// A known contract value.
    Viewer,
    /// A value introduced by a newer server.
    Unknown(String),
}
impl Serialize for Role {
    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
        serializer.serialize_str(match self {
            Self::Admin => "admin",
            Self::Editor => "editor",
            Self::Viewer => "viewer",
            Self::Unknown(value) => value,
        })
    }
}
impl<'de> Deserialize<'de> for Role {
    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        Ok(match String::deserialize(deserializer)?.as_str() {
            "admin" => Self::Admin,
            "editor" => Self::Editor,
            "viewer" => Self::Viewer,
            value => Self::Unknown(value.to_owned()),
        })
    }
}
impl<'de> DeserializeStrict<'de> for Role {
    fn deserialize_strict<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        #[derive(Deserialize)]
        enum __Known {
            #[serde(rename = "admin")]
            Admin,
            #[serde(rename = "editor")]
            Editor,
            #[serde(rename = "viewer")]
            Viewer,
        }
        Ok(match __Known::deserialize(deserializer)? {
            __Known::Admin => Self::Admin,
            __Known::Editor => Self::Editor,
            __Known::Viewer => Self::Viewer,
        })
    }
}

/// Match a Workload identity.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct WorkloadPrincipal {
    /// Contract field workloadId.
    #[serde(rename = "workloadId")]
    pub workload_id: String,
}
impl<'de> DeserializeStrict<'de> for WorkloadPrincipal {
    fn deserialize_strict<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
        #[derive(Deserialize)]
        #[serde(deny_unknown_fields)]
        struct __Wire {
            #[serde(rename = "workloadId")]
            workload_id: Strict<String>,
        }
        let wire = __Wire::deserialize(deserializer)?;
        Ok(Self {
            workload_id: wire.workload_id.0,
        })
    }
}

/// Typed errors declared by this service contract.
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum AuthorizationError {
    /// Authorization:Conflict.
    Conflict { reason: String },
    /// Authorization:InvalidArgument.
    InvalidArgument { reason: String },
    /// Authorization:LimitReached.
    LimitReached { reason: String },
    /// Authorization:NotFound.
    NotFound { resource: String },
}
impl AuthorizationError {
    /// HTTP status for this declared error.
    pub fn status(&self) -> u16 {
        match self {
            Self::Conflict { .. } => 409,
            Self::InvalidArgument { .. } => 400,
            Self::LimitReached { .. } => 412,
            Self::NotFound { .. } => 404,
        }
    }
    /// Serialize only contract-declared error parameters.
    pub fn envelope(&self, instance: String) -> ErrorEnvelope {
        match self {
            Self::Conflict { reason } => {
                let mut envelope =
                    ErrorEnvelope::new("CONFLICT", "Authorization:Conflict", instance);
                envelope
                    .parameters
                    .insert("reason".into(), reason.to_string());
                envelope
            }
            Self::InvalidArgument { reason } => {
                let mut envelope = ErrorEnvelope::new(
                    "INVALID_ARGUMENT",
                    "Authorization:InvalidArgument",
                    instance,
                );
                envelope
                    .parameters
                    .insert("reason".into(), reason.to_string());
                envelope
            }
            Self::LimitReached { reason } => {
                let mut envelope = ErrorEnvelope::new(
                    "FAILED_PRECONDITION",
                    "Authorization:LimitReached",
                    instance,
                );
                envelope
                    .parameters
                    .insert("reason".into(), reason.to_string());
                envelope
            }
            Self::NotFound { resource } => {
                let mut envelope =
                    ErrorEnvelope::new("NOT_FOUND", "Authorization:NotFound", instance);
                envelope
                    .parameters
                    .insert("resource".into(), resource.to_string());
                envelope
            }
        }
    }
    /// Decode a declared error and its typed error parameters.
    pub fn decode_envelope(envelope: &ErrorEnvelope) -> Option<Self> {
        if envelope.error_instance_id.len() != 36
            || Uuid::parse_str(&envelope.error_instance_id).is_err()
        {
            return None;
        }
        match envelope.error_name.as_str() {
            "Authorization:Conflict" => {
                if envelope.error_code != "CONFLICT" {
                    return None;
                }
                let reason = envelope.parameters.get("reason")?.clone();
                Some(Self::Conflict { reason })
            }
            "Authorization:InvalidArgument" => {
                if envelope.error_code != "INVALID_ARGUMENT" {
                    return None;
                }
                let reason = envelope.parameters.get("reason")?.clone();
                Some(Self::InvalidArgument { reason })
            }
            "Authorization:LimitReached" => {
                if envelope.error_code != "FAILED_PRECONDITION" {
                    return None;
                }
                let reason = envelope.parameters.get("reason")?.clone();
                Some(Self::LimitReached { reason })
            }
            "Authorization:NotFound" => {
                if envelope.error_code != "NOT_FOUND" {
                    return None;
                }
                let resource = envelope.parameters.get("resource")?.clone();
                Some(Self::NotFound { resource })
            }
            _ => None,
        }
    }
}
impl Display for AuthorizationError {
    fn fmt(&self, formatter: &mut Formatter<'_>) -> fmt::Result {
        match self {
            Self::Conflict { reason } => {
                write!(formatter, "Authorization:Conflict (reason: {})", reason)
            }
            Self::InvalidArgument { reason } => write!(
                formatter,
                "Authorization:InvalidArgument (reason: {})",
                reason
            ),
            Self::LimitReached { reason } => {
                write!(formatter, "Authorization:LimitReached (reason: {})", reason)
            }
            Self::NotFound { resource } => {
                write!(formatter, "Authorization:NotFound (resource: {})", resource)
            }
        }
    }
}
impl StdError for AuthorizationError {}
impl ServiceError for AuthorizationError {
    fn to_envelope(&self, instance: String) -> ErrorEnvelope {
        Self::envelope(self, instance)
    }
    fn from_envelope(envelope: &ErrorEnvelope) -> Option<Self> {
        Self::decode_envelope(envelope)
    }
}
#[automatically_derived]
impl Default for ListGrantsRequest {
    fn default() -> Self {
        Self {
            page_size: None,
            page_token: None,
            principal: None,
        }
    }
}