#
k8s_openapi/v1_35/api/authorization/v1/
subject_access_review_status.rs

    1// Generated from definition io.k8s.api.authorization.v1.SubjectAccessReviewStatus
    2
    3/// SubjectAccessReviewStatus
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct SubjectAccessReviewStatus {
    6    /// Allowed is required. True if the action would be allowed, false otherwise.
    7    pub allowed: bool,
    8
    9    /// Denied is optional. True if the action would be denied, otherwise false. If both allowed is false and denied is false, then the authorizer has no opinion on whether to authorize the action. Denied may not be true if Allowed is true.
    10    pub denied: Option<bool>,
    11
    12    /// EvaluationError is an indication that some error occurred during the authorization check. It is entirely possible to get an error and be able to continue determine authorization status in spite of it. For instance, RBAC can be missing a role, but enough roles are still present and bound to reason about the request.
    13    pub evaluation_error: Option<std::string::String>,
    14
    15    /// Reason is optional.  It indicates why a request was allowed or denied.
    16    pub reason: Option<std::string::String>,
    17}
    18
    19impl crate::DeepMerge for SubjectAccessReviewStatus {
    20    fn merge_from(&mut self, other: Self) {
    21        crate::DeepMerge::merge_from(&mut self.allowed, other.allowed);
    22        crate::DeepMerge::merge_from(&mut self.denied, other.denied);
    23        crate::DeepMerge::merge_from(&mut self.evaluation_error, other.evaluation_error);
    24        crate::DeepMerge::merge_from(&mut self.reason, other.reason);
    25    }
    26}
    27
    28impl<'de> crate::serde::Deserialize<'de> for SubjectAccessReviewStatus {
    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_allowed,
    33            Key_denied,
    34            Key_evaluation_error,
    35            Key_reason,
    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                            "allowed" => Field::Key_allowed,
    53                            "denied" => Field::Key_denied,
    54                            "evaluationError" => Field::Key_evaluation_error,
    55                            "reason" => Field::Key_reason,
    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 = SubjectAccessReviewStatus;
    69
    70            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    71                f.write_str("SubjectAccessReviewStatus")
    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_allowed: Option<bool> = None;
    76                let mut value_denied: Option<bool> = None;
    77                let mut value_evaluation_error: Option<std::string::String> = None;
    78                let mut value_reason: Option<std::string::String> = None;
    79
    80                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    81                    match key {
    82                        Field::Key_allowed => value_allowed = crate::serde::de::MapAccess::next_value(&mut map)?,
    83                        Field::Key_denied => value_denied = crate::serde::de::MapAccess::next_value(&mut map)?,
    84                        Field::Key_evaluation_error => value_evaluation_error = crate::serde::de::MapAccess::next_value(&mut map)?,
    85                        Field::Key_reason => value_reason = 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(SubjectAccessReviewStatus {
    91                    allowed: value_allowed.unwrap_or_default(),
    92                    denied: value_denied,
    93                    evaluation_error: value_evaluation_error,
    94                    reason: value_reason,
    95                })
    96            }
    97        }
    98
    99        deserializer.deserialize_struct(
    100            "SubjectAccessReviewStatus",
    101            &[
    102                "allowed",
    103                "denied",
    104                "evaluationError",
    105                "reason",
    106            ],
    107            Visitor,
    108        )
    109    }
    110}
    111
    112impl crate::serde::Serialize for SubjectAccessReviewStatus {
    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            "SubjectAccessReviewStatus",
    116            1 +
    117            self.denied.as_ref().map_or(0, |_| 1) +
    118            self.evaluation_error.as_ref().map_or(0, |_| 1) +
    119            self.reason.as_ref().map_or(0, |_| 1),
    120        )?;
    121        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "allowed", &self.allowed)?;
    122        if let Some(value) = &self.denied {
    123            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "denied", value)?;
    124        }
    125        if let Some(value) = &self.evaluation_error {
    126            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "evaluationError", value)?;
    127        }
    128        if let Some(value) = &self.reason {
    129            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "reason", value)?;
    130        }
    131        crate::serde::ser::SerializeStruct::end(state)
    132    }
    133}
    134
    135#[cfg(feature = "schemars")]
    136impl crate::schemars::JsonSchema for SubjectAccessReviewStatus {
    137    fn schema_name() -> std::borrow::Cow<'static, str> {
    138        "io.k8s.api.authorization.v1.SubjectAccessReviewStatus".into()
    139    }
    140
    141    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    142        crate::schemars::json_schema!({
    143            "description": "SubjectAccessReviewStatus",
    144            "type": "object",
    145            "properties": {
    146                "allowed": {
    147                    "description": "Allowed is required. True if the action would be allowed, false otherwise.",
    148                    "type": "boolean",
    149                },
    150                "denied": {
    151                    "description": "Denied is optional. True if the action would be denied, otherwise false. If both allowed is false and denied is false, then the authorizer has no opinion on whether to authorize the action. Denied may not be true if Allowed is true.",
    152                    "type": "boolean",
    153                },
    154                "evaluationError": {
    155                    "description": "EvaluationError is an indication that some error occurred during the authorization check. It is entirely possible to get an error and be able to continue determine authorization status in spite of it. For instance, RBAC can be missing a role, but enough roles are still present and bound to reason about the request.",
    156                    "type": "string",
    157                },
    158                "reason": {
    159                    "description": "Reason is optional.  It indicates why a request was allowed or denied.",
    160                    "type": "string",
    161                },
    162            },
    163            "required": [
    164                "allowed",
    165            ],
    166        })
    167    }
    168}