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

    1// Generated from definition io.k8s.api.rbac.v1.Role
    2
    3/// Role is a namespaced, logical grouping of PolicyRules that can be referenced as a unit by a RoleBinding.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct Role {
    6    /// Standard object's metadata.
    7    pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
    8
    9    /// Rules holds all the PolicyRules for this Role
    10    pub rules: Option<std::vec::Vec<crate::api::rbac::v1::PolicyRule>>,
    11}
    12
    13impl crate::Resource for Role {
    14    const API_VERSION: &'static str = "rbac.authorization.k8s.io/v1";
    15    const GROUP: &'static str = "rbac.authorization.k8s.io";
    16    const KIND: &'static str = "Role";
    17    const VERSION: &'static str = "v1";
    18    const URL_PATH_SEGMENT: &'static str = "roles";
    19    type Scope = crate::NamespaceResourceScope;
    20}
    21
    22impl crate::ListableResource for Role {
    23    const LIST_KIND: &'static str = "RoleList";
    24}
    25
    26impl crate::Metadata for Role {
    27    type Ty = crate::apimachinery::pkg::apis::meta::v1::ObjectMeta;
    28
    29    fn metadata(&self) -> &<Self as crate::Metadata>::Ty {
    30        &self.metadata
    31    }
    32
    33    fn metadata_mut(&mut self) -> &mut<Self as crate::Metadata>::Ty {
    34        &mut self.metadata
    35    }
    36}
    37
    38impl crate::DeepMerge for Role {
    39    fn merge_from(&mut self, other: Self) {
    40        crate::DeepMerge::merge_from(&mut self.metadata, other.metadata);
    41        crate::merge_strategies::list::atomic(&mut self.rules, other.rules);
    42    }
    43}
    44
    45impl<'de> crate::serde::Deserialize<'de> for Role {
    46    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    47        #[allow(non_camel_case_types)]
    48        enum Field {
    49            Key_api_version,
    50            Key_kind,
    51            Key_metadata,
    52            Key_rules,
    53            Other,
    54        }
    55
    56        impl<'de> crate::serde::Deserialize<'de> for Field {
    57            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    58                struct Visitor;
    59
    60                impl crate::serde::de::Visitor<'_> for Visitor {
    61                    type Value = Field;
    62
    63                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    64                        f.write_str("field identifier")
    65                    }
    66
    67                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    68                        Ok(match v {
    69                            "apiVersion" => Field::Key_api_version,
    70                            "kind" => Field::Key_kind,
    71                            "metadata" => Field::Key_metadata,
    72                            "rules" => Field::Key_rules,
    73                            _ => Field::Other,
    74                        })
    75                    }
    76                }
    77
    78                deserializer.deserialize_identifier(Visitor)
    79            }
    80        }
    81
    82        struct Visitor;
    83
    84        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    85            type Value = Role;
    86
    87            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    88                f.write_str(<Self::Value as crate::Resource>::KIND)
    89            }
    90
    91            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    92                let mut value_metadata: Option<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta> = None;
    93                let mut value_rules: Option<std::vec::Vec<crate::api::rbac::v1::PolicyRule>> = None;
    94
    95                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    96                    match key {
    97                        Field::Key_api_version => {
    98                            let value_api_version: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
    99                            if value_api_version != <Self::Value as crate::Resource>::API_VERSION {
    100                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_api_version), &<Self::Value as crate::Resource>::API_VERSION));
    101                            }
    102                        },
    103                        Field::Key_kind => {
    104                            let value_kind: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
    105                            if value_kind != <Self::Value as crate::Resource>::KIND {
    106                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_kind), &<Self::Value as crate::Resource>::KIND));
    107                            }
    108                        },
    109                        Field::Key_metadata => value_metadata = crate::serde::de::MapAccess::next_value(&mut map)?,
    110                        Field::Key_rules => value_rules = crate::serde::de::MapAccess::next_value(&mut map)?,
    111                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    112                    }
    113                }
    114
    115                Ok(Role {
    116                    metadata: value_metadata.unwrap_or_default(),
    117                    rules: value_rules,
    118                })
    119            }
    120        }
    121
    122        deserializer.deserialize_struct(
    123            <Self as crate::Resource>::KIND,
    124            &[
    125                "apiVersion",
    126                "kind",
    127                "metadata",
    128                "rules",
    129            ],
    130            Visitor,
    131        )
    132    }
    133}
    134
    135impl crate::serde::Serialize for Role {
    136    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    137        let mut state = serializer.serialize_struct(
    138            <Self as crate::Resource>::KIND,
    139            3 +
    140            self.rules.as_ref().map_or(0, |_| 1),
    141        )?;
    142        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as crate::Resource>::API_VERSION)?;
    143        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as crate::Resource>::KIND)?;
    144        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
    145        if let Some(value) = &self.rules {
    146            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "rules", value)?;
    147        }
    148        crate::serde::ser::SerializeStruct::end(state)
    149    }
    150}
    151
    152#[cfg(feature = "schemars")]
    153impl crate::schemars::JsonSchema for Role {
    154    fn schema_name() -> std::borrow::Cow<'static, str> {
    155        "io.k8s.api.rbac.v1.Role".into()
    156    }
    157
    158    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    159        crate::schemars::json_schema!({
    160            "description": "Role is a namespaced, logical grouping of PolicyRules that can be referenced as a unit by a RoleBinding.",
    161            "type": "object",
    162            "properties": {
    163                "apiVersion": {
    164                    "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",
    165                    "type": "string",
    166                },
    167                "kind": {
    168                    "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",
    169                    "type": "string",
    170                },
    171                "metadata": ({
    172                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>();
    173                    schema_obj.ensure_object().insert("description".into(), "Standard object's metadata.".into());
    174                    schema_obj
    175                }),
    176                "rules": {
    177                    "description": "Rules holds all the PolicyRules for this Role",
    178                    "type": "array",
    179                    "items": (__gen.subschema_for::<crate::api::rbac::v1::PolicyRule>()),
    180                },
    181            },
    182            "required": [
    183                "metadata",
    184            ],
    185        })
    186    }
    187}