k8s_openapi/v1_35/api/core/v1/
service_account_token_projection.rs

1// Generated from definition io.k8s.api.core.v1.ServiceAccountTokenProjection
2
3/// ServiceAccountTokenProjection represents a projected service account token volume. This projection can be used to insert a service account token into the pods runtime filesystem for use against APIs (Kubernetes API Server or otherwise).
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ServiceAccountTokenProjection {
6    /// audience is the intended audience of the token. A recipient of a token must identify itself with an identifier specified in the audience of the token, and otherwise should reject the token. The audience defaults to the identifier of the apiserver.
7    pub audience: Option<std::string::String>,
8
9    /// expirationSeconds is the requested duration of validity of the service account token. As the token approaches expiration, the kubelet volume plugin will proactively rotate the service account token. The kubelet will start trying to rotate the token if the token is older than 80 percent of its time to live or if the token is older than 24 hours.Defaults to 1 hour and must be at least 10 minutes.
10    pub expiration_seconds: Option<i64>,
11
12    /// path is the path relative to the mount point of the file to project the token into.
13    pub path: std::string::String,
14}
15
16impl crate::DeepMerge for ServiceAccountTokenProjection {
17    fn merge_from(&mut self, other: Self) {
18        crate::DeepMerge::merge_from(&mut self.audience, other.audience);
19        crate::DeepMerge::merge_from(&mut self.expiration_seconds, other.expiration_seconds);
20        crate::DeepMerge::merge_from(&mut self.path, other.path);
21    }
22}
23
24impl<'de> crate::serde::Deserialize<'de> for ServiceAccountTokenProjection {
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_audience,
29            Key_expiration_seconds,
30            Key_path,
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                            "audience" => Field::Key_audience,
48                            "expirationSeconds" => Field::Key_expiration_seconds,
49                            "path" => Field::Key_path,
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 = ServiceAccountTokenProjection;
63
64            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
65                f.write_str("ServiceAccountTokenProjection")
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_audience: Option<std::string::String> = None;
70                let mut value_expiration_seconds: Option<i64> = None;
71                let mut value_path: Option<std::string::String> = None;
72
73                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
74                    match key {
75                        Field::Key_audience => value_audience = crate::serde::de::MapAccess::next_value(&mut map)?,
76                        Field::Key_expiration_seconds => value_expiration_seconds = crate::serde::de::MapAccess::next_value(&mut map)?,
77                        Field::Key_path => value_path = 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(ServiceAccountTokenProjection {
83                    audience: value_audience,
84                    expiration_seconds: value_expiration_seconds,
85                    path: value_path.unwrap_or_default(),
86                })
87            }
88        }
89
90        deserializer.deserialize_struct(
91            "ServiceAccountTokenProjection",
92            &[
93                "audience",
94                "expirationSeconds",
95                "path",
96            ],
97            Visitor,
98        )
99    }
100}
101
102impl crate::serde::Serialize for ServiceAccountTokenProjection {
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            "ServiceAccountTokenProjection",
106            1 +
107            self.audience.as_ref().map_or(0, |_| 1) +
108            self.expiration_seconds.as_ref().map_or(0, |_| 1),
109        )?;
110        if let Some(value) = &self.audience {
111            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "audience", value)?;
112        }
113        if let Some(value) = &self.expiration_seconds {
114            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "expirationSeconds", value)?;
115        }
116        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "path", &self.path)?;
117        crate::serde::ser::SerializeStruct::end(state)
118    }
119}
120
121#[cfg(feature = "schemars")]
122impl crate::schemars::JsonSchema for ServiceAccountTokenProjection {
123    fn schema_name() -> std::borrow::Cow<'static, str> {
124        "io.k8s.api.core.v1.ServiceAccountTokenProjection".into()
125    }
126
127    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
128        crate::schemars::json_schema!({
129            "description": "ServiceAccountTokenProjection represents a projected service account token volume. This projection can be used to insert a service account token into the pods runtime filesystem for use against APIs (Kubernetes API Server or otherwise).",
130            "type": "object",
131            "properties": {
132                "audience": {
133                    "description": "audience is the intended audience of the token. A recipient of a token must identify itself with an identifier specified in the audience of the token, and otherwise should reject the token. The audience defaults to the identifier of the apiserver.",
134                    "type": "string",
135                },
136                "expirationSeconds": {
137                    "description": "expirationSeconds is the requested duration of validity of the service account token. As the token approaches expiration, the kubelet volume plugin will proactively rotate the service account token. The kubelet will start trying to rotate the token if the token is older than 80 percent of its time to live or if the token is older than 24 hours.Defaults to 1 hour and must be at least 10 minutes.",
138                    "type": "integer",
139                    "format": "int64",
140                },
141                "path": {
142                    "description": "path is the path relative to the mount point of the file to project the token into.",
143                    "type": "string",
144                },
145            },
146            "required": [
147                "path",
148            ],
149        })
150    }
151}