1use crate::secret::*;
2impl serde::Serialize for Secret {
3 #[allow(deprecated)]
4 fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
5 where
6 S: serde::Serializer,
7 {
8 use serde::ser::SerializeStruct;
9 let mut len = 0;
10 if self.secret_backend.is_some() {
11 len += 1;
12 }
13 let mut struct_ser = serializer.serialize_struct("secret.Secret", len)?;
14 if let Some(v) = self.secret_backend.as_ref() {
15 match v {
16 secret::SecretBackend::Meta(v) => {
17 struct_ser.serialize_field("meta", v)?;
18 }
19 secret::SecretBackend::HashicorpVault(v) => {
20 struct_ser.serialize_field("hashicorpVault", v)?;
21 }
22 }
23 }
24 struct_ser.end()
25 }
26}
27impl<'de> serde::Deserialize<'de> for Secret {
28 #[allow(deprecated)]
29 fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
30 where
31 D: serde::Deserializer<'de>,
32 {
33 const FIELDS: &[&str] = &[
34 "meta",
35 "hashicorp_vault",
36 "hashicorpVault",
37 ];
38
39 #[allow(clippy::enum_variant_names)]
40 enum GeneratedField {
41 Meta,
42 HashicorpVault,
43 }
44 impl<'de> serde::Deserialize<'de> for GeneratedField {
45 fn deserialize<D>(deserializer: D) -> std::result::Result<GeneratedField, D::Error>
46 where
47 D: serde::Deserializer<'de>,
48 {
49 struct GeneratedVisitor;
50
51 impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
52 type Value = GeneratedField;
53
54 fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
55 write!(formatter, "expected one of: {:?}", &FIELDS)
56 }
57
58 #[allow(unused_variables)]
59 fn visit_str<E>(self, value: &str) -> std::result::Result<GeneratedField, E>
60 where
61 E: serde::de::Error,
62 {
63 match value {
64 "meta" => Ok(GeneratedField::Meta),
65 "hashicorpVault" | "hashicorp_vault" => Ok(GeneratedField::HashicorpVault),
66 _ => Err(serde::de::Error::unknown_field(value, FIELDS)),
67 }
68 }
69 }
70 deserializer.deserialize_identifier(GeneratedVisitor)
71 }
72 }
73 struct GeneratedVisitor;
74 impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
75 type Value = Secret;
76
77 fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
78 formatter.write_str("struct secret.Secret")
79 }
80
81 fn visit_map<V>(self, mut map_: V) -> std::result::Result<Secret, V::Error>
82 where
83 V: serde::de::MapAccess<'de>,
84 {
85 let mut secret_backend__ = None;
86 while let Some(k) = map_.next_key()? {
87 match k {
88 GeneratedField::Meta => {
89 if secret_backend__.is_some() {
90 return Err(serde::de::Error::duplicate_field("meta"));
91 }
92 secret_backend__ = map_.next_value::<::std::option::Option<_>>()?.map(secret::SecretBackend::Meta)
93;
94 }
95 GeneratedField::HashicorpVault => {
96 if secret_backend__.is_some() {
97 return Err(serde::de::Error::duplicate_field("hashicorpVault"));
98 }
99 secret_backend__ = map_.next_value::<::std::option::Option<_>>()?.map(secret::SecretBackend::HashicorpVault)
100;
101 }
102 }
103 }
104 Ok(Secret {
105 secret_backend: secret_backend__,
106 })
107 }
108 }
109 deserializer.deserialize_struct("secret.Secret", FIELDS, GeneratedVisitor)
110 }
111}
112impl serde::Serialize for SecretHashicropValutBackend {
113 #[allow(deprecated)]
114 fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
115 where
116 S: serde::Serializer,
117 {
118 use serde::ser::SerializeStruct;
119 let mut len = 0;
120 if !self.host.is_empty() {
121 len += 1;
122 }
123 if !self.vault_token.is_empty() {
124 len += 1;
125 }
126 let mut struct_ser = serializer.serialize_struct("secret.SecretHashicropValutBackend", len)?;
127 if !self.host.is_empty() {
128 struct_ser.serialize_field("host", &self.host)?;
129 }
130 if !self.vault_token.is_empty() {
131 struct_ser.serialize_field("vaultToken", &self.vault_token)?;
132 }
133 struct_ser.end()
134 }
135}
136impl<'de> serde::Deserialize<'de> for SecretHashicropValutBackend {
137 #[allow(deprecated)]
138 fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
139 where
140 D: serde::Deserializer<'de>,
141 {
142 const FIELDS: &[&str] = &[
143 "host",
144 "vault_token",
145 "vaultToken",
146 ];
147
148 #[allow(clippy::enum_variant_names)]
149 enum GeneratedField {
150 Host,
151 VaultToken,
152 }
153 impl<'de> serde::Deserialize<'de> for GeneratedField {
154 fn deserialize<D>(deserializer: D) -> std::result::Result<GeneratedField, D::Error>
155 where
156 D: serde::Deserializer<'de>,
157 {
158 struct GeneratedVisitor;
159
160 impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
161 type Value = GeneratedField;
162
163 fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
164 write!(formatter, "expected one of: {:?}", &FIELDS)
165 }
166
167 #[allow(unused_variables)]
168 fn visit_str<E>(self, value: &str) -> std::result::Result<GeneratedField, E>
169 where
170 E: serde::de::Error,
171 {
172 match value {
173 "host" => Ok(GeneratedField::Host),
174 "vaultToken" | "vault_token" => Ok(GeneratedField::VaultToken),
175 _ => Err(serde::de::Error::unknown_field(value, FIELDS)),
176 }
177 }
178 }
179 deserializer.deserialize_identifier(GeneratedVisitor)
180 }
181 }
182 struct GeneratedVisitor;
183 impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
184 type Value = SecretHashicropValutBackend;
185
186 fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
187 formatter.write_str("struct secret.SecretHashicropValutBackend")
188 }
189
190 fn visit_map<V>(self, mut map_: V) -> std::result::Result<SecretHashicropValutBackend, V::Error>
191 where
192 V: serde::de::MapAccess<'de>,
193 {
194 let mut host__ = None;
195 let mut vault_token__ = None;
196 while let Some(k) = map_.next_key()? {
197 match k {
198 GeneratedField::Host => {
199 if host__.is_some() {
200 return Err(serde::de::Error::duplicate_field("host"));
201 }
202 host__ = Some(map_.next_value()?);
203 }
204 GeneratedField::VaultToken => {
205 if vault_token__.is_some() {
206 return Err(serde::de::Error::duplicate_field("vaultToken"));
207 }
208 vault_token__ = Some(map_.next_value()?);
209 }
210 }
211 }
212 Ok(SecretHashicropValutBackend {
213 host: host__.unwrap_or_default(),
214 vault_token: vault_token__.unwrap_or_default(),
215 })
216 }
217 }
218 deserializer.deserialize_struct("secret.SecretHashicropValutBackend", FIELDS, GeneratedVisitor)
219 }
220}
221impl serde::Serialize for SecretMetaBackend {
222 #[allow(deprecated)]
223 fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
224 where
225 S: serde::Serializer,
226 {
227 use serde::ser::SerializeStruct;
228 let mut len = 0;
229 if !self.value.is_empty() {
230 len += 1;
231 }
232 let mut struct_ser = serializer.serialize_struct("secret.SecretMetaBackend", len)?;
233 if !self.value.is_empty() {
234 #[allow(clippy::needless_borrow)]
235 #[allow(clippy::needless_borrows_for_generic_args)]
236 struct_ser.serialize_field("value", pbjson::private::base64::encode(&self.value).as_str())?;
237 }
238 struct_ser.end()
239 }
240}
241impl<'de> serde::Deserialize<'de> for SecretMetaBackend {
242 #[allow(deprecated)]
243 fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
244 where
245 D: serde::Deserializer<'de>,
246 {
247 const FIELDS: &[&str] = &[
248 "value",
249 ];
250
251 #[allow(clippy::enum_variant_names)]
252 enum GeneratedField {
253 Value,
254 }
255 impl<'de> serde::Deserialize<'de> for GeneratedField {
256 fn deserialize<D>(deserializer: D) -> std::result::Result<GeneratedField, D::Error>
257 where
258 D: serde::Deserializer<'de>,
259 {
260 struct GeneratedVisitor;
261
262 impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
263 type Value = GeneratedField;
264
265 fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
266 write!(formatter, "expected one of: {:?}", &FIELDS)
267 }
268
269 #[allow(unused_variables)]
270 fn visit_str<E>(self, value: &str) -> std::result::Result<GeneratedField, E>
271 where
272 E: serde::de::Error,
273 {
274 match value {
275 "value" => Ok(GeneratedField::Value),
276 _ => Err(serde::de::Error::unknown_field(value, FIELDS)),
277 }
278 }
279 }
280 deserializer.deserialize_identifier(GeneratedVisitor)
281 }
282 }
283 struct GeneratedVisitor;
284 impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
285 type Value = SecretMetaBackend;
286
287 fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
288 formatter.write_str("struct secret.SecretMetaBackend")
289 }
290
291 fn visit_map<V>(self, mut map_: V) -> std::result::Result<SecretMetaBackend, V::Error>
292 where
293 V: serde::de::MapAccess<'de>,
294 {
295 let mut value__ = None;
296 while let Some(k) = map_.next_key()? {
297 match k {
298 GeneratedField::Value => {
299 if value__.is_some() {
300 return Err(serde::de::Error::duplicate_field("value"));
301 }
302 value__ =
303 Some(map_.next_value::<::pbjson::private::BytesDeserialize<_>>()?.0)
304 ;
305 }
306 }
307 }
308 Ok(SecretMetaBackend {
309 value: value__.unwrap_or_default(),
310 })
311 }
312 }
313 deserializer.deserialize_struct("secret.SecretMetaBackend", FIELDS, GeneratedVisitor)
314 }
315}
316impl serde::Serialize for SecretRef {
317 #[allow(deprecated)]
318 fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
319 where
320 S: serde::Serializer,
321 {
322 use serde::ser::SerializeStruct;
323 let mut len = 0;
324 if self.secret_id != 0 {
325 len += 1;
326 }
327 if self.ref_as != 0 {
328 len += 1;
329 }
330 let mut struct_ser = serializer.serialize_struct("secret.SecretRef", len)?;
331 if self.secret_id != 0 {
332 struct_ser.serialize_field("secretId", &self.secret_id)?;
333 }
334 if self.ref_as != 0 {
335 let v = secret_ref::RefAsType::try_from(self.ref_as)
336 .map_err(|_| serde::ser::Error::custom(format!("Invalid variant {}", self.ref_as)))?;
337 struct_ser.serialize_field("refAs", &v)?;
338 }
339 struct_ser.end()
340 }
341}
342impl<'de> serde::Deserialize<'de> for SecretRef {
343 #[allow(deprecated)]
344 fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
345 where
346 D: serde::Deserializer<'de>,
347 {
348 const FIELDS: &[&str] = &[
349 "secret_id",
350 "secretId",
351 "ref_as",
352 "refAs",
353 ];
354
355 #[allow(clippy::enum_variant_names)]
356 enum GeneratedField {
357 SecretId,
358 RefAs,
359 }
360 impl<'de> serde::Deserialize<'de> for GeneratedField {
361 fn deserialize<D>(deserializer: D) -> std::result::Result<GeneratedField, D::Error>
362 where
363 D: serde::Deserializer<'de>,
364 {
365 struct GeneratedVisitor;
366
367 impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
368 type Value = GeneratedField;
369
370 fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
371 write!(formatter, "expected one of: {:?}", &FIELDS)
372 }
373
374 #[allow(unused_variables)]
375 fn visit_str<E>(self, value: &str) -> std::result::Result<GeneratedField, E>
376 where
377 E: serde::de::Error,
378 {
379 match value {
380 "secretId" | "secret_id" => Ok(GeneratedField::SecretId),
381 "refAs" | "ref_as" => Ok(GeneratedField::RefAs),
382 _ => Err(serde::de::Error::unknown_field(value, FIELDS)),
383 }
384 }
385 }
386 deserializer.deserialize_identifier(GeneratedVisitor)
387 }
388 }
389 struct GeneratedVisitor;
390 impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
391 type Value = SecretRef;
392
393 fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
394 formatter.write_str("struct secret.SecretRef")
395 }
396
397 fn visit_map<V>(self, mut map_: V) -> std::result::Result<SecretRef, V::Error>
398 where
399 V: serde::de::MapAccess<'de>,
400 {
401 let mut secret_id__ = None;
402 let mut ref_as__ = None;
403 while let Some(k) = map_.next_key()? {
404 match k {
405 GeneratedField::SecretId => {
406 if secret_id__.is_some() {
407 return Err(serde::de::Error::duplicate_field("secretId"));
408 }
409 secret_id__ =
410 Some(map_.next_value::<::pbjson::private::NumberDeserialize<_>>()?.0)
411 ;
412 }
413 GeneratedField::RefAs => {
414 if ref_as__.is_some() {
415 return Err(serde::de::Error::duplicate_field("refAs"));
416 }
417 ref_as__ = Some(map_.next_value::<secret_ref::RefAsType>()? as i32);
418 }
419 }
420 }
421 Ok(SecretRef {
422 secret_id: secret_id__.unwrap_or_default(),
423 ref_as: ref_as__.unwrap_or_default(),
424 })
425 }
426 }
427 deserializer.deserialize_struct("secret.SecretRef", FIELDS, GeneratedVisitor)
428 }
429}
430impl serde::Serialize for secret_ref::RefAsType {
431 #[allow(deprecated)]
432 fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
433 where
434 S: serde::Serializer,
435 {
436 let variant = match self {
437 Self::Unspecified => "UNSPECIFIED",
438 Self::Text => "TEXT",
439 Self::File => "FILE",
440 };
441 serializer.serialize_str(variant)
442 }
443}
444impl<'de> serde::Deserialize<'de> for secret_ref::RefAsType {
445 #[allow(deprecated)]
446 fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
447 where
448 D: serde::Deserializer<'de>,
449 {
450 const FIELDS: &[&str] = &[
451 "UNSPECIFIED",
452 "TEXT",
453 "FILE",
454 ];
455
456 struct GeneratedVisitor;
457
458 impl<'de> serde::de::Visitor<'de> for GeneratedVisitor {
459 type Value = secret_ref::RefAsType;
460
461 fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
462 write!(formatter, "expected one of: {:?}", &FIELDS)
463 }
464
465 fn visit_i64<E>(self, v: i64) -> std::result::Result<Self::Value, E>
466 where
467 E: serde::de::Error,
468 {
469 i32::try_from(v)
470 .ok()
471 .and_then(|x| x.try_into().ok())
472 .ok_or_else(|| {
473 serde::de::Error::invalid_value(serde::de::Unexpected::Signed(v), &self)
474 })
475 }
476
477 fn visit_u64<E>(self, v: u64) -> std::result::Result<Self::Value, E>
478 where
479 E: serde::de::Error,
480 {
481 i32::try_from(v)
482 .ok()
483 .and_then(|x| x.try_into().ok())
484 .ok_or_else(|| {
485 serde::de::Error::invalid_value(serde::de::Unexpected::Unsigned(v), &self)
486 })
487 }
488
489 fn visit_str<E>(self, value: &str) -> std::result::Result<Self::Value, E>
490 where
491 E: serde::de::Error,
492 {
493 match value {
494 "UNSPECIFIED" => Ok(secret_ref::RefAsType::Unspecified),
495 "TEXT" => Ok(secret_ref::RefAsType::Text),
496 "FILE" => Ok(secret_ref::RefAsType::File),
497 _ => Err(serde::de::Error::unknown_variant(value, FIELDS)),
498 }
499 }
500 }
501 deserializer.deserialize_any(GeneratedVisitor)
502 }
503}