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
// @generated by sylphx-gen. Do not edit.
//! `sylphx.broker.v1`.
#![allow(clippy::all)]
/// The request of CreateTrustPolicy.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct CreateTrustPolicyRequest {
/// The org to create in.
///
/// Field behavior: `required`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub parent: String,
/// The trust policy to create; only spec and caller-writable metadata are read.
///
/// Field behavior: `required`.
#[serde(
default,
skip_serializing_if = "Option::is_none",
alias = "trustPolicy"
)]
pub trust_policy: Option<TrustPolicy>,
/// The id of the new trust policy, `^[a-z]([a-z0-9_-]{0,61}[a-z0-9])?$`; the server assigns one when
/// empty.
#[serde(
default,
skip_serializing_if = "crate::runtime::is_default",
alias = "trustPolicyId"
)]
pub trust_policy_id: String,
/// Validate and return the result without writing anything.
#[serde(
default,
skip_serializing_if = "crate::runtime::is_default",
alias = "validateOnly"
)]
pub validate_only: bool,
}
/// The request of DeleteTrustPolicy.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct DeleteTrustPolicyRequest {
/// The name of the trust policy to delete.
///
/// Field behavior: `required`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub name: String,
/// Delete only if the current etag matches.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub etag: String,
/// Validate without deleting anything.
#[serde(
default,
skip_serializing_if = "crate::runtime::is_default",
alias = "validateOnly"
)]
pub validate_only: bool,
}
/// The request of ExchangeReadToken.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct ExchangeReadTokenRequest {
/// The trust policy to exchange under.
///
/// Field behavior: `required`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub name: String,
/// The permissions this call needs, at most the policy's; empty means the
/// policy's. Every resolved permission must be read-only.
#[serde(default, skip_serializing_if = "std::collections::BTreeMap::is_empty")]
pub permissions: std::collections::BTreeMap<String, String>,
/// The one repository this call needs, `owner/name`, one of the policy's.
///
/// Field behavior: `required`.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub repositories: Vec<String>,
/// How long the credential should live, at most the policy's `max_ttl`.
/// A GitHub installation token always lives one hour: unset or `3600s`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub ttl: String,
}
/// The response of ExchangeReadToken.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct ExchangeReadTokenResponse {
/// The provider credential. Never logged, persisted, or cached by the
/// caller beyond `expire_time`.
///
/// Field behavior: `sensitive`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub token: String,
/// What `token` is.
#[serde(
default,
skip_serializing_if = "Option::is_none",
alias = "credentialKind"
)]
pub credential_kind: Option<CredentialKind>,
/// When the credential stops working.
#[serde(
default,
skip_serializing_if = "crate::runtime::is_default",
alias = "expireTime"
)]
pub expire_time: String,
/// The permissions the credential carries.
#[serde(default, skip_serializing_if = "std::collections::BTreeMap::is_empty")]
pub permissions: std::collections::BTreeMap<String, String>,
/// The one repository the credential covers.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub repositories: Vec<String>,
/// The record of this credential,
/// `orgs/{org}/trust_policies/{trust_policy}/token_exchanges/{token_exchange}`:
/// the name to revoke it by.
#[serde(
default,
skip_serializing_if = "crate::runtime::is_default",
alias = "tokenExchange"
)]
pub token_exchange: String,
/// The Connection the credential was issued on, the policy's.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub connection: String,
/// The provider identity that signed the credential: for GitHub,
/// `github-apps/{app_id}` of the installation it was minted against.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub issuer: String,
}
/// The request of ExchangeToken.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct ExchangeTokenRequest {
/// The trust policy to exchange under.
///
/// Field behavior: `required`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub name: String,
/// The permissions this call needs, at most the policy's; empty means the
/// policy's.
#[serde(default, skip_serializing_if = "std::collections::BTreeMap::is_empty")]
pub permissions: std::collections::BTreeMap<String, String>,
/// The one repository this call needs, `owner/name`, one of the policy's.
///
/// Field behavior: `required`.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub repositories: Vec<String>,
/// How long the credential should live, at most the policy's `max_ttl`.
/// A GitHub installation token always lives one hour: unset or `3600s`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub ttl: String,
}
/// The response of ExchangeToken.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct ExchangeTokenResponse {
/// The provider credential. Never logged, persisted, or cached by the
/// caller beyond `expire_time`.
///
/// Field behavior: `sensitive`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub token: String,
/// What `token` is.
#[serde(
default,
skip_serializing_if = "Option::is_none",
alias = "credentialKind"
)]
pub credential_kind: Option<CredentialKind>,
/// When the credential stops working.
#[serde(
default,
skip_serializing_if = "crate::runtime::is_default",
alias = "expireTime"
)]
pub expire_time: String,
/// The permissions the credential carries.
#[serde(default, skip_serializing_if = "std::collections::BTreeMap::is_empty")]
pub permissions: std::collections::BTreeMap<String, String>,
/// The one repository the credential covers.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub repositories: Vec<String>,
/// The record of this credential,
/// `orgs/{org}/trust_policies/{trust_policy}/token_exchanges/{token_exchange}`:
/// the name to revoke it by.
#[serde(
default,
skip_serializing_if = "crate::runtime::is_default",
alias = "tokenExchange"
)]
pub token_exchange: String,
/// The Connection the credential was issued on, the policy's.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub connection: String,
/// The provider identity that signed the credential: for GitHub,
/// `github-apps/{app_id}` of the installation it was minted against.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub issuer: String,
}
/// The request of GetTokenExchange.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct GetTokenExchangeRequest {
/// The name of the record to get.
///
/// Field behavior: `required`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub name: String,
}
/// The request of GetTrustPolicy.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct GetTrustPolicyRequest {
/// The name of the trust policy to get.
///
/// Field behavior: `required`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub name: String,
}
/// The request of ListTokenExchanges.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct ListTokenExchangesRequest {
/// The trust policy to list under.
///
/// Field behavior: `required`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub parent: String,
/// At most this many; default 50, clamped to 1000.
#[serde(
default,
skip_serializing_if = "crate::runtime::is_default",
alias = "pageSize"
)]
pub page_size: i32,
/// `next_page_token` of the previous page.
#[serde(
default,
skip_serializing_if = "crate::runtime::is_default",
alias = "pageToken"
)]
pub page_token: String,
}
/// The response of ListTokenExchanges.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct ListTokenExchangesResponse {
/// The page, newest first.
#[serde(
default,
skip_serializing_if = "Vec::is_empty",
alias = "tokenExchanges"
)]
pub token_exchanges: Vec<TokenExchange>,
/// The token of the next page; empty on the last page.
#[serde(
default,
skip_serializing_if = "crate::runtime::is_default",
alias = "nextPageToken"
)]
pub next_page_token: String,
}
/// The request of ListTrustPolicies.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct ListTrustPoliciesRequest {
/// The org to list in.
///
/// Field behavior: `required`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub parent: String,
/// At most this many; default 50, clamped to 1000.
#[serde(
default,
skip_serializing_if = "crate::runtime::is_default",
alias = "pageSize"
)]
pub page_size: i32,
/// `next_page_token` of the previous page.
#[serde(
default,
skip_serializing_if = "crate::runtime::is_default",
alias = "pageToken"
)]
pub page_token: String,
/// AIP-160 filter over labels and filterable fields.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub filter: String,
/// AIP-132 ordering over filterable fields.
#[serde(
default,
skip_serializing_if = "crate::runtime::is_default",
alias = "orderBy"
)]
pub order_by: String,
}
/// The response of ListTrustPolicies.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct ListTrustPoliciesResponse {
/// The page.
#[serde(
default,
skip_serializing_if = "Vec::is_empty",
alias = "trustPolicies"
)]
pub trust_policies: Vec<TrustPolicy>,
/// The token of the next page; empty on the last page.
#[serde(
default,
skip_serializing_if = "crate::runtime::is_default",
alias = "nextPageToken"
)]
pub next_page_token: String,
}
/// The request of RevokeTokenExchange.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct RevokeTokenExchangeRequest {
/// The record of the credential to revoke.
///
/// Field behavior: `required`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub name: String,
}
/// A TokenExchange is the record of one credential the Broker issued under a
/// TrustPolicy: who asked, for which Agent, on which repository, with which
/// permissions, until when. The credential itself is never returned again;
/// the record keeps only its SHA-256. The Broker holds the credential sealed
/// until it is revoked or expires, so `:revoke` needs nothing from the caller.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct TokenExchange {
/// `orgs/{org}/trust_policies/{trust_policy}/token_exchanges/{token_exchange}`.
///
/// Field behavior: `identifier`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub name: String,
/// `tkx_<cell><ulid>`; also the `{token_exchange}` id.
///
/// Field behavior: `output_only`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub uid: String,
/// Resource metadata.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub meta: Option<crate::common::ResourceMeta>,
/// The accountable principal, `orgs/{org}/principals/{id}`.
///
/// Field behavior: `output_only`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub subject: String,
/// The Agent the subject's delegated grant acted for; empty when the
/// subject exchanged for itself.
///
/// Field behavior: `output_only`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub actor: String,
/// The one repository the credential covers, `owner/name`.
///
/// Field behavior: `output_only`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub repository: String,
/// The permissions the credential carries.
///
/// Field behavior: `output_only`.
#[serde(default, skip_serializing_if = "std::collections::BTreeMap::is_empty")]
pub permissions: std::collections::BTreeMap<String, String>,
/// What the credential is.
///
/// Field behavior: `output_only`.
#[serde(
default,
skip_serializing_if = "Option::is_none",
alias = "credentialKind"
)]
pub credential_kind: Option<CredentialKind>,
/// When it was issued.
///
/// Field behavior: `output_only`.
#[serde(
default,
skip_serializing_if = "crate::runtime::is_default",
alias = "createTime"
)]
pub create_time: String,
/// When the provider stops honoring it.
///
/// Field behavior: `output_only`.
#[serde(
default,
skip_serializing_if = "crate::runtime::is_default",
alias = "expireTime"
)]
pub expire_time: String,
/// When the provider confirmed it revoked; unset while live or when it
/// simply expired.
///
/// Field behavior: `output_only`.
#[serde(
default,
skip_serializing_if = "crate::runtime::is_default",
alias = "revokeTime"
)]
pub revoke_time: String,
/// Lowercase hex SHA-256 of the credential, to match a credential seen
/// elsewhere to its record.
///
/// Field behavior: `output_only`.
#[serde(
default,
skip_serializing_if = "crate::runtime::is_default",
alias = "tokenSha256"
)]
pub token_sha256: String,
/// The Connection the credential was issued on.
///
/// Field behavior: `output_only`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub connection: String,
/// The provider identity that signed it: for GitHub, `github-apps/{app_id}`.
///
/// Field behavior: `output_only`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub issuer: String,
}
/// A TrustPolicy grants a set of Access principals the right to exchange
/// their grant for a provider credential on one Connection, never wider than
/// the policy's permissions and repositories.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct TrustPolicy {
/// `orgs/{org}/trust_policies/{trust_policy}`.
///
/// Field behavior: `identifier`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub name: String,
/// `tpol_<cell><ulid>`.
///
/// Field behavior: `output_only`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub uid: String,
/// Resource metadata.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub meta: Option<crate::common::ResourceMeta>,
/// Desired state.
///
/// Field behavior: `required`.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub spec: Option<TrustPolicySpec>,
/// Observed state.
///
/// Field behavior: `output_only`.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub status: Option<TrustPolicyStatus>,
}
/// TrustPolicySpec is the caller-writable state of a TrustPolicy.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct TrustPolicySpec {
/// The Connection credentials are issued on:
/// `orgs/{org}/connections/github-{installation_id}`, an active
/// installation of the platform's GitHub App in the same org.
///
/// Field behavior: `required`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub connection: String,
/// The Access principals allowed to exchange, `orgs/{org}/principals/{id}`
/// in the policy's org: the caller's own principal, or the accountable
/// principal of a delegated grant. 1 to 64.
///
/// Field behavior: `required`.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub subjects: Vec<String>,
/// The most a credential may carry, in GitHub repository permission names,
/// for example `{"contents": "write", "pull_requests": "write"}`.
/// `administration` is read only; organization permissions are refused.
/// A policy with `actors` carries at most `contents` and `pull_requests`.
///
/// Field behavior: `required`.
#[serde(default, skip_serializing_if = "std::collections::BTreeMap::is_empty")]
pub permissions: std::collections::BTreeMap<String, String>,
/// The repositories a credential may cover: 1 to 1000 exact `owner/name`
/// entries, no wildcard, each owned by the Connection's account.
/// One exchange covers exactly one repository.
///
/// Field behavior: `required`.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub repositories: Vec<String>,
/// What the credential service issues; `access_token` on the wire.
///
/// Field behavior: `required`.
#[serde(
default,
skip_serializing_if = "Option::is_none",
alias = "credentialKind"
)]
pub credential_kind: Option<CredentialKind>,
/// The longest a credential lives; default and maximum 1 hour.
#[serde(
default,
skip_serializing_if = "crate::runtime::is_default",
alias = "maxTtl"
)]
pub max_ttl: String,
/// The Agents a delegated grant may act for: an Agent name
/// `orgs/{org}/projects/{project}/envs/{env}/agents/{agent}`, or every
/// Agent of an environment, `.../envs/{env}/agents/*`. 0 to 64. When set,
/// only a delegated grant whose actor matches may exchange; a grant with no
/// actor is refused. When empty, any grant of a subject may exchange,
/// delegated or not.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub actors: Vec<String>,
}
/// TrustPolicyStatus is the observed state of a TrustPolicy.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct TrustPolicyStatus {
/// The generation this status was computed from.
///
/// Field behavior: `output_only`.
#[serde(
default,
skip_serializing_if = "crate::runtime::is_default",
with = "crate::runtime::int64",
alias = "observedGeneration"
)]
pub observed_generation: i64,
/// Ready: the policy was admitted against an active installation. A
/// permission the installation lacks is refused at exchange with reason
/// `CapabilityMissing`.
///
/// Field behavior: `output_only`.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub conditions: Vec<crate::common::Condition>,
}
/// The request of UpdateTrustPolicy.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct UpdateTrustPolicyRequest {
/// The trust policy to update; `name` identifies it.
///
/// Field behavior: `required`.
#[serde(
default,
skip_serializing_if = "Option::is_none",
alias = "trustPolicy"
)]
pub trust_policy: Option<TrustPolicy>,
/// The fields to write; unset writes every populated field.
#[serde(
default,
skip_serializing_if = "crate::runtime::is_default",
alias = "updateMask"
)]
pub update_mask: String,
/// Validate and return the result without writing anything.
#[serde(
default,
skip_serializing_if = "crate::runtime::is_default",
alias = "validateOnly"
)]
pub validate_only: bool,
}
/// CredentialKind is what the Broker issues under a TrustPolicy.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum CredentialKind {
/// A short-lived access token scoped to the call, for example a GitHub App
/// installation token.
AccessToken,
/// A single-use runner registration, for example a GitHub Actions JIT
/// runner config. Never persisted.
RunnerRegistration,
/// A value this SDK version does not know.
Unknown(String),
}
impl CredentialKind {
/// The wire string.
pub fn as_str(&self) -> &str {
match self {
Self::AccessToken => "access_token",
Self::RunnerRegistration => "runner_registration",
Self::Unknown(s) => s.as_str(),
}
}
/// Parses a wire string; unknown values are kept.
pub fn from_wire(s: &str) -> Self {
match s {
"access_token" => Self::AccessToken,
"runner_registration" => Self::RunnerRegistration,
other => Self::Unknown(other.to_string()),
}
}
}
impl serde::Serialize for CredentialKind {
fn serialize<S: serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
s.serialize_str(self.as_str())
}
}
impl<'de> serde::Deserialize<'de> for CredentialKind {
fn deserialize<D: serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
let s = <String as serde::Deserialize>::deserialize(d)?;
Ok(Self::from_wire(&s))
}
}
impl crate::runtime::QueryValue for CredentialKind {
fn query_value(&self) -> Option<String> {
Some(self.as_str().to_string())
}
}
impl<T: crate::runtime::Transport> crate::runtime::Client<T> {
/// Sylphx Broker (`preview`).
pub fn broker(&self) -> BrokerApi<'_, T> {
BrokerApi { client: self }
}
}
/// BrokerService is the credential service: workload identity in, short-lived
/// scoped provider credential out.
///
/// Namespace of Sylphx Broker on the client.
pub struct BrokerApi<'a, T> {
client: &'a crate::runtime::Client<T>,
}
impl<'a, T: crate::runtime::Transport> BrokerApi<'a, T> {
/// The `trust_policies` collection.
pub fn trust_policies(&self) -> TrustPoliciesCollection<'a, T> {
TrustPoliciesCollection {
client: self.client,
}
}
/// The `token_exchanges` collection.
pub fn token_exchanges(&self) -> TokenExchangesCollection<'a, T> {
TokenExchangesCollection {
client: self.client,
}
}
}
/// `trust_policies` of Sylphx Broker: Resource type `broker.sylphx.com/TrustPolicy`.
pub struct TrustPoliciesCollection<'a, T> {
client: &'a crate::runtime::Client<T>,
}
impl<'a, T: crate::runtime::Transport> TrustPoliciesCollection<'a, T> {
/// Gets a trust policy.
///
/// `GET /v1/{name=orgs/*/trust_policies/*}` · permission `broker:read` · effect `read`
///
/// Errors: `UNAUTHENTICATED`, `PERMISSION_DENIED`, `RESOURCE_NOT_FOUND`.
pub async fn get(
&self,
request: GetTrustPolicyRequest,
) -> Result<TrustPolicy, crate::runtime::Error> {
let path = format!(
"/v1/{}",
crate::runtime::path_param(&request.name, "orgs/*/trust_policies/*", "name")?
);
let query = crate::runtime::Query::default();
let http = crate::runtime::HttpRequest {
method: "GET",
path,
query: query.0,
body: None,
mutation: false,
origin: None,
effect_ids: false,
};
self.client.call(http).await
}
/// Lists an org's trust policies.
///
/// `GET /v1/{parent=orgs/*}/trust_policies` · permission `broker:read` · effect `read`
///
/// Errors: `UNAUTHENTICATED`, `PERMISSION_DENIED`, `INVALID_FIELD`, `PAGE_TOKEN_MISMATCH`.
pub async fn list(
&self,
request: ListTrustPoliciesRequest,
) -> Result<ListTrustPoliciesResponse, crate::runtime::Error> {
let path = format!(
"/v1/{}/trust_policies",
crate::runtime::path_param(&request.parent, "orgs/*", "parent")?
);
let mut query = crate::runtime::Query::default();
query.push("page_size", &request.page_size);
query.push("page_token", &request.page_token);
query.push("filter", &request.filter);
query.push("order_by", &request.order_by);
let http = crate::runtime::HttpRequest {
method: "GET",
path,
query: query.0,
body: None,
mutation: false,
origin: None,
effect_ids: false,
};
self.client.call(http).await
}
/// Every page of [`Self::list`], collected.
pub async fn list_all(
&self,
mut request: ListTrustPoliciesRequest,
) -> Result<Vec<TrustPolicy>, crate::runtime::Error> {
let mut items = Vec::new();
loop {
let page = self.list(request.clone()).await?;
items.extend(page.trust_policies);
if page.next_page_token.is_empty() {
return Ok(items);
}
request.page_token = page.next_page_token;
}
}
/// Creates a trust policy.
///
/// `POST /v1/{parent=orgs/*}/trust_policies` · permission `broker:admin` · effect `write`
///
/// Errors: `UNAUTHENTICATED`, `PERMISSION_DENIED`, `UNKNOWN_FIELD`, `INVALID_FIELD`, `RESOURCE_ALREADY_EXISTS`, `IDEMPOTENCY_KEY_REUSED`, `IDEMPOTENCY_IN_PROGRESS`, `PLAN_LIMIT_REACHED`.
pub async fn create(
&self,
request: CreateTrustPolicyRequest,
) -> Result<TrustPolicy, crate::runtime::Error> {
let path = format!(
"/v1/{}/trust_policies",
crate::runtime::path_param(&request.parent, "orgs/*", "parent")?
);
let mut query = crate::runtime::Query::default();
query.push("trust_policy_id", &request.trust_policy_id);
query.push("validate_only", &request.validate_only);
let http = crate::runtime::HttpRequest {
method: "POST",
path,
query: query.0,
body: Some(crate::runtime::body(&request.trust_policy)?),
mutation: true,
origin: None,
effect_ids: false,
};
self.client.call(http).await
}
/// Updates a trust policy.
///
/// `PATCH /v1/{trust_policy.name=orgs/*/trust_policies/*}` · permission `broker:admin` · effect `write`
///
/// Errors: `UNAUTHENTICATED`, `PERMISSION_DENIED`, `RESOURCE_NOT_FOUND`, `UNKNOWN_FIELD`, `INVALID_FIELD`, `ETAG_MISMATCH`, `IDEMPOTENCY_KEY_REUSED`, `IDEMPOTENCY_IN_PROGRESS`.
pub async fn update(
&self,
request: UpdateTrustPolicyRequest,
) -> Result<TrustPolicy, crate::runtime::Error> {
let path = format!(
"/v1/{}",
crate::runtime::path_param(
request
.trust_policy
.as_ref()
.map(|v| v.name.as_str())
.unwrap_or(""),
"orgs/*/trust_policies/*",
"trust_policy.name"
)?
);
let mut query = crate::runtime::Query::default();
query.push("update_mask", &request.update_mask);
query.push("validate_only", &request.validate_only);
let http = crate::runtime::HttpRequest {
method: "PATCH",
path,
query: query.0,
body: Some(crate::runtime::body(&request.trust_policy)?),
mutation: true,
origin: None,
effect_ids: false,
};
self.client.call(http).await
}
/// Deletes a trust policy.
///
/// `DELETE /v1/{name=orgs/*/trust_policies/*}` · permission `broker:admin` · effect `destructive`
///
/// Errors: `UNAUTHENTICATED`, `PERMISSION_DENIED`, `RESOURCE_NOT_FOUND`, `ETAG_MISMATCH`, `INVALID_STATE`, `IDEMPOTENCY_KEY_REUSED`, `IDEMPOTENCY_IN_PROGRESS`.
pub async fn delete(
&self,
request: DeleteTrustPolicyRequest,
) -> Result<crate::runtime::Empty, crate::runtime::Error> {
let path = format!(
"/v1/{}",
crate::runtime::path_param(&request.name, "orgs/*/trust_policies/*", "name")?
);
let mut query = crate::runtime::Query::default();
query.push("etag", &request.etag);
query.push("validate_only", &request.validate_only);
let http = crate::runtime::HttpRequest {
method: "DELETE",
path,
query: query.0,
body: None,
mutation: true,
origin: None,
effect_ids: false,
};
self.client.call(http).await
}
/// Exchanges the caller's Access grant for a short-lived provider
/// credential under a trust policy (RFC 8693 token exchange): a GitHub App
/// installation token for exactly one of the policy's repositories,
/// narrowed to the requested permissions. The grant's principal (for a
/// delegated grant, its accountable principal) must be a policy subject,
/// its actor must match the policy's actors, and it must hold
/// `broker:exchange` on this policy. Every call writes one TokenExchange
/// record. A permission the Connection lacks is PERMISSION_DENIED with
/// reason `CapabilityMissing`, never an outage.
///
/// `POST /v1/{name=orgs/*/trust_policies/*}:exchangeToken` · permission `broker:exchange` · effect `write`
///
/// Errors: `UNAUTHENTICATED`, `PERMISSION_DENIED`, `RESOURCE_NOT_FOUND`, `INVALID_FIELD`, `INVALID_STATE`, `RATE_LIMITED`, `UNAVAILABLE`.
pub async fn exchange_token(
&self,
request: ExchangeTokenRequest,
) -> Result<ExchangeTokenResponse, crate::runtime::Error> {
let path = format!(
"/v1/{}:exchangeToken",
crate::runtime::path_param(&request.name, "orgs/*/trust_policies/*", "name")?
);
let query = crate::runtime::Query::default();
let http = crate::runtime::HttpRequest {
method: "POST",
path,
query: query.0,
body: Some(crate::runtime::body_without(&request, &["name"])?),
mutation: true,
origin: None,
effect_ids: false,
};
self.client.call(http).await
}
/// Exchanges the caller's Access grant for a read-only GitHub App
/// installation token. Requires the explicit `broker:exchange:read` scope
/// on this policy, with the same subject, actor, Connection and repository
/// checks as ExchangeToken. Every resolved permission must be read-only:
/// omitting permissions inherits the policy and is refused if it has writes.
/// The provider's returned permissions must confirm the requested ceiling.
/// Writes one TokenExchange audit record; `broker:read` cannot issue tokens.
///
/// `POST /v1/{name=orgs/*/trust_policies/*}:exchangeReadToken` · permission `broker:exchange:read` · effect `write`
///
/// Errors: `UNAUTHENTICATED`, `PERMISSION_DENIED`, `RESOURCE_NOT_FOUND`, `INVALID_FIELD`, `INVALID_STATE`, `RATE_LIMITED`, `UNAVAILABLE`.
pub async fn exchange_read_token(
&self,
request: ExchangeReadTokenRequest,
) -> Result<ExchangeReadTokenResponse, crate::runtime::Error> {
let path = format!(
"/v1/{}:exchangeReadToken",
crate::runtime::path_param(&request.name, "orgs/*/trust_policies/*", "name")?
);
let query = crate::runtime::Query::default();
let http = crate::runtime::HttpRequest {
method: "POST",
path,
query: query.0,
body: Some(crate::runtime::body_without(&request, &["name"])?),
mutation: true,
origin: None,
effect_ids: false,
};
self.client.call(http).await
}
}
/// `token_exchanges` of Sylphx Broker: Resource type `broker.sylphx.com/TokenExchange`.
pub struct TokenExchangesCollection<'a, T> {
client: &'a crate::runtime::Client<T>,
}
impl<'a, T: crate::runtime::Transport> TokenExchangesCollection<'a, T> {
/// Gets the record of one issued credential.
///
/// `GET /v1/{name=orgs/*/trust_policies/*/token_exchanges/*}` · permission `broker:read` · effect `read`
///
/// Errors: `UNAUTHENTICATED`, `PERMISSION_DENIED`, `RESOURCE_NOT_FOUND`.
pub async fn get(
&self,
request: GetTokenExchangeRequest,
) -> Result<TokenExchange, crate::runtime::Error> {
let path = format!(
"/v1/{}",
crate::runtime::path_param(
&request.name,
"orgs/*/trust_policies/*/token_exchanges/*",
"name"
)?
);
let query = crate::runtime::Query::default();
let http = crate::runtime::HttpRequest {
method: "GET",
path,
query: query.0,
body: None,
mutation: false,
origin: None,
effect_ids: false,
};
self.client.call(http).await
}
/// Lists the credentials issued under a trust policy, newest first.
///
/// `GET /v1/{parent=orgs/*/trust_policies/*}/token_exchanges` · permission `broker:read` · effect `read`
///
/// Errors: `UNAUTHENTICATED`, `PERMISSION_DENIED`, `INVALID_FIELD`, `PAGE_TOKEN_MISMATCH`.
pub async fn list(
&self,
request: ListTokenExchangesRequest,
) -> Result<ListTokenExchangesResponse, crate::runtime::Error> {
let path = format!(
"/v1/{}/token_exchanges",
crate::runtime::path_param(&request.parent, "orgs/*/trust_policies/*", "parent")?
);
let mut query = crate::runtime::Query::default();
query.push("page_size", &request.page_size);
query.push("page_token", &request.page_token);
let http = crate::runtime::HttpRequest {
method: "GET",
path,
query: query.0,
body: None,
mutation: false,
origin: None,
effect_ids: false,
};
self.client.call(http).await
}
/// Every page of [`Self::list`], collected.
pub async fn list_all(
&self,
mut request: ListTokenExchangesRequest,
) -> Result<Vec<TokenExchange>, crate::runtime::Error> {
let mut items = Vec::new();
loop {
let page = self.list(request.clone()).await?;
items.extend(page.token_exchanges);
if page.next_page_token.is_empty() {
return Ok(items);
}
request.page_token = page.next_page_token;
}
}
/// Revokes an issued credential at the provider by its record. The Broker
/// uses the credential it holds sealed, so the caller needs no token and no
/// live delegation. Idempotent: a credential already revoked or expired
/// answers the record. Erases the sealed credential once the provider
/// confirms.
///
/// `POST /v1/{name=orgs/*/trust_policies/*/token_exchanges/*}:revoke` · permission `broker:read` · effect `destructive`
///
/// Errors: `UNAUTHENTICATED`, `PERMISSION_DENIED`, `RESOURCE_NOT_FOUND`, `UNAVAILABLE`.
pub async fn revoke(
&self,
request: RevokeTokenExchangeRequest,
) -> Result<TokenExchange, crate::runtime::Error> {
let path = format!(
"/v1/{}:revoke",
crate::runtime::path_param(
&request.name,
"orgs/*/trust_policies/*/token_exchanges/*",
"name"
)?
);
let query = crate::runtime::Query::default();
let http = crate::runtime::HttpRequest {
method: "POST",
path,
query: query.0,
body: Some(crate::runtime::body_without(&request, &["name"])?),
mutation: true,
origin: None,
effect_ids: false,
};
self.client.call(http).await
}
}