k8s_openapi/v1_34/api/authorization/v1/
non_resource_rule.rs

1// Generated from definition io.k8s.api.authorization.v1.NonResourceRule
2
3/// NonResourceRule holds information that describes a rule for the non-resource
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct NonResourceRule {
6    /// NonResourceURLs is a set of partial urls that a user should have access to.  *s are allowed, but only as the full, final step in the path.  "*" means all.
7    pub non_resource_urls: Option<std::vec::Vec<std::string::String>>,
8
9    /// Verb is a list of kubernetes non-resource API verbs, like: get, post, put, delete, patch, head, options.  "*" means all.
10    pub verbs: std::vec::Vec<std::string::String>,
11}
12
13impl crate::DeepMerge for NonResourceRule {
14    fn merge_from(&mut self, other: Self) {
15        crate::merge_strategies::list::atomic(&mut self.non_resource_urls, other.non_resource_urls);
16        crate::merge_strategies::list::atomic(&mut self.verbs, other.verbs);
17    }
18}
19
20impl<'de> crate::serde::Deserialize<'de> for NonResourceRule {
21    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
22        #[allow(non_camel_case_types)]
23        enum Field {
24            Key_non_resource_urls,
25            Key_verbs,
26            Other,
27        }
28
29        impl<'de> crate::serde::Deserialize<'de> for Field {
30            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
31                struct Visitor;
32
33                impl crate::serde::de::Visitor<'_> for Visitor {
34                    type Value = Field;
35
36                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
37                        f.write_str("field identifier")
38                    }
39
40                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
41                        Ok(match v {
42                            "nonResourceURLs" => Field::Key_non_resource_urls,
43                            "verbs" => Field::Key_verbs,
44                            _ => Field::Other,
45                        })
46                    }
47                }
48
49                deserializer.deserialize_identifier(Visitor)
50            }
51        }
52
53        struct Visitor;
54
55        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
56            type Value = NonResourceRule;
57
58            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
59                f.write_str("NonResourceRule")
60            }
61
62            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
63                let mut value_non_resource_urls: Option<std::vec::Vec<std::string::String>> = None;
64                let mut value_verbs: Option<std::vec::Vec<std::string::String>> = None;
65
66                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
67                    match key {
68                        Field::Key_non_resource_urls => value_non_resource_urls = crate::serde::de::MapAccess::next_value(&mut map)?,
69                        Field::Key_verbs => value_verbs = crate::serde::de::MapAccess::next_value(&mut map)?,
70                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
71                    }
72                }
73
74                Ok(NonResourceRule {
75                    non_resource_urls: value_non_resource_urls,
76                    verbs: value_verbs.unwrap_or_default(),
77                })
78            }
79        }
80
81        deserializer.deserialize_struct(
82            "NonResourceRule",
83            &[
84                "nonResourceURLs",
85                "verbs",
86            ],
87            Visitor,
88        )
89    }
90}
91
92impl crate::serde::Serialize for NonResourceRule {
93    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
94        let mut state = serializer.serialize_struct(
95            "NonResourceRule",
96            1 +
97            self.non_resource_urls.as_ref().map_or(0, |_| 1),
98        )?;
99        if let Some(value) = &self.non_resource_urls {
100            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nonResourceURLs", value)?;
101        }
102        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "verbs", &self.verbs)?;
103        crate::serde::ser::SerializeStruct::end(state)
104    }
105}
106
107#[cfg(feature = "schemars")]
108impl crate::schemars::JsonSchema for NonResourceRule {
109    fn schema_name() -> std::borrow::Cow<'static, str> {
110        "io.k8s.api.authorization.v1.NonResourceRule".into()
111    }
112
113    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
114        crate::schemars::json_schema!({
115            "description": "NonResourceRule holds information that describes a rule for the non-resource",
116            "type": "object",
117            "properties": {
118                "nonResourceURLs": {
119                    "description": "NonResourceURLs is a set of partial urls that a user should have access to.  *s are allowed, but only as the full, final step in the path.  \"*\" means all.",
120                    "type": "array",
121                    "items": {
122                        "type": "string",
123                    },
124                },
125                "verbs": {
126                    "description": "Verb is a list of kubernetes non-resource API verbs, like: get, post, put, delete, patch, head, options.  \"*\" means all.",
127                    "type": "array",
128                    "items": {
129                        "type": "string",
130                    },
131                },
132            },
133            "required": [
134                "verbs",
135            ],
136        })
137    }
138}