k8s_openapi/v1_32/api/authorization/v1/
resource_rule.rs

1// Generated from definition io.k8s.api.authorization.v1.ResourceRule
2
3/// 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.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ResourceRule {
6    /// 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.
7    pub api_groups: Option<Vec<String>>,
8
9    /// ResourceNames is an optional white list of names that the rule applies to.  An empty set means that everything is allowed.  "*" means all.
10    pub resource_names: Option<Vec<String>>,
11
12    /// Resources is a list of resources this rule applies to.  "*" means all in the specified apiGroups.
13    ///  "*/foo" represents the subresource 'foo' for all resources in the specified apiGroups.
14    pub resources: Option<Vec<String>>,
15
16    /// Verb is a list of kubernetes resource API verbs, like: get, list, watch, create, update, delete, proxy.  "*" means all.
17    pub verbs: Vec<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 std::fmt::Formatter<'_>) -> std::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 std::fmt::Formatter<'_>) -> std::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<Vec<String>> = None;
77                let mut value_resource_names: Option<Vec<String>> = None;
78                let mut value_resources: Option<Vec<String>> = None;
79                let mut value_verbs: Option<Vec<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() -> String {
139        "io.k8s.api.authorization.v1.ResourceRule".to_owned()
140    }
141
142    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
143        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
144            metadata: Some(Box::new(crate::schemars::schema::Metadata {
145                description: Some("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.".to_owned()),
146                ..Default::default()
147            })),
148            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
149            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
150                properties: [
151                    (
152                        "apiGroups".to_owned(),
153                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
154                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
155                                description: Some("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.".to_owned()),
156                                ..Default::default()
157                            })),
158                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
159                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
160                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
161                                    crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
162                                        instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
163                                        ..Default::default()
164                                    })
165                                ))),
166                                ..Default::default()
167                            })),
168                            ..Default::default()
169                        }),
170                    ),
171                    (
172                        "resourceNames".to_owned(),
173                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
174                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
175                                description: Some("ResourceNames is an optional white list of names that the rule applies to.  An empty set means that everything is allowed.  \"*\" means all.".to_owned()),
176                                ..Default::default()
177                            })),
178                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
179                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
180                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
181                                    crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
182                                        instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
183                                        ..Default::default()
184                                    })
185                                ))),
186                                ..Default::default()
187                            })),
188                            ..Default::default()
189                        }),
190                    ),
191                    (
192                        "resources".to_owned(),
193                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
194                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
195                                description: Some("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.".to_owned()),
196                                ..Default::default()
197                            })),
198                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
199                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
200                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
201                                    crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
202                                        instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
203                                        ..Default::default()
204                                    })
205                                ))),
206                                ..Default::default()
207                            })),
208                            ..Default::default()
209                        }),
210                    ),
211                    (
212                        "verbs".to_owned(),
213                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
214                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
215                                description: Some("Verb is a list of kubernetes resource API verbs, like: get, list, watch, create, update, delete, proxy.  \"*\" means all.".to_owned()),
216                                ..Default::default()
217                            })),
218                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
219                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
220                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
221                                    crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
222                                        instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
223                                        ..Default::default()
224                                    })
225                                ))),
226                                ..Default::default()
227                            })),
228                            ..Default::default()
229                        }),
230                    ),
231                ].into(),
232                required: [
233                    "verbs".to_owned(),
234                ].into(),
235                ..Default::default()
236            })),
237            ..Default::default()
238        })
239    }
240}