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

    1// Generated from definition io.k8s.api.flowcontrol.v1.Subject
    2
    3/// Subject matches the originator of a request, as identified by the request authentication system. There are three ways of matching an originator; by user, group, or service account.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct Subject {
    6    /// `group` matches based on user group name.
    7    pub group: Option<crate::api::flowcontrol::v1::GroupSubject>,
    8
    9    /// `kind` indicates which one of the other fields is non-empty. Required
    10    pub kind: std::string::String,
    11
    12    /// `serviceAccount` matches ServiceAccounts.
    13    pub service_account: Option<crate::api::flowcontrol::v1::ServiceAccountSubject>,
    14
    15    /// `user` matches based on username.
    16    pub user: Option<crate::api::flowcontrol::v1::UserSubject>,
    17}
    18
    19impl crate::DeepMerge for Subject {
    20    fn merge_from(&mut self, other: Self) {
    21        crate::DeepMerge::merge_from(&mut self.group, other.group);
    22        crate::DeepMerge::merge_from(&mut self.kind, other.kind);
    23        crate::DeepMerge::merge_from(&mut self.service_account, other.service_account);
    24        crate::DeepMerge::merge_from(&mut self.user, other.user);
    25    }
    26}
    27
    28impl<'de> crate::serde::Deserialize<'de> for Subject {
    29    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    30        #[allow(non_camel_case_types)]
    31        enum Field {
    32            Key_group,
    33            Key_kind,
    34            Key_service_account,
    35            Key_user,
    36            Other,
    37        }
    38
    39        impl<'de> crate::serde::Deserialize<'de> for Field {
    40            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    41                struct Visitor;
    42
    43                impl crate::serde::de::Visitor<'_> for Visitor {
    44                    type Value = Field;
    45
    46                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    47                        f.write_str("field identifier")
    48                    }
    49
    50                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    51                        Ok(match v {
    52                            "group" => Field::Key_group,
    53                            "kind" => Field::Key_kind,
    54                            "serviceAccount" => Field::Key_service_account,
    55                            "user" => Field::Key_user,
    56                            _ => Field::Other,
    57                        })
    58                    }
    59                }
    60
    61                deserializer.deserialize_identifier(Visitor)
    62            }
    63        }
    64
    65        struct Visitor;
    66
    67        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    68            type Value = Subject;
    69
    70            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    71                f.write_str("Subject")
    72            }
    73
    74            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    75                let mut value_group: Option<crate::api::flowcontrol::v1::GroupSubject> = None;
    76                let mut value_kind: Option<std::string::String> = None;
    77                let mut value_service_account: Option<crate::api::flowcontrol::v1::ServiceAccountSubject> = None;
    78                let mut value_user: Option<crate::api::flowcontrol::v1::UserSubject> = None;
    79
    80                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    81                    match key {
    82                        Field::Key_group => value_group = crate::serde::de::MapAccess::next_value(&mut map)?,
    83                        Field::Key_kind => value_kind = crate::serde::de::MapAccess::next_value(&mut map)?,
    84                        Field::Key_service_account => value_service_account = crate::serde::de::MapAccess::next_value(&mut map)?,
    85                        Field::Key_user => value_user = crate::serde::de::MapAccess::next_value(&mut map)?,
    86                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    87                    }
    88                }
    89
    90                Ok(Subject {
    91                    group: value_group,
    92                    kind: value_kind.unwrap_or_default(),
    93                    service_account: value_service_account,
    94                    user: value_user,
    95                })
    96            }
    97        }
    98
    99        deserializer.deserialize_struct(
    100            "Subject",
    101            &[
    102                "group",
    103                "kind",
    104                "serviceAccount",
    105                "user",
    106            ],
    107            Visitor,
    108        )
    109    }
    110}
    111
    112impl crate::serde::Serialize for Subject {
    113    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    114        let mut state = serializer.serialize_struct(
    115            "Subject",
    116            1 +
    117            self.group.as_ref().map_or(0, |_| 1) +
    118            self.service_account.as_ref().map_or(0, |_| 1) +
    119            self.user.as_ref().map_or(0, |_| 1),
    120        )?;
    121        if let Some(value) = &self.group {
    122            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "group", value)?;
    123        }
    124        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", &self.kind)?;
    125        if let Some(value) = &self.service_account {
    126            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "serviceAccount", value)?;
    127        }
    128        if let Some(value) = &self.user {
    129            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "user", value)?;
    130        }
    131        crate::serde::ser::SerializeStruct::end(state)
    132    }
    133}
    134
    135#[cfg(feature = "schemars")]
    136impl crate::schemars::JsonSchema for Subject {
    137    fn schema_name() -> std::borrow::Cow<'static, str> {
    138        "io.k8s.api.flowcontrol.v1.Subject".into()
    139    }
    140
    141    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    142        crate::schemars::json_schema!({
    143            "description": "Subject matches the originator of a request, as identified by the request authentication system. There are three ways of matching an originator; by user, group, or service account.",
    144            "type": "object",
    145            "properties": {
    146                "group": ({
    147                    let mut schema_obj = __gen.subschema_for::<crate::api::flowcontrol::v1::GroupSubject>();
    148                    schema_obj.ensure_object().insert("description".into(), "`group` matches based on user group name.".into());
    149                    schema_obj
    150                }),
    151                "kind": {
    152                    "description": "`kind` indicates which one of the other fields is non-empty. Required",
    153                    "type": "string",
    154                },
    155                "serviceAccount": ({
    156                    let mut schema_obj = __gen.subschema_for::<crate::api::flowcontrol::v1::ServiceAccountSubject>();
    157                    schema_obj.ensure_object().insert("description".into(), "`serviceAccount` matches ServiceAccounts.".into());
    158                    schema_obj
    159                }),
    160                "user": ({
    161                    let mut schema_obj = __gen.subschema_for::<crate::api::flowcontrol::v1::UserSubject>();
    162                    schema_obj.ensure_object().insert("description".into(), "`user` matches based on username.".into());
    163                    schema_obj
    164                }),
    165            },
    166            "required": [
    167                "kind",
    168            ],
    169        })
    170    }
    171}