k8s_openapi/v1_30/api/flowcontrol/v1beta3/
non_resource_policy_rule.rs

1// Generated from definition io.k8s.api.flowcontrol.v1beta3.NonResourcePolicyRule
2
3/// NonResourcePolicyRule is a predicate that matches non-resource requests according to their verb and the target non-resource URL. A NonResourcePolicyRule matches a request if and only if both (a) at least one member of verbs matches the request and (b) at least one member of nonResourceURLs matches the request.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct NonResourcePolicyRule {
6    /// `nonResourceURLs` is a set of url prefixes that a user should have access to and may not be empty. For example:
7    ///   - "/healthz" is legal
8    ///   - "/hea*" is illegal
9    ///   - "/hea" is legal but matches nothing
10    ///   - "/hea/*" also matches nothing
11    ///   - "/healthz/*" matches all per-component health checks.
12    /// "*" matches all non-resource urls. if it is present, it must be the only entry. Required.
13    pub non_resource_urls: Vec<String>,
14
15    /// `verbs` is a list of matching verbs and may not be empty. "*" matches all verbs. If it is present, it must be the only entry. Required.
16    pub verbs: Vec<String>,
17}
18
19impl crate::DeepMerge for NonResourcePolicyRule {
20    fn merge_from(&mut self, other: Self) {
21        crate::merge_strategies::list::set(&mut self.non_resource_urls, other.non_resource_urls);
22        crate::merge_strategies::list::set(&mut self.verbs, other.verbs);
23    }
24}
25
26impl<'de> crate::serde::Deserialize<'de> for NonResourcePolicyRule {
27    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
28        #[allow(non_camel_case_types)]
29        enum Field {
30            Key_non_resource_urls,
31            Key_verbs,
32            Other,
33        }
34
35        impl<'de> crate::serde::Deserialize<'de> for Field {
36            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
37                struct Visitor;
38
39                impl<'de> crate::serde::de::Visitor<'de> for Visitor {
40                    type Value = Field;
41
42                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
43                        f.write_str("field identifier")
44                    }
45
46                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
47                        Ok(match v {
48                            "nonResourceURLs" => Field::Key_non_resource_urls,
49                            "verbs" => Field::Key_verbs,
50                            _ => Field::Other,
51                        })
52                    }
53                }
54
55                deserializer.deserialize_identifier(Visitor)
56            }
57        }
58
59        struct Visitor;
60
61        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
62            type Value = NonResourcePolicyRule;
63
64            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
65                f.write_str("NonResourcePolicyRule")
66            }
67
68            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
69                let mut value_non_resource_urls: Option<Vec<String>> = None;
70                let mut value_verbs: Option<Vec<String>> = None;
71
72                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
73                    match key {
74                        Field::Key_non_resource_urls => value_non_resource_urls = crate::serde::de::MapAccess::next_value(&mut map)?,
75                        Field::Key_verbs => value_verbs = crate::serde::de::MapAccess::next_value(&mut map)?,
76                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
77                    }
78                }
79
80                Ok(NonResourcePolicyRule {
81                    non_resource_urls: value_non_resource_urls.unwrap_or_default(),
82                    verbs: value_verbs.unwrap_or_default(),
83                })
84            }
85        }
86
87        deserializer.deserialize_struct(
88            "NonResourcePolicyRule",
89            &[
90                "nonResourceURLs",
91                "verbs",
92            ],
93            Visitor,
94        )
95    }
96}
97
98impl crate::serde::Serialize for NonResourcePolicyRule {
99    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
100        let mut state = serializer.serialize_struct(
101            "NonResourcePolicyRule",
102            2,
103        )?;
104        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nonResourceURLs", &self.non_resource_urls)?;
105        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "verbs", &self.verbs)?;
106        crate::serde::ser::SerializeStruct::end(state)
107    }
108}
109
110#[cfg(feature = "schemars")]
111impl crate::schemars::JsonSchema for NonResourcePolicyRule {
112    fn schema_name() -> String {
113        "io.k8s.api.flowcontrol.v1beta3.NonResourcePolicyRule".to_owned()
114    }
115
116    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
117        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
118            metadata: Some(Box::new(crate::schemars::schema::Metadata {
119                description: Some("NonResourcePolicyRule is a predicate that matches non-resource requests according to their verb and the target non-resource URL. A NonResourcePolicyRule matches a request if and only if both (a) at least one member of verbs matches the request and (b) at least one member of nonResourceURLs matches the request.".to_owned()),
120                ..Default::default()
121            })),
122            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
123            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
124                properties: [
125                    (
126                        "nonResourceURLs".to_owned(),
127                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
128                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
129                                description: Some("`nonResourceURLs` is a set of url prefixes that a user should have access to and may not be empty. For example:\n  - \"/healthz\" is legal\n  - \"/hea*\" is illegal\n  - \"/hea\" is legal but matches nothing\n  - \"/hea/*\" also matches nothing\n  - \"/healthz/*\" matches all per-component health checks.\n\"*\" matches all non-resource urls. if it is present, it must be the only entry. Required.".to_owned()),
130                                ..Default::default()
131                            })),
132                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
133                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
134                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
135                                    crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
136                                        instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
137                                        ..Default::default()
138                                    })
139                                ))),
140                                ..Default::default()
141                            })),
142                            ..Default::default()
143                        }),
144                    ),
145                    (
146                        "verbs".to_owned(),
147                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
148                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
149                                description: Some("`verbs` is a list of matching verbs and may not be empty. \"*\" matches all verbs. If it is present, it must be the only entry. Required.".to_owned()),
150                                ..Default::default()
151                            })),
152                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
153                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
154                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(
155                                    crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
156                                        instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
157                                        ..Default::default()
158                                    })
159                                ))),
160                                ..Default::default()
161                            })),
162                            ..Default::default()
163                        }),
164                    ),
165                ].into(),
166                required: [
167                    "nonResourceURLs".to_owned(),
168                    "verbs".to_owned(),
169                ].into(),
170                ..Default::default()
171            })),
172            ..Default::default()
173        })
174    }
175}