1// Generated from definition io.k8s.api.rbac.v1.Subject
23/// Subject contains a reference to the object or user identities a role binding applies to. This can either hold a direct API object reference, or a value for non-objects such as user and group names.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct Subject {
6/// APIGroup holds the API group of the referenced subject. Defaults to "" for ServiceAccount subjects. Defaults to "rbac.authorization.k8s.io" for User and Group subjects.
7pub api_group: Option<std::string::String>,
89/// Kind of object being referenced. Values defined by this API group are "User", "Group", and "ServiceAccount". If the Authorizer does not recognized the kind value, the Authorizer should report an error.
10pub kind: std::string::String,
1112/// Name of the object being referenced.
13pub name: std::string::String,
1415/// Namespace of the referenced object. If the object kind is non-namespace, such as "User" or "Group", and this value is not empty the Authorizer should report an error.
16pub namespace: Option<std::string::String>,
17}
1819impl crate::DeepMerge for Subject {
20fn merge_from(&mut self, other: Self) {
21crate::DeepMerge::merge_from(&mut self.api_group, other.api_group);
22crate::DeepMerge::merge_from(&mut self.kind, other.kind);
23crate::DeepMerge::merge_from(&mut self.name, other.name);
24crate::DeepMerge::merge_from(&mut self.namespace, other.namespace);
25 }
26}
2728impl<'de> crate::serde::Deserialize<'de> for Subject {
29fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
30#[allow(non_camel_case_types)]
31enum Field {
32 Key_api_group,
33 Key_kind,
34 Key_name,
35 Key_namespace,
36 Other,
37 }
3839impl<'de> crate::serde::Deserialize<'de> for Field {
40fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
41struct Visitor;
4243impl crate::serde::de::Visitor<'_> for Visitor {
44type Value = Field;
4546fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
47 f.write_str("field identifier")
48 }
4950fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
51Ok(match v {
52"apiGroup" => Field::Key_api_group,
53"kind" => Field::Key_kind,
54"name" => Field::Key_name,
55"namespace" => Field::Key_namespace,
56_ => Field::Other,
57 })
58 }
59 }
6061 deserializer.deserialize_identifier(Visitor)
62 }
63 }
6465struct Visitor;
6667impl<'de> crate::serde::de::Visitor<'de> for Visitor {
68type Value = Subject;
6970fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
71 f.write_str("Subject")
72 }
7374fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
75let mut value_api_group: Option<std::string::String> = None;
76let mut value_kind: Option<std::string::String> = None;
77let mut value_name: Option<std::string::String> = None;
78let mut value_namespace: Option<std::string::String> = None;
7980while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
81match key {
82 Field::Key_api_group => value_api_group = crate::serde::de::MapAccess::next_value(&mut map)?,
83 Field::Key_kind => value_kind = crate::serde::de::MapAccess::next_value(&mut map)?,
84 Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
85 Field::Key_namespace => value_namespace = crate::serde::de::MapAccess::next_value(&mut map)?,
86 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
87 }
88 }
8990Ok(Subject {
91 api_group: value_api_group,
92 kind: value_kind.unwrap_or_default(),
93 name: value_name.unwrap_or_default(),
94 namespace: value_namespace,
95 })
96 }
97 }
9899 deserializer.deserialize_struct(
100"Subject",
101&[
102"apiGroup",
103"kind",
104"name",
105"namespace",
106 ],
107 Visitor,
108 )
109 }
110}
111112impl crate::serde::Serialize for Subject {
113fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
114let mut state = serializer.serialize_struct(
115"Subject",
1162 +
117self.api_group.as_ref().map_or(0, |_| 1) +
118self.namespace.as_ref().map_or(0, |_| 1),
119 )?;
120if let Some(value) = &self.api_group {
121crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiGroup", value)?;
122 }
123crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", &self.kind)?;
124crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
125if let Some(value) = &self.namespace {
126crate::serde::ser::SerializeStruct::serialize_field(&mut state, "namespace", value)?;
127 }
128crate::serde::ser::SerializeStruct::end(state)
129 }
130}
131132#[cfg(feature = "schemars")]
133impl crate::schemars::JsonSchema for Subject {
134fn schema_name() -> std::string::String {
135"io.k8s.api.rbac.v1.Subject".into()
136 }
137138fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
139crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
140 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
141 description: Some("Subject contains a reference to the object or user identities a role binding applies to. This can either hold a direct API object reference, or a value for non-objects such as user and group names.".into()),
142 ..Default::default()
143 })),
144 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
145 object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
146 properties: [
147 (
148"apiGroup".into(),
149crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
150 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
151 description: Some("APIGroup holds the API group of the referenced subject. Defaults to \"\" for ServiceAccount subjects. Defaults to \"rbac.authorization.k8s.io\" for User and Group subjects.".into()),
152 ..Default::default()
153 })),
154 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
155 ..Default::default()
156 }),
157 ),
158 (
159"kind".into(),
160crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
161 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
162 description: Some("Kind of object being referenced. Values defined by this API group are \"User\", \"Group\", and \"ServiceAccount\". If the Authorizer does not recognized the kind value, the Authorizer should report an error.".into()),
163 ..Default::default()
164 })),
165 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
166 ..Default::default()
167 }),
168 ),
169 (
170"name".into(),
171crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
172 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
173 description: Some("Name of the object being referenced.".into()),
174 ..Default::default()
175 })),
176 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
177 ..Default::default()
178 }),
179 ),
180 (
181"namespace".into(),
182crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
183 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
184 description: Some("Namespace of the referenced object. If the object kind is non-namespace, such as \"User\" or \"Group\", and this value is not empty the Authorizer should report an error.".into()),
185 ..Default::default()
186 })),
187 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
188 ..Default::default()
189 }),
190 ),
191 ].into(),
192 required: [
193"kind".into(),
194"name".into(),
195 ].into(),
196 ..Default::default()
197 })),
198 ..Default::default()
199 })
200 }
201}