k8s_openapi/v1_32/api/flowcontrol/v1/
resource_policy_rule.rs

1// Generated from definition io.k8s.api.flowcontrol.v1.ResourcePolicyRule
2
3/// 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.
7    pub api_groups: Vec<String>,
8
9    /// `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.
10    pub cluster_scope: Option<bool>,
11
12    /// `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.
13    pub namespaces: Option<Vec<String>>,
14
15    /// `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.
16    pub resources: Vec<String>,
17
18    /// `verbs` is a list of matching verbs and may not be empty. "*" matches all verbs and, if present, must be the only entry. Required.
19    pub verbs: Vec<String>,
20}
21
22impl crate::DeepMerge for ResourcePolicyRule {
23    fn merge_from(&mut self, other: Self) {
24        crate::merge_strategies::list::set(&mut self.api_groups, other.api_groups);
25        crate::DeepMerge::merge_from(&mut self.cluster_scope, other.cluster_scope);
26        crate::merge_strategies::list::set(&mut self.namespaces, other.namespaces);
27        crate::merge_strategies::list::set(&mut self.resources, other.resources);
28        crate::merge_strategies::list::set(&mut self.verbs, other.verbs);
29    }
30}
31
32impl<'de> crate::serde::Deserialize<'de> for ResourcePolicyRule {
33    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
34        #[allow(non_camel_case_types)]
35        enum Field {
36            Key_api_groups,
37            Key_cluster_scope,
38            Key_namespaces,
39            Key_resources,
40            Key_verbs,
41            Other,
42        }
43
44        impl<'de> crate::serde::Deserialize<'de> for Field {
45            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
46                struct Visitor;
47
48                impl crate::serde::de::Visitor<'_> for Visitor {
49                    type Value = Field;
50
51                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
52                        f.write_str("field identifier")
53                    }
54
55                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
56                        Ok(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                }
66
67                deserializer.deserialize_identifier(Visitor)
68            }
69        }
70
71        struct Visitor;
72
73        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
74            type Value = ResourcePolicyRule;
75
76            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
77                f.write_str("ResourcePolicyRule")
78            }
79
80            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
81                let mut value_api_groups: Option<Vec<String>> = None;
82                let mut value_cluster_scope: Option<bool> = None;
83                let mut value_namespaces: Option<Vec<String>> = None;
84                let mut value_resources: Option<Vec<String>> = None;
85                let mut value_verbs: Option<Vec<String>> = None;
86
87                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
88                    match 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                }
97
98                Ok(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        }
107
108        deserializer.deserialize_struct(
109            "ResourcePolicyRule",
110            &[
111                "apiGroups",
112                "clusterScope",
113                "namespaces",
114                "resources",
115                "verbs",
116            ],
117            Visitor,
118        )
119    }
120}
121
122impl crate::serde::Serialize for ResourcePolicyRule {
123    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
124        let mut state = serializer.serialize_struct(
125            "ResourcePolicyRule",
126            3 +
127            self.cluster_scope.as_ref().map_or(0, |_| 1) +
128            self.namespaces.as_ref().map_or(0, |_| 1),
129        )?;
130        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiGroups", &self.api_groups)?;
131        if let Some(value) = &self.cluster_scope {
132            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "clusterScope", value)?;
133        }
134        if let Some(value) = &self.namespaces {
135            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "namespaces", value)?;
136        }
137        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resources", &self.resources)?;
138        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "verbs", &self.verbs)?;
139        crate::serde::ser::SerializeStruct::end(state)
140    }
141}
142
143#[cfg(feature = "schemars")]
144impl crate::schemars::JsonSchema for ResourcePolicyRule {
145    fn schema_name() -> String {
146        "io.k8s.api.flowcontrol.v1.ResourcePolicyRule".to_owned()
147    }
148
149    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
150        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
151            metadata: Some(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.".to_owned()),
153                ..Default::default()
154            })),
155            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
156            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
157                properties: [
158                    (
159                        "apiGroups".to_owned(),
160                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
161                            metadata: Some(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.".to_owned()),
163                                ..Default::default()
164                            })),
165                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
166                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
167                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
168                                    crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
169                                        instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
170                                        ..Default::default()
171                                    })
172                                ))),
173                                ..Default::default()
174                            })),
175                            ..Default::default()
176                        }),
177                    ),
178                    (
179                        "clusterScope".to_owned(),
180                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
181                            metadata: Some(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.".to_owned()),
183                                ..Default::default()
184                            })),
185                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Boolean))),
186                            ..Default::default()
187                        }),
188                    ),
189                    (
190                        "namespaces".to_owned(),
191                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
192                            metadata: Some(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.".to_owned()),
194                                ..Default::default()
195                            })),
196                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
197                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
198                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
199                                    crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
200                                        instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
201                                        ..Default::default()
202                                    })
203                                ))),
204                                ..Default::default()
205                            })),
206                            ..Default::default()
207                        }),
208                    ),
209                    (
210                        "resources".to_owned(),
211                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
212                            metadata: Some(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.".to_owned()),
214                                ..Default::default()
215                            })),
216                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
217                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
218                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
219                                    crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
220                                        instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
221                                        ..Default::default()
222                                    })
223                                ))),
224                                ..Default::default()
225                            })),
226                            ..Default::default()
227                        }),
228                    ),
229                    (
230                        "verbs".to_owned(),
231                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
232                            metadata: Some(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.".to_owned()),
234                                ..Default::default()
235                            })),
236                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
237                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
238                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
239                                    crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
240                                        instance_type: Some(crate::schemars::schema::SingleOrVec::Single(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".to_owned(),
252                    "resources".to_owned(),
253                    "verbs".to_owned(),
254                ].into(),
255                ..Default::default()
256            })),
257            ..Default::default()
258        })
259    }
260}