Skip to main content

k8s_openapi/v1_36/api/authentication/v1/
token_request_spec.rs

1// Generated from definition io.k8s.api.authentication.v1.TokenRequestSpec
2
3/// TokenRequestSpec contains client provided parameters of a token request.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct TokenRequestSpec {
6    /// audiences are the intendend audiences of the token. A recipient of a token must identify themself with an identifier in the list of audiences of the token, and otherwise should reject the token. A token issued for multiple audiences may be used to authenticate against any of the audiences listed but implies a high degree of trust between the target audiences.
7    pub audiences: Option<std::vec::Vec<std::string::String>>,
8
9    /// boundObjectRef is a reference to an object that the token will be bound to. The token will only be valid for as long as the bound object exists. NOTE: The API server's TokenReview endpoint will validate the BoundObjectRef, but other audiences may not. Keep ExpirationSeconds small if you want prompt revocation.
10    pub bound_object_ref: Option<crate::api::authentication::v1::BoundObjectReference>,
11
12    /// expirationSeconds is the requested duration of validity of the request. The token issuer may return a token with a different validity duration so a client needs to check the 'expiration' field in a response.
13    pub expiration_seconds: Option<i64>,
14}
15
16impl crate::DeepMerge for TokenRequestSpec {
17    fn merge_from(&mut self, other: Self) {
18        crate::merge_strategies::list::atomic(&mut self.audiences, other.audiences);
19        crate::DeepMerge::merge_from(&mut self.bound_object_ref, other.bound_object_ref);
20        crate::DeepMerge::merge_from(&mut self.expiration_seconds, other.expiration_seconds);
21    }
22}
23
24impl<'de> crate::serde::Deserialize<'de> for TokenRequestSpec {
25    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
26        #[allow(non_camel_case_types)]
27        enum Field {
28            Key_audiences,
29            Key_bound_object_ref,
30            Key_expiration_seconds,
31            Other,
32        }
33
34        impl<'de> crate::serde::Deserialize<'de> for Field {
35            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
36                struct Visitor;
37
38                impl crate::serde::de::Visitor<'_> for Visitor {
39                    type Value = Field;
40
41                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
42                        f.write_str("field identifier")
43                    }
44
45                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
46                        Ok(match v {
47                            "audiences" => Field::Key_audiences,
48                            "boundObjectRef" => Field::Key_bound_object_ref,
49                            "expirationSeconds" => Field::Key_expiration_seconds,
50                            _ => Field::Other,
51                        })
52                    }
53                }
54
55                deserializer.deserialize_identifier(Visitor)
56            }
57        }
58
59        struct Visitor;
60
61        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
62            type Value = TokenRequestSpec;
63
64            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
65                f.write_str("TokenRequestSpec")
66            }
67
68            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
69                let mut value_audiences: Option<std::vec::Vec<std::string::String>> = None;
70                let mut value_bound_object_ref: Option<crate::api::authentication::v1::BoundObjectReference> = None;
71                let mut value_expiration_seconds: Option<i64> = None;
72
73                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
74                    match key {
75                        Field::Key_audiences => value_audiences = crate::serde::de::MapAccess::next_value(&mut map)?,
76                        Field::Key_bound_object_ref => value_bound_object_ref = crate::serde::de::MapAccess::next_value(&mut map)?,
77                        Field::Key_expiration_seconds => value_expiration_seconds = crate::serde::de::MapAccess::next_value(&mut map)?,
78                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
79                    }
80                }
81
82                Ok(TokenRequestSpec {
83                    audiences: value_audiences,
84                    bound_object_ref: value_bound_object_ref,
85                    expiration_seconds: value_expiration_seconds,
86                })
87            }
88        }
89
90        deserializer.deserialize_struct(
91            "TokenRequestSpec",
92            &[
93                "audiences",
94                "boundObjectRef",
95                "expirationSeconds",
96            ],
97            Visitor,
98        )
99    }
100}
101
102impl crate::serde::Serialize for TokenRequestSpec {
103    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
104        let mut state = serializer.serialize_struct(
105            "TokenRequestSpec",
106            self.audiences.as_ref().map_or(0, |_| 1) +
107            self.bound_object_ref.as_ref().map_or(0, |_| 1) +
108            self.expiration_seconds.as_ref().map_or(0, |_| 1),
109        )?;
110        if let Some(value) = &self.audiences {
111            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "audiences", value)?;
112        }
113        if let Some(value) = &self.bound_object_ref {
114            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "boundObjectRef", value)?;
115        }
116        if let Some(value) = &self.expiration_seconds {
117            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "expirationSeconds", value)?;
118        }
119        crate::serde::ser::SerializeStruct::end(state)
120    }
121}
122
123#[cfg(feature = "schemars")]
124impl crate::schemars::JsonSchema for TokenRequestSpec {
125    fn schema_name() -> std::borrow::Cow<'static, str> {
126        "io.k8s.api.authentication.v1.TokenRequestSpec".into()
127    }
128
129    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
130        crate::schemars::json_schema!({
131            "description": "TokenRequestSpec contains client provided parameters of a token request.",
132            "type": "object",
133            "properties": {
134                "audiences": {
135                    "description": "audiences are the intendend audiences of the token. A recipient of a token must identify themself with an identifier in the list of audiences of the token, and otherwise should reject the token. A token issued for multiple audiences may be used to authenticate against any of the audiences listed but implies a high degree of trust between the target audiences.",
136                    "type": "array",
137                    "items": {
138                        "type": "string",
139                    },
140                },
141                "boundObjectRef": ({
142                    let mut schema_obj = __gen.subschema_for::<crate::api::authentication::v1::BoundObjectReference>();
143                    schema_obj.ensure_object().insert("description".into(), "boundObjectRef is a reference to an object that the token will be bound to. The token will only be valid for as long as the bound object exists. NOTE: The API server's TokenReview endpoint will validate the BoundObjectRef, but other audiences may not. Keep ExpirationSeconds small if you want prompt revocation.".into());
144                    schema_obj
145                }),
146                "expirationSeconds": {
147                    "description": "expirationSeconds is the requested duration of validity of the request. The token issuer may return a token with a different validity duration so a client needs to check the 'expiration' field in a response.",
148                    "type": "integer",
149                    "format": "int64",
150                },
151            },
152        })
153    }
154}
155
156#[cfg(feature = "schemars08")]
157impl crate::schemars08::JsonSchema for TokenRequestSpec {
158    fn schema_name() -> std::string::String {
159        "io.k8s.api.authentication.v1.TokenRequestSpec".into()
160    }
161
162    fn json_schema(__gen: &mut crate::schemars08::gen::SchemaGenerator) -> crate::schemars08::schema::Schema {
163        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
164            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
165                description: Some("TokenRequestSpec contains client provided parameters of a token request.".into()),
166                ..Default::default()
167            })),
168            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Object))),
169            object: Some(std::boxed::Box::new(crate::schemars08::schema::ObjectValidation {
170                properties: [
171                    (
172                        "audiences".into(),
173                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
174                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
175                                description: Some("audiences are the intendend audiences of the token. A recipient of a token must identify themself with an identifier in the list of audiences of the token, and otherwise should reject the token. A token issued for multiple audiences may be used to authenticate against any of the audiences listed but implies a high degree of trust between the target audiences.".into()),
176                                ..Default::default()
177                            })),
178                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Array))),
179                            array: Some(std::boxed::Box::new(crate::schemars08::schema::ArrayValidation {
180                                items: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(
181                                    crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
182                                        instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
183                                        ..Default::default()
184                                    })
185                                ))),
186                                ..Default::default()
187                            })),
188                            ..Default::default()
189                        }),
190                    ),
191                    (
192                        "boundObjectRef".into(),
193                        {
194                            let mut schema_obj = __gen.subschema_for::<crate::api::authentication::v1::BoundObjectReference>().into_object();
195                            schema_obj.metadata = Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
196                                description: Some("boundObjectRef is a reference to an object that the token will be bound to. The token will only be valid for as long as the bound object exists. NOTE: The API server's TokenReview endpoint will validate the BoundObjectRef, but other audiences may not. Keep ExpirationSeconds small if you want prompt revocation.".into()),
197                                ..Default::default()
198                            }));
199                            crate::schemars08::schema::Schema::Object(schema_obj)
200                        },
201                    ),
202                    (
203                        "expirationSeconds".into(),
204                        crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
205                            metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
206                                description: Some("expirationSeconds is the requested duration of validity of the request. The token issuer may return a token with a different validity duration so a client needs to check the 'expiration' field in a response.".into()),
207                                ..Default::default()
208                            })),
209                            instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Integer))),
210                            format: Some("int64".into()),
211                            ..Default::default()
212                        }),
213                    ),
214                ].into(),
215                ..Default::default()
216            })),
217            ..Default::default()
218        })
219    }
220}