#
k8s_openapi/v1_35/api/rbac/v1/
cluster_role.rs

    1// Generated from definition io.k8s.api.rbac.v1.ClusterRole
    2
    3/// ClusterRole is a cluster level, logical grouping of PolicyRules that can be referenced as a unit by a RoleBinding or ClusterRoleBinding.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct ClusterRole {
    6    /// AggregationRule is an optional field that describes how to build the Rules for this ClusterRole. If AggregationRule is set, then the Rules are controller managed and direct changes to Rules will be stomped by the controller.
    7    pub aggregation_rule: Option<crate::api::rbac::v1::AggregationRule>,
    8
    9    /// Standard object's metadata.
    10    pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
    11
    12    /// Rules holds all the PolicyRules for this ClusterRole
    13    pub rules: Option<std::vec::Vec<crate::api::rbac::v1::PolicyRule>>,
    14}
    15
    16impl crate::Resource for ClusterRole {
    17    const API_VERSION: &'static str = "rbac.authorization.k8s.io/v1";
    18    const GROUP: &'static str = "rbac.authorization.k8s.io";
    19    const KIND: &'static str = "ClusterRole";
    20    const VERSION: &'static str = "v1";
    21    const URL_PATH_SEGMENT: &'static str = "clusterroles";
    22    type Scope = crate::ClusterResourceScope;
    23}
    24
    25impl crate::ListableResource for ClusterRole {
    26    const LIST_KIND: &'static str = "ClusterRoleList";
    27}
    28
    29impl crate::Metadata for ClusterRole {
    30    type Ty = crate::apimachinery::pkg::apis::meta::v1::ObjectMeta;
    31
    32    fn metadata(&self) -> &<Self as crate::Metadata>::Ty {
    33        &self.metadata
    34    }
    35
    36    fn metadata_mut(&mut self) -> &mut<Self as crate::Metadata>::Ty {
    37        &mut self.metadata
    38    }
    39}
    40
    41impl crate::DeepMerge for ClusterRole {
    42    fn merge_from(&mut self, other: Self) {
    43        crate::DeepMerge::merge_from(&mut self.aggregation_rule, other.aggregation_rule);
    44        crate::DeepMerge::merge_from(&mut self.metadata, other.metadata);
    45        crate::merge_strategies::list::atomic(&mut self.rules, other.rules);
    46    }
    47}
    48
    49impl<'de> crate::serde::Deserialize<'de> for ClusterRole {
    50    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    51        #[allow(non_camel_case_types)]
    52        enum Field {
    53            Key_api_version,
    54            Key_kind,
    55            Key_aggregation_rule,
    56            Key_metadata,
    57            Key_rules,
    58            Other,
    59        }
    60
    61        impl<'de> crate::serde::Deserialize<'de> for Field {
    62            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    63                struct Visitor;
    64
    65                impl crate::serde::de::Visitor<'_> for Visitor {
    66                    type Value = Field;
    67
    68                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    69                        f.write_str("field identifier")
    70                    }
    71
    72                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    73                        Ok(match v {
    74                            "apiVersion" => Field::Key_api_version,
    75                            "kind" => Field::Key_kind,
    76                            "aggregationRule" => Field::Key_aggregation_rule,
    77                            "metadata" => Field::Key_metadata,
    78                            "rules" => Field::Key_rules,
    79                            _ => Field::Other,
    80                        })
    81                    }
    82                }
    83
    84                deserializer.deserialize_identifier(Visitor)
    85            }
    86        }
    87
    88        struct Visitor;
    89
    90        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    91            type Value = ClusterRole;
    92
    93            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    94                f.write_str(<Self::Value as crate::Resource>::KIND)
    95            }
    96
    97            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    98                let mut value_aggregation_rule: Option<crate::api::rbac::v1::AggregationRule> = None;
    99                let mut value_metadata: Option<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta> = None;
    100                let mut value_rules: Option<std::vec::Vec<crate::api::rbac::v1::PolicyRule>> = None;
    101
    102                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    103                    match key {
    104                        Field::Key_api_version => {
    105                            let value_api_version: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
    106                            if value_api_version != <Self::Value as crate::Resource>::API_VERSION {
    107                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_api_version), &<Self::Value as crate::Resource>::API_VERSION));
    108                            }
    109                        },
    110                        Field::Key_kind => {
    111                            let value_kind: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
    112                            if value_kind != <Self::Value as crate::Resource>::KIND {
    113                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_kind), &<Self::Value as crate::Resource>::KIND));
    114                            }
    115                        },
    116                        Field::Key_aggregation_rule => value_aggregation_rule = crate::serde::de::MapAccess::next_value(&mut map)?,
    117                        Field::Key_metadata => value_metadata = crate::serde::de::MapAccess::next_value(&mut map)?,
    118                        Field::Key_rules => value_rules = crate::serde::de::MapAccess::next_value(&mut map)?,
    119                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    120                    }
    121                }
    122
    123                Ok(ClusterRole {
    124                    aggregation_rule: value_aggregation_rule,
    125                    metadata: value_metadata.unwrap_or_default(),
    126                    rules: value_rules,
    127                })
    128            }
    129        }
    130
    131        deserializer.deserialize_struct(
    132            <Self as crate::Resource>::KIND,
    133            &[
    134                "apiVersion",
    135                "kind",
    136                "aggregationRule",
    137                "metadata",
    138                "rules",
    139            ],
    140            Visitor,
    141        )
    142    }
    143}
    144
    145impl crate::serde::Serialize for ClusterRole {
    146    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    147        let mut state = serializer.serialize_struct(
    148            <Self as crate::Resource>::KIND,
    149            3 +
    150            self.aggregation_rule.as_ref().map_or(0, |_| 1) +
    151            self.rules.as_ref().map_or(0, |_| 1),
    152        )?;
    153        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as crate::Resource>::API_VERSION)?;
    154        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as crate::Resource>::KIND)?;
    155        if let Some(value) = &self.aggregation_rule {
    156            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "aggregationRule", value)?;
    157        }
    158        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
    159        if let Some(value) = &self.rules {
    160            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "rules", value)?;
    161        }
    162        crate::serde::ser::SerializeStruct::end(state)
    163    }
    164}
    165
    166#[cfg(feature = "schemars")]
    167impl crate::schemars::JsonSchema for ClusterRole {
    168    fn schema_name() -> std::borrow::Cow<'static, str> {
    169        "io.k8s.api.rbac.v1.ClusterRole".into()
    170    }
    171
    172    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    173        crate::schemars::json_schema!({
    174            "description": "ClusterRole is a cluster level, logical grouping of PolicyRules that can be referenced as a unit by a RoleBinding or ClusterRoleBinding.",
    175            "type": "object",
    176            "properties": {
    177                "aggregationRule": ({
    178                    let mut schema_obj = __gen.subschema_for::<crate::api::rbac::v1::AggregationRule>();
    179                    schema_obj.ensure_object().insert("description".into(), "AggregationRule is an optional field that describes how to build the Rules for this ClusterRole. If AggregationRule is set, then the Rules are controller managed and direct changes to Rules will be stomped by the controller.".into());
    180                    schema_obj
    181                }),
    182                "apiVersion": {
    183                    "description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
    184                    "type": "string",
    185                },
    186                "kind": {
    187                    "description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
    188                    "type": "string",
    189                },
    190                "metadata": ({
    191                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>();
    192                    schema_obj.ensure_object().insert("description".into(), "Standard object's metadata.".into());
    193                    schema_obj
    194                }),
    195                "rules": {
    196                    "description": "Rules holds all the PolicyRules for this ClusterRole",
    197                    "type": "array",
    198                    "items": (__gen.subschema_for::<crate::api::rbac::v1::PolicyRule>()),
    199                },
    200            },
    201            "required": [
    202                "metadata",
    203            ],
    204        })
    205    }
    206}