1// Generated from definition io.k8s.api.flowcontrol.v1.ResourcePolicyRule
23/// ResourcePolicyRule is a predicate that matches some resource requests, testing the request's verb and the target resource. A ResourcePolicyRule matches a resource request if and only if: (a) at least one member of verbs matches the request, (b) at least one member of apiGroups matches the request, (c) at least one member of resources matches the request, and (d) either (d1) the request does not specify a namespace (i.e., `Namespace==""`) and clusterScope is true or (d2) the request specifies a namespace and least one member of namespaces matches the request's namespace.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ResourcePolicyRule {
6/// `apiGroups` is a list of matching API groups and may not be empty. "*" matches all API groups and, if present, must be the only entry. Required.
7pub api_groups: std::vec::Vec<std::string::String>,
89/// `clusterScope` indicates whether to match requests that do not specify a namespace (which happens either because the resource is not namespaced or the request targets all namespaces). If this field is omitted or false then the `namespaces` field must contain a non-empty list.
10pub cluster_scope: Option<bool>,
1112/// `namespaces` is a list of target namespaces that restricts matches. A request that specifies a target namespace matches only if either (a) this list contains that target namespace or (b) this list contains "*". Note that "*" matches any specified namespace but does not match a request that _does not specify_ a namespace (see the `clusterScope` field for that). This list may be empty, but only if `clusterScope` is true.
13pub namespaces: Option<std::vec::Vec<std::string::String>>,
1415/// `resources` is a list of matching resources (i.e., lowercase and plural) with, if desired, subresource. For example, \[ "services", "nodes/status" \]. This list may not be empty. "*" matches all resources and, if present, must be the only entry. Required.
16pub resources: std::vec::Vec<std::string::String>,
1718/// `verbs` is a list of matching verbs and may not be empty. "*" matches all verbs and, if present, must be the only entry. Required.
19pub verbs: std::vec::Vec<std::string::String>,
20}
2122impl crate::DeepMerge for ResourcePolicyRule {
23fn merge_from(&mut self, other: Self) {
24crate::merge_strategies::list::set(&mut self.api_groups, other.api_groups);
25crate::DeepMerge::merge_from(&mut self.cluster_scope, other.cluster_scope);
26crate::merge_strategies::list::set(&mut self.namespaces, other.namespaces);
27crate::merge_strategies::list::set(&mut self.resources, other.resources);
28crate::merge_strategies::list::set(&mut self.verbs, other.verbs);
29 }
30}
3132impl<'de> crate::serde::Deserialize<'de> for ResourcePolicyRule {
33fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
34#[allow(non_camel_case_types)]
35enum Field {
36 Key_api_groups,
37 Key_cluster_scope,
38 Key_namespaces,
39 Key_resources,
40 Key_verbs,
41 Other,
42 }
4344impl<'de> crate::serde::Deserialize<'de> for Field {
45fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
46struct Visitor;
4748impl crate::serde::de::Visitor<'_> for Visitor {
49type Value = Field;
5051fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
52 f.write_str("field identifier")
53 }
5455fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
56Ok(match v {
57"apiGroups" => Field::Key_api_groups,
58"clusterScope" => Field::Key_cluster_scope,
59"namespaces" => Field::Key_namespaces,
60"resources" => Field::Key_resources,
61"verbs" => Field::Key_verbs,
62_ => Field::Other,
63 })
64 }
65 }
6667 deserializer.deserialize_identifier(Visitor)
68 }
69 }
7071struct Visitor;
7273impl<'de> crate::serde::de::Visitor<'de> for Visitor {
74type Value = ResourcePolicyRule;
7576fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
77 f.write_str("ResourcePolicyRule")
78 }
7980fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
81let mut value_api_groups: Option<std::vec::Vec<std::string::String>> = None;
82let mut value_cluster_scope: Option<bool> = None;
83let mut value_namespaces: Option<std::vec::Vec<std::string::String>> = None;
84let mut value_resources: Option<std::vec::Vec<std::string::String>> = None;
85let mut value_verbs: Option<std::vec::Vec<std::string::String>> = None;
8687while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
88match key {
89 Field::Key_api_groups => value_api_groups = crate::serde::de::MapAccess::next_value(&mut map)?,
90 Field::Key_cluster_scope => value_cluster_scope = crate::serde::de::MapAccess::next_value(&mut map)?,
91 Field::Key_namespaces => value_namespaces = crate::serde::de::MapAccess::next_value(&mut map)?,
92 Field::Key_resources => value_resources = crate::serde::de::MapAccess::next_value(&mut map)?,
93 Field::Key_verbs => value_verbs = crate::serde::de::MapAccess::next_value(&mut map)?,
94 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
95 }
96 }
9798Ok(ResourcePolicyRule {
99 api_groups: value_api_groups.unwrap_or_default(),
100 cluster_scope: value_cluster_scope,
101 namespaces: value_namespaces,
102 resources: value_resources.unwrap_or_default(),
103 verbs: value_verbs.unwrap_or_default(),
104 })
105 }
106 }
107108 deserializer.deserialize_struct(
109"ResourcePolicyRule",
110&[
111"apiGroups",
112"clusterScope",
113"namespaces",
114"resources",
115"verbs",
116 ],
117 Visitor,
118 )
119 }
120}
121122impl crate::serde::Serialize for ResourcePolicyRule {
123fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
124let mut state = serializer.serialize_struct(
125"ResourcePolicyRule",
1263 +
127self.cluster_scope.as_ref().map_or(0, |_| 1) +
128self.namespaces.as_ref().map_or(0, |_| 1),
129 )?;
130crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiGroups", &self.api_groups)?;
131if let Some(value) = &self.cluster_scope {
132crate::serde::ser::SerializeStruct::serialize_field(&mut state, "clusterScope", value)?;
133 }
134if let Some(value) = &self.namespaces {
135crate::serde::ser::SerializeStruct::serialize_field(&mut state, "namespaces", value)?;
136 }
137crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resources", &self.resources)?;
138crate::serde::ser::SerializeStruct::serialize_field(&mut state, "verbs", &self.verbs)?;
139crate::serde::ser::SerializeStruct::end(state)
140 }
141}
142143#[cfg(feature = "schemars")]
144impl crate::schemars::JsonSchema for ResourcePolicyRule {
145fn schema_name() -> std::string::String {
146"io.k8s.api.flowcontrol.v1.ResourcePolicyRule".into()
147 }
148149fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
150crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
151 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
152 description: Some("ResourcePolicyRule is a predicate that matches some resource requests, testing the request's verb and the target resource. A ResourcePolicyRule matches a resource request if and only if: (a) at least one member of verbs matches the request, (b) at least one member of apiGroups matches the request, (c) at least one member of resources matches the request, and (d) either (d1) the request does not specify a namespace (i.e., `Namespace==\"\"`) and clusterScope is true or (d2) the request specifies a namespace and least one member of namespaces matches the request's namespace.".into()),
153 ..Default::default()
154 })),
155 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
156 object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
157 properties: [
158 (
159"apiGroups".into(),
160crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
161 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
162 description: Some("`apiGroups` is a list of matching API groups and may not be empty. \"*\" matches all API groups and, if present, must be the only entry. Required.".into()),
163 ..Default::default()
164 })),
165 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
166 array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
167 items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(
168crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
169 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
170 ..Default::default()
171 })
172 ))),
173 ..Default::default()
174 })),
175 ..Default::default()
176 }),
177 ),
178 (
179"clusterScope".into(),
180crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
181 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
182 description: Some("`clusterScope` indicates whether to match requests that do not specify a namespace (which happens either because the resource is not namespaced or the request targets all namespaces). If this field is omitted or false then the `namespaces` field must contain a non-empty list.".into()),
183 ..Default::default()
184 })),
185 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Boolean))),
186 ..Default::default()
187 }),
188 ),
189 (
190"namespaces".into(),
191crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
192 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
193 description: Some("`namespaces` is a list of target namespaces that restricts matches. A request that specifies a target namespace matches only if either (a) this list contains that target namespace or (b) this list contains \"*\". Note that \"*\" matches any specified namespace but does not match a request that _does not specify_ a namespace (see the `clusterScope` field for that). This list may be empty, but only if `clusterScope` is true.".into()),
194 ..Default::default()
195 })),
196 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
197 array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
198 items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(
199crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
200 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
201 ..Default::default()
202 })
203 ))),
204 ..Default::default()
205 })),
206 ..Default::default()
207 }),
208 ),
209 (
210"resources".into(),
211crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
212 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
213 description: Some("`resources` is a list of matching resources (i.e., lowercase and plural) with, if desired, subresource. For example, [ \"services\", \"nodes/status\" ]. This list may not be empty. \"*\" matches all resources and, if present, must be the only entry. Required.".into()),
214 ..Default::default()
215 })),
216 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
217 array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
218 items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(
219crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
220 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
221 ..Default::default()
222 })
223 ))),
224 ..Default::default()
225 })),
226 ..Default::default()
227 }),
228 ),
229 (
230"verbs".into(),
231crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
232 metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
233 description: Some("`verbs` is a list of matching verbs and may not be empty. \"*\" matches all verbs and, if present, must be the only entry. Required.".into()),
234 ..Default::default()
235 })),
236 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
237 array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
238 items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(
239crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
240 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
241 ..Default::default()
242 })
243 ))),
244 ..Default::default()
245 })),
246 ..Default::default()
247 }),
248 ),
249 ].into(),
250 required: [
251"apiGroups".into(),
252"resources".into(),
253"verbs".into(),
254 ].into(),
255 ..Default::default()
256 })),
257 ..Default::default()
258 })
259 }
260}