#
k8s_openapi/v1_35/api/flowcontrol/v1/
non_resource_policy_rule.rs

    1// Generated from definition io.k8s.api.flowcontrol.v1.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: std::vec::Vec<std::string::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: std::vec::Vec<std::string::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 crate::serde::de::Visitor<'_> for Visitor {
    40                    type Value = Field;
    41
    42                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::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 core::fmt::Formatter<'_>) -> core::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<std::vec::Vec<std::string::String>> = None;
    70                let mut value_verbs: Option<std::vec::Vec<std::string::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() -> std::borrow::Cow<'static, str> {
    113        "io.k8s.api.flowcontrol.v1.NonResourcePolicyRule".into()
    114    }
    115
    116    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    117        crate::schemars::json_schema!({
    118            "description": "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.",
    119            "type": "object",
    120            "properties": {
    121                "nonResourceURLs": {
    122                    "description": "`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.",
    123                    "type": "array",
    124                    "items": {
    125                        "type": "string",
    126                    },
    127                },
    128                "verbs": {
    129                    "description": "`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.",
    130                    "type": "array",
    131                    "items": {
    132                        "type": "string",
    133                    },
    134                },
    135            },
    136            "required": [
    137                "nonResourceURLs",
    138                "verbs",
    139            ],
    140        })
    141    }
    142}