k8s_openapi/v1_34/api/admissionregistration/v1/
named_rule_with_operations.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct NamedRuleWithOperations {
6 pub api_groups: Option<std::vec::Vec<std::string::String>>,
8
9 pub api_versions: Option<std::vec::Vec<std::string::String>>,
11
12 pub operations: Option<std::vec::Vec<std::string::String>>,
14
15 pub resource_names: Option<std::vec::Vec<std::string::String>>,
17
18 pub resources: Option<std::vec::Vec<std::string::String>>,
26
27 pub scope: Option<std::string::String>,
29}
30
31impl crate::DeepMerge for NamedRuleWithOperations {
32 fn merge_from(&mut self, other: Self) {
33 crate::merge_strategies::list::atomic(&mut self.api_groups, other.api_groups);
34 crate::merge_strategies::list::atomic(&mut self.api_versions, other.api_versions);
35 crate::merge_strategies::list::atomic(&mut self.operations, other.operations);
36 crate::merge_strategies::list::atomic(&mut self.resource_names, other.resource_names);
37 crate::merge_strategies::list::atomic(&mut self.resources, other.resources);
38 crate::DeepMerge::merge_from(&mut self.scope, other.scope);
39 }
40}
41
42impl<'de> crate::serde::Deserialize<'de> for NamedRuleWithOperations {
43 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
44 #[allow(non_camel_case_types)]
45 enum Field {
46 Key_api_groups,
47 Key_api_versions,
48 Key_operations,
49 Key_resource_names,
50 Key_resources,
51 Key_scope,
52 Other,
53 }
54
55 impl<'de> crate::serde::Deserialize<'de> for Field {
56 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
57 struct Visitor;
58
59 impl crate::serde::de::Visitor<'_> for Visitor {
60 type Value = Field;
61
62 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
63 f.write_str("field identifier")
64 }
65
66 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
67 Ok(match v {
68 "apiGroups" => Field::Key_api_groups,
69 "apiVersions" => Field::Key_api_versions,
70 "operations" => Field::Key_operations,
71 "resourceNames" => Field::Key_resource_names,
72 "resources" => Field::Key_resources,
73 "scope" => Field::Key_scope,
74 _ => Field::Other,
75 })
76 }
77 }
78
79 deserializer.deserialize_identifier(Visitor)
80 }
81 }
82
83 struct Visitor;
84
85 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
86 type Value = NamedRuleWithOperations;
87
88 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
89 f.write_str("NamedRuleWithOperations")
90 }
91
92 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
93 let mut value_api_groups: Option<std::vec::Vec<std::string::String>> = None;
94 let mut value_api_versions: Option<std::vec::Vec<std::string::String>> = None;
95 let mut value_operations: Option<std::vec::Vec<std::string::String>> = None;
96 let mut value_resource_names: Option<std::vec::Vec<std::string::String>> = None;
97 let mut value_resources: Option<std::vec::Vec<std::string::String>> = None;
98 let mut value_scope: Option<std::string::String> = None;
99
100 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
101 match key {
102 Field::Key_api_groups => value_api_groups = crate::serde::de::MapAccess::next_value(&mut map)?,
103 Field::Key_api_versions => value_api_versions = crate::serde::de::MapAccess::next_value(&mut map)?,
104 Field::Key_operations => value_operations = crate::serde::de::MapAccess::next_value(&mut map)?,
105 Field::Key_resource_names => value_resource_names = crate::serde::de::MapAccess::next_value(&mut map)?,
106 Field::Key_resources => value_resources = crate::serde::de::MapAccess::next_value(&mut map)?,
107 Field::Key_scope => value_scope = crate::serde::de::MapAccess::next_value(&mut map)?,
108 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
109 }
110 }
111
112 Ok(NamedRuleWithOperations {
113 api_groups: value_api_groups,
114 api_versions: value_api_versions,
115 operations: value_operations,
116 resource_names: value_resource_names,
117 resources: value_resources,
118 scope: value_scope,
119 })
120 }
121 }
122
123 deserializer.deserialize_struct(
124 "NamedRuleWithOperations",
125 &[
126 "apiGroups",
127 "apiVersions",
128 "operations",
129 "resourceNames",
130 "resources",
131 "scope",
132 ],
133 Visitor,
134 )
135 }
136}
137
138impl crate::serde::Serialize for NamedRuleWithOperations {
139 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
140 let mut state = serializer.serialize_struct(
141 "NamedRuleWithOperations",
142 self.api_groups.as_ref().map_or(0, |_| 1) +
143 self.api_versions.as_ref().map_or(0, |_| 1) +
144 self.operations.as_ref().map_or(0, |_| 1) +
145 self.resource_names.as_ref().map_or(0, |_| 1) +
146 self.resources.as_ref().map_or(0, |_| 1) +
147 self.scope.as_ref().map_or(0, |_| 1),
148 )?;
149 if let Some(value) = &self.api_groups {
150 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiGroups", value)?;
151 }
152 if let Some(value) = &self.api_versions {
153 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersions", value)?;
154 }
155 if let Some(value) = &self.operations {
156 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "operations", value)?;
157 }
158 if let Some(value) = &self.resource_names {
159 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resourceNames", value)?;
160 }
161 if let Some(value) = &self.resources {
162 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resources", value)?;
163 }
164 if let Some(value) = &self.scope {
165 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "scope", value)?;
166 }
167 crate::serde::ser::SerializeStruct::end(state)
168 }
169}
170
171#[cfg(feature = "schemars")]
172impl crate::schemars::JsonSchema for NamedRuleWithOperations {
173 fn schema_name() -> std::borrow::Cow<'static, str> {
174 "io.k8s.api.admissionregistration.v1.NamedRuleWithOperations".into()
175 }
176
177 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
178 crate::schemars::json_schema!({
179 "description": "NamedRuleWithOperations is a tuple of Operations and Resources with ResourceNames.",
180 "type": "object",
181 "properties": {
182 "apiGroups": {
183 "description": "APIGroups is the API groups the resources belong to. '*' is all groups. If '*' is present, the length of the slice must be one. Required.",
184 "type": "array",
185 "items": {
186 "type": "string",
187 },
188 },
189 "apiVersions": {
190 "description": "APIVersions is the API versions the resources belong to. '*' is all versions. If '*' is present, the length of the slice must be one. Required.",
191 "type": "array",
192 "items": {
193 "type": "string",
194 },
195 },
196 "operations": {
197 "description": "Operations is the operations the admission hook cares about - CREATE, UPDATE, DELETE, CONNECT or * for all of those operations and any future admission operations that are added. If '*' is present, the length of the slice must be one. Required.",
198 "type": "array",
199 "items": {
200 "type": "string",
201 },
202 },
203 "resourceNames": {
204 "description": "ResourceNames is an optional white list of names that the rule applies to. An empty set means that everything is allowed.",
205 "type": "array",
206 "items": {
207 "type": "string",
208 },
209 },
210 "resources": {
211 "description": "Resources is a list of resources this rule applies to.\n\nFor example: 'pods' means pods. 'pods/log' means the log subresource of pods. '*' means all resources, but not subresources. 'pods/*' means all subresources of pods. '*/scale' means all scale subresources. '*/*' means all resources and their subresources.\n\nIf wildcard is present, the validation rule will ensure resources do not overlap with each other.\n\nDepending on the enclosing object, subresources might not be allowed. Required.",
212 "type": "array",
213 "items": {
214 "type": "string",
215 },
216 },
217 "scope": {
218 "description": "scope specifies the scope of this rule. Valid values are \"Cluster\", \"Namespaced\", and \"*\" \"Cluster\" means that only cluster-scoped resources will match this rule. Namespace API objects are cluster-scoped. \"Namespaced\" means that only namespaced resources will match this rule. \"*\" means that there are no scope restrictions. Subresources match the scope of their parent resource. Default is \"*\".",
219 "type": "string",
220 },
221 },
222 })
223 }
224}