k8s_openapi/v1_34/api/authorization/v1/
resource_rule.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ResourceRule {
6 pub api_groups: Option<std::vec::Vec<std::string::String>>,
8
9 pub resource_names: Option<std::vec::Vec<std::string::String>>,
11
12 pub resources: Option<std::vec::Vec<std::string::String>>,
15
16 pub verbs: std::vec::Vec<std::string::String>,
18}
19
20impl crate::DeepMerge for ResourceRule {
21 fn merge_from(&mut self, other: Self) {
22 crate::merge_strategies::list::atomic(&mut self.api_groups, other.api_groups);
23 crate::merge_strategies::list::atomic(&mut self.resource_names, other.resource_names);
24 crate::merge_strategies::list::atomic(&mut self.resources, other.resources);
25 crate::merge_strategies::list::atomic(&mut self.verbs, other.verbs);
26 }
27}
28
29impl<'de> crate::serde::Deserialize<'de> for ResourceRule {
30 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
31 #[allow(non_camel_case_types)]
32 enum Field {
33 Key_api_groups,
34 Key_resource_names,
35 Key_resources,
36 Key_verbs,
37 Other,
38 }
39
40 impl<'de> crate::serde::Deserialize<'de> for Field {
41 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
42 struct Visitor;
43
44 impl crate::serde::de::Visitor<'_> for Visitor {
45 type Value = Field;
46
47 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
48 f.write_str("field identifier")
49 }
50
51 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
52 Ok(match v {
53 "apiGroups" => Field::Key_api_groups,
54 "resourceNames" => Field::Key_resource_names,
55 "resources" => Field::Key_resources,
56 "verbs" => Field::Key_verbs,
57 _ => Field::Other,
58 })
59 }
60 }
61
62 deserializer.deserialize_identifier(Visitor)
63 }
64 }
65
66 struct Visitor;
67
68 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
69 type Value = ResourceRule;
70
71 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
72 f.write_str("ResourceRule")
73 }
74
75 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
76 let mut value_api_groups: Option<std::vec::Vec<std::string::String>> = None;
77 let mut value_resource_names: Option<std::vec::Vec<std::string::String>> = None;
78 let mut value_resources: Option<std::vec::Vec<std::string::String>> = None;
79 let mut value_verbs: Option<std::vec::Vec<std::string::String>> = None;
80
81 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
82 match key {
83 Field::Key_api_groups => value_api_groups = crate::serde::de::MapAccess::next_value(&mut map)?,
84 Field::Key_resource_names => value_resource_names = crate::serde::de::MapAccess::next_value(&mut map)?,
85 Field::Key_resources => value_resources = crate::serde::de::MapAccess::next_value(&mut map)?,
86 Field::Key_verbs => value_verbs = crate::serde::de::MapAccess::next_value(&mut map)?,
87 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
88 }
89 }
90
91 Ok(ResourceRule {
92 api_groups: value_api_groups,
93 resource_names: value_resource_names,
94 resources: value_resources,
95 verbs: value_verbs.unwrap_or_default(),
96 })
97 }
98 }
99
100 deserializer.deserialize_struct(
101 "ResourceRule",
102 &[
103 "apiGroups",
104 "resourceNames",
105 "resources",
106 "verbs",
107 ],
108 Visitor,
109 )
110 }
111}
112
113impl crate::serde::Serialize for ResourceRule {
114 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
115 let mut state = serializer.serialize_struct(
116 "ResourceRule",
117 1 +
118 self.api_groups.as_ref().map_or(0, |_| 1) +
119 self.resource_names.as_ref().map_or(0, |_| 1) +
120 self.resources.as_ref().map_or(0, |_| 1),
121 )?;
122 if let Some(value) = &self.api_groups {
123 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiGroups", value)?;
124 }
125 if let Some(value) = &self.resource_names {
126 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resourceNames", value)?;
127 }
128 if let Some(value) = &self.resources {
129 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resources", value)?;
130 }
131 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "verbs", &self.verbs)?;
132 crate::serde::ser::SerializeStruct::end(state)
133 }
134}
135
136#[cfg(feature = "schemars")]
137impl crate::schemars::JsonSchema for ResourceRule {
138 fn schema_name() -> std::borrow::Cow<'static, str> {
139 "io.k8s.api.authorization.v1.ResourceRule".into()
140 }
141
142 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
143 crate::schemars::json_schema!({
144 "description": "ResourceRule is the list of actions the subject is allowed to perform on resources. The list ordering isn't significant, may contain duplicates, and possibly be incomplete.",
145 "type": "object",
146 "properties": {
147 "apiGroups": {
148 "description": "APIGroups is the name of the APIGroup that contains the resources. If multiple API groups are specified, any action requested against one of the enumerated resources in any API group will be allowed. \"*\" means all.",
149 "type": "array",
150 "items": {
151 "type": "string",
152 },
153 },
154 "resourceNames": {
155 "description": "ResourceNames is an optional white list of names that the rule applies to. An empty set means that everything is allowed. \"*\" means all.",
156 "type": "array",
157 "items": {
158 "type": "string",
159 },
160 },
161 "resources": {
162 "description": "Resources is a list of resources this rule applies to. \"*\" means all in the specified apiGroups.\n \"*/foo\" represents the subresource 'foo' for all resources in the specified apiGroups.",
163 "type": "array",
164 "items": {
165 "type": "string",
166 },
167 },
168 "verbs": {
169 "description": "Verb is a list of kubernetes resource API verbs, like: get, list, watch, create, update, delete, proxy. \"*\" means all.",
170 "type": "array",
171 "items": {
172 "type": "string",
173 },
174 },
175 },
176 "required": [
177 "verbs",
178 ],
179 })
180 }
181}