#
k8s_openapi/v1_35/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: std::vec::Vec<std::string::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<std::vec::Vec<std::string::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: std::vec::Vec<std::string::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: std::vec::Vec<std::string::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 core::fmt::Formatter<'_>) -> core::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 core::fmt::Formatter<'_>) -> core::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<std::vec::Vec<std::string::String>> = None;
    82                let mut value_cluster_scope: Option<bool> = None;
    83                let mut value_namespaces: Option<std::vec::Vec<std::string::String>> = None;
    84                let mut value_resources: Option<std::vec::Vec<std::string::String>> = None;
    85                let mut value_verbs: Option<std::vec::Vec<std::string::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() -> std::borrow::Cow<'static, str> {
    146        "io.k8s.api.flowcontrol.v1.ResourcePolicyRule".into()
    147    }
    148
    149    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    150        crate::schemars::json_schema!({
    151            "description": "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.",
    152            "type": "object",
    153            "properties": {
    154                "apiGroups": {
    155                    "description": "`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.",
    156                    "type": "array",
    157                    "items": {
    158                        "type": "string",
    159                    },
    160                },
    161                "clusterScope": {
    162                    "description": "`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.",
    163                    "type": "boolean",
    164                },
    165                "namespaces": {
    166                    "description": "`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.",
    167                    "type": "array",
    168                    "items": {
    169                        "type": "string",
    170                    },
    171                },
    172                "resources": {
    173                    "description": "`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.",
    174                    "type": "array",
    175                    "items": {
    176                        "type": "string",
    177                    },
    178                },
    179                "verbs": {
    180                    "description": "`verbs` is a list of matching verbs and may not be empty. \"*\" matches all verbs and, if present, must be the only entry. Required.",
    181                    "type": "array",
    182                    "items": {
    183                        "type": "string",
    184                    },
    185                },
    186            },
    187            "required": [
    188                "apiGroups",
    189                "resources",
    190                "verbs",
    191            ],
    192        })
    193    }
    194}