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
// @generated by sylphx-gen 0.1.0 from contracts@cdf6473b36ca648759a7f4b1fc21554541d52a947477e6e9d1d7a6a9a79bdaa0. Do not edit.
//! `sylphx.config.v1`.
#![allow(clippy::all)]
/// A ConfigFlag is one typed configuration value or feature flag of an
/// environment: a default, targeting rules, and percentage rollouts.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct ConfigFlag {
/// `orgs/{org}/projects/{project}/envs/{env}/config_flags/{config_flag}`;
/// the id is the key evaluators ask for.
///
/// Field behavior: `identifier`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub name: String,
/// `cfg_<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<ConfigFlagSpec>,
/// Observed state.
///
/// Field behavior: `output_only`.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub status: Option<ConfigFlagStatus>,
}
/// ConfigFlagSpec is the caller-writable state of a ConfigFlag.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct ConfigFlagSpec {
/// The type every value of the flag has.
///
/// Field behavior: `required`, `immutable`.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub value_type: Option<ConfigValueType>,
/// The value when no rule matches, or when the flag is disabled.
///
/// Field behavior: `required`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub default_value: serde_json::Value,
/// When false, every evaluation returns `default_value` and the rules are
/// skipped: a kill switch. Default true.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub enabled: Option<bool>,
/// Targeting rules, first match wins.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub rules: Vec<TargetingRule>,
/// What the flag is for.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub description: String,
}
/// ConfigFlagStatus is the observed state of a ConfigFlag.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct ConfigFlagStatus {
/// The generation this status was computed from.
///
/// Field behavior: `output_only`.
#[serde(
default,
skip_serializing_if = "crate::runtime::is_default",
with = "crate::runtime::int64"
)]
pub observed_generation: i64,
/// Ready, Reconciling, Stalled. Reconciling while a change rolls out in
/// waves; Stalled when a wave's health gate fails and the change halts.
///
/// Field behavior: `output_only`.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub conditions: Vec<crate::common::Condition>,
/// The wave the current change has reached, from 1.
///
/// Field behavior: `output_only`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub wave: i32,
/// How many waves the change takes.
///
/// Field behavior: `output_only`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub wave_count: i32,
/// How many Cells serve the current generation.
///
/// Field behavior: `output_only`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub updated_cell_count: i32,
/// How many Cells the environment spans.
///
/// Field behavior: `output_only`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub cell_count: i32,
}
/// The request of CreateConfigFlag.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct CreateConfigFlagRequest {
/// The environment to create in.
///
/// Field behavior: `required`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub parent: String,
/// The config flag to create; only spec and caller-writable metadata are read.
///
/// Field behavior: `required`.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub config_flag: Option<ConfigFlag>,
/// The id of the new config flag, the key evaluators ask for; the server assigns one when
/// empty.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub config_flag_id: String,
/// Validate and return the result without writing anything.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub validate_only: bool,
}
/// The request of DeleteConfigFlag.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct DeleteConfigFlagRequest {
/// The name of the config flag 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")]
pub validate_only: bool,
}
/// The request of GetConfigFlag.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct GetConfigFlagRequest {
/// The name of the config flag to get.
///
/// Field behavior: `required`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub name: String,
}
/// The request of ListConfigFlags.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct ListConfigFlagsRequest {
/// The environment 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")]
pub page_size: i32,
/// `next_page_token` of the previous page.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
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")]
pub order_by: String,
}
/// The response of ListConfigFlags.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct ListConfigFlagsResponse {
/// The page.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub config_flags: Vec<ConfigFlag>,
/// The token of the next page; empty on the last page.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub next_page_token: String,
}
/// TargetingRule serves a value to evaluations that match a condition, to a
/// stable percentage of them.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct TargetingRule {
/// A CEL expression over the evaluation context, for example
/// `ctx.region == "hk" && ctx.plan == "pro"`.
///
/// Field behavior: `required`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub condition: String,
/// The value served when the rule matches; of the flag's type.
///
/// Field behavior: `required`.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub value: serde_json::Value,
/// The share of matching evaluations served `value`, from 0 to 100;
/// default 100. The rest fall through to the next rule.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub percentage: Option<i32>,
/// The context attribute hashed to pick the stable percentage, for example
/// `user_id`; default the evaluation's subject.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub bucket_attribute: String,
/// What the rule is for.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub description: String,
}
/// The request of UpdateConfigFlag.
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
#[non_exhaustive]
pub struct UpdateConfigFlagRequest {
/// The config flag to update; `name` identifies it.
///
/// Field behavior: `required`.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub config_flag: Option<ConfigFlag>,
/// The fields to write; unset writes every populated field.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub update_mask: String,
/// Validate and return the result without writing anything.
#[serde(default, skip_serializing_if = "crate::runtime::is_default")]
pub validate_only: bool,
}
/// ConfigValueType is the type of a ConfigFlag's values.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum ConfigValueType {
/// A boolean: a feature flag.
Bool,
/// A string.
String,
/// A 64-bit integer, carried as a JSON number within ±2^53.
Int64,
/// A double.
Double,
/// Any JSON value.
Json,
/// A value this SDK version does not know.
Unknown(String),
}
impl ConfigValueType {
/// The wire string.
pub fn as_str(&self) -> &str {
match self {
Self::Bool => "bool",
Self::String => "string",
Self::Int64 => "int64",
Self::Double => "double",
Self::Json => "json",
Self::Unknown(s) => s.as_str(),
}
}
/// Parses a wire string; unknown values are kept.
pub fn from_wire(s: &str) -> Self {
match s {
"bool" => Self::Bool,
"string" => Self::String,
"int64" => Self::Int64,
"double" => Self::Double,
"json" => Self::Json,
other => Self::Unknown(other.to_string()),
}
}
}
impl serde::Serialize for ConfigValueType {
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 ConfigValueType {
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 ConfigValueType {
fn query_value(&self) -> Option<String> {
Some(self.as_str().to_string())
}
}
impl<T: crate::runtime::Transport> crate::runtime::Client<T> {
/// Sylphx Config (`preview`).
pub fn config(&self) -> ConfigApi<'_, T> {
ConfigApi { client: self }
}
}
/// ConfigService is Kernel Config: dynamic configuration and feature flags
/// evaluated in the Cell from the Cell Snapshot.
///
/// Namespace of Sylphx Config on the client.
pub struct ConfigApi<'a, T> {
client: &'a crate::runtime::Client<T>,
}
impl<'a, T: crate::runtime::Transport> ConfigApi<'a, T> {
/// The `config_flags` collection.
pub fn config_flags(&self) -> ConfigFlagsCollection<'a, T> {
ConfigFlagsCollection {
client: self.client,
}
}
}
/// `config_flags` of Sylphx Config: Resource type `config.sylphx.com/ConfigFlag`.
pub struct ConfigFlagsCollection<'a, T> {
client: &'a crate::runtime::Client<T>,
}
impl<'a, T: crate::runtime::Transport> ConfigFlagsCollection<'a, T> {
/// Gets a config flag.
///
/// `GET /v1/{name=orgs/*/projects/*/envs/*/config_flags/*}` · permission `config:read` · effect `read`
///
/// Errors: `UNAUTHENTICATED`, `PERMISSION_DENIED`, `RESOURCE_NOT_FOUND`.
pub async fn get(
&self,
request: GetConfigFlagRequest,
) -> Result<ConfigFlag, crate::runtime::Error> {
let path = format!(
"/v1/{}",
crate::runtime::path_param(
&request.name,
"orgs/*/projects/*/envs/*/config_flags/*",
"name"
)?
);
let query = crate::runtime::Query::default();
let http = crate::runtime::HttpRequest {
method: "GET",
path,
query: query.0,
body: None,
mutation: false,
};
self.client.call(http).await
}
/// Lists config flags in an environment.
///
/// `GET /v1/{parent=orgs/*/projects/*/envs/*}/config_flags` · permission `config:read` · effect `read`
///
/// Errors: `UNAUTHENTICATED`, `PERMISSION_DENIED`, `INVALID_FIELD`, `PAGE_TOKEN_MISMATCH`.
pub async fn list(
&self,
request: ListConfigFlagsRequest,
) -> Result<ListConfigFlagsResponse, crate::runtime::Error> {
let path = format!(
"/v1/{}/config_flags",
crate::runtime::path_param(&request.parent, "orgs/*/projects/*/envs/*", "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,
};
self.client.call(http).await
}
/// Every page of [`Self::list`], collected.
pub async fn list_all(
&self,
mut request: ListConfigFlagsRequest,
) -> Result<Vec<ConfigFlag>, crate::runtime::Error> {
let mut items = Vec::new();
loop {
let page = self.list(request.clone()).await?;
items.extend(page.config_flags);
if page.next_page_token.is_empty() {
return Ok(items);
}
request.page_token = page.next_page_token;
}
}
/// Creates a config flag; the Operation is done when every Cell serves it.
///
/// `POST /v1/{parent=orgs/*/projects/*/envs/*}/config_flags` · permission `config:write` · 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: CreateConfigFlagRequest,
) -> Result<crate::runtime::Operation<'a, T, ConfigFlag>, crate::runtime::Error> {
let path = format!(
"/v1/{}/config_flags",
crate::runtime::path_param(&request.parent, "orgs/*/projects/*/envs/*", "parent")?
);
let mut query = crate::runtime::Query::default();
query.push("config_flag_id", &request.config_flag_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.config_flag)?),
mutation: true,
};
let operation = self.client.call(http).await?;
Ok(crate::runtime::Operation::new(self.client, operation))
}
/// Updates a config flag; the change rolls out in waves and the Operation is done when every Cell serves it.
///
/// `PATCH /v1/{config_flag.name=orgs/*/projects/*/envs/*/config_flags/*}` · permission `config:write` · 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: UpdateConfigFlagRequest,
) -> Result<crate::runtime::Operation<'a, T, ConfigFlag>, crate::runtime::Error> {
let path = format!(
"/v1/{}",
crate::runtime::path_param(
request
.config_flag
.as_ref()
.map(|v| v.name.as_str())
.unwrap_or(""),
"orgs/*/projects/*/envs/*/config_flags/*",
"config_flag.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.config_flag)?),
mutation: true,
};
let operation = self.client.call(http).await?;
Ok(crate::runtime::Operation::new(self.client, operation))
}
/// Deletes a config flag; evaluators then get their compiled-in fallback.
///
/// `DELETE /v1/{name=orgs/*/projects/*/envs/*/config_flags/*}` · permission `config:write` · 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: DeleteConfigFlagRequest,
) -> Result<crate::runtime::Operation<'a, T, crate::runtime::Empty>, crate::runtime::Error>
{
let path = format!(
"/v1/{}",
crate::runtime::path_param(
&request.name,
"orgs/*/projects/*/envs/*/config_flags/*",
"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,
};
let operation = self.client.call(http).await?;
Ok(crate::runtime::Operation::new(self.client, operation))
}
}