sylphx 0.3.2

The Sylphx SDK: one API, one key, every Sylphx service. Generated from the Sylphx schema registry.
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
// @generated by sylphx-gen 0.1.0 from contracts@c8a7361c53e572321b0ec9fb014fd1e8279b007b62562423038e0d0e5b9d767a. 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 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 caller's identity: a SPIFFE JWT-SVID or an Access-issued workload
    /// OIDC token, with audience `broker.sylphx.com`.
    ///
    /// Field behavior: `required`, `sensitive`.
    #[serde(
        default,
        skip_serializing_if = "crate::runtime::is_default",
        alias = "subjectToken"
    )]
    pub subject_token: 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 repositories this call needs, at most the policy's; empty means the
    /// policy's.
    #[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`.
    #[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 repositories the credential covers; empty means every repository
    /// the Connection covers.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub repositories: Vec<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 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,
}

/// A TrustPolicy grants a set of subjects the right to exchange their
/// identity 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,
    /// `trp_<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.
    ///
    /// Field behavior: `required`.
    #[serde(default, skip_serializing_if = "crate::runtime::is_default")]
    pub connection: String,
    /// The identities allowed to exchange: SPIFFE ids
    /// (`spiffe://<trust-domain>/cell/<cell>/role/<role>`, `*` matching one
    /// segment) or Sylphx Access principal names. The cell segment is never
    /// stripped.
    ///
    /// Field behavior: `required`.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub subjects: Vec<String>,
    /// The most a credential may carry, in the provider's permission names, for
    /// example `{"contents": "read", "checks": "write"}`.
    ///
    /// Field behavior: `required`.
    #[serde(default, skip_serializing_if = "std::collections::BTreeMap::is_empty")]
    pub permissions: std::collections::BTreeMap<String, String>,
    /// The most repositories a credential may cover; empty means every
    /// repository the Connection covers.
    #[serde(default, skip_serializing_if = "Vec::is_empty")]
    pub repositories: Vec<String>,
    /// What the credential service issues.
    ///
    /// 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,
}

/// 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, Reconciling, Stalled. Ready is FALSE with reason
    /// `CapabilityMissing` when the Connection lacks a permission the policy
    /// names.
    ///
    /// 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,
        }
    }
}

/// `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 workload identity for a short-lived provider
    /// credential under a trust policy (RFC 8693 token exchange). The
    /// credential is narrowed to the request and cached per installation and
    /// permission set; 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`.
    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
    }
}