k8s_openapi/v1_33/api/flowcontrol/v1/
policy_rules_with_subjects.rs

1// Generated from definition io.k8s.api.flowcontrol.v1.PolicyRulesWithSubjects
2
3/// PolicyRulesWithSubjects prescribes a test that applies to a request to an apiserver. The test considers the subject making the request, the verb being requested, and the resource to be acted upon. This PolicyRulesWithSubjects matches a request if and only if both (a) at least one member of subjects matches the request and (b) at least one member of resourceRules or nonResourceRules matches the request.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct PolicyRulesWithSubjects {
6    /// `nonResourceRules` is a list of NonResourcePolicyRules that identify matching requests according to their verb and the target non-resource URL.
7    pub non_resource_rules: Option<std::vec::Vec<crate::api::flowcontrol::v1::NonResourcePolicyRule>>,
8
9    /// `resourceRules` is a slice of ResourcePolicyRules that identify matching requests according to their verb and the target resource. At least one of `resourceRules` and `nonResourceRules` has to be non-empty.
10    pub resource_rules: Option<std::vec::Vec<crate::api::flowcontrol::v1::ResourcePolicyRule>>,
11
12    /// subjects is the list of normal user, serviceaccount, or group that this rule cares about. There must be at least one member in this slice. A slice that includes both the system:authenticated and system:unauthenticated user groups matches every request. Required.
13    pub subjects: std::vec::Vec<crate::api::flowcontrol::v1::Subject>,
14}
15
16impl crate::DeepMerge for PolicyRulesWithSubjects {
17    fn merge_from(&mut self, other: Self) {
18        crate::merge_strategies::list::atomic(&mut self.non_resource_rules, other.non_resource_rules);
19        crate::merge_strategies::list::atomic(&mut self.resource_rules, other.resource_rules);
20        crate::merge_strategies::list::atomic(&mut self.subjects, other.subjects);
21    }
22}
23
24impl<'de> crate::serde::Deserialize<'de> for PolicyRulesWithSubjects {
25    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
26        #[allow(non_camel_case_types)]
27        enum Field {
28            Key_non_resource_rules,
29            Key_resource_rules,
30            Key_subjects,
31            Other,
32        }
33
34        impl<'de> crate::serde::Deserialize<'de> for Field {
35            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
36                struct Visitor;
37
38                impl crate::serde::de::Visitor<'_> for Visitor {
39                    type Value = Field;
40
41                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
42                        f.write_str("field identifier")
43                    }
44
45                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
46                        Ok(match v {
47                            "nonResourceRules" => Field::Key_non_resource_rules,
48                            "resourceRules" => Field::Key_resource_rules,
49                            "subjects" => Field::Key_subjects,
50                            _ => Field::Other,
51                        })
52                    }
53                }
54
55                deserializer.deserialize_identifier(Visitor)
56            }
57        }
58
59        struct Visitor;
60
61        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
62            type Value = PolicyRulesWithSubjects;
63
64            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
65                f.write_str("PolicyRulesWithSubjects")
66            }
67
68            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
69                let mut value_non_resource_rules: Option<std::vec::Vec<crate::api::flowcontrol::v1::NonResourcePolicyRule>> = None;
70                let mut value_resource_rules: Option<std::vec::Vec<crate::api::flowcontrol::v1::ResourcePolicyRule>> = None;
71                let mut value_subjects: Option<std::vec::Vec<crate::api::flowcontrol::v1::Subject>> = None;
72
73                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
74                    match key {
75                        Field::Key_non_resource_rules => value_non_resource_rules = crate::serde::de::MapAccess::next_value(&mut map)?,
76                        Field::Key_resource_rules => value_resource_rules = crate::serde::de::MapAccess::next_value(&mut map)?,
77                        Field::Key_subjects => value_subjects = crate::serde::de::MapAccess::next_value(&mut map)?,
78                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
79                    }
80                }
81
82                Ok(PolicyRulesWithSubjects {
83                    non_resource_rules: value_non_resource_rules,
84                    resource_rules: value_resource_rules,
85                    subjects: value_subjects.unwrap_or_default(),
86                })
87            }
88        }
89
90        deserializer.deserialize_struct(
91            "PolicyRulesWithSubjects",
92            &[
93                "nonResourceRules",
94                "resourceRules",
95                "subjects",
96            ],
97            Visitor,
98        )
99    }
100}
101
102impl crate::serde::Serialize for PolicyRulesWithSubjects {
103    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
104        let mut state = serializer.serialize_struct(
105            "PolicyRulesWithSubjects",
106            1 +
107            self.non_resource_rules.as_ref().map_or(0, |_| 1) +
108            self.resource_rules.as_ref().map_or(0, |_| 1),
109        )?;
110        if let Some(value) = &self.non_resource_rules {
111            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nonResourceRules", value)?;
112        }
113        if let Some(value) = &self.resource_rules {
114            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resourceRules", value)?;
115        }
116        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "subjects", &self.subjects)?;
117        crate::serde::ser::SerializeStruct::end(state)
118    }
119}
120
121#[cfg(feature = "schemars")]
122impl crate::schemars::JsonSchema for PolicyRulesWithSubjects {
123    fn schema_name() -> std::string::String {
124        "io.k8s.api.flowcontrol.v1.PolicyRulesWithSubjects".into()
125    }
126
127    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
128        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
129            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
130                description: Some("PolicyRulesWithSubjects prescribes a test that applies to a request to an apiserver. The test considers the subject making the request, the verb being requested, and the resource to be acted upon. This PolicyRulesWithSubjects matches a request if and only if both (a) at least one member of subjects matches the request and (b) at least one member of resourceRules or nonResourceRules matches the request.".into()),
131                ..Default::default()
132            })),
133            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
134            object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
135                properties: [
136                    (
137                        "nonResourceRules".into(),
138                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
139                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
140                                description: Some("`nonResourceRules` is a list of NonResourcePolicyRules that identify matching requests according to their verb and the target non-resource URL.".into()),
141                                ..Default::default()
142                            })),
143                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
144                            array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
145                                items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::flowcontrol::v1::NonResourcePolicyRule>()))),
146                                ..Default::default()
147                            })),
148                            ..Default::default()
149                        }),
150                    ),
151                    (
152                        "resourceRules".into(),
153                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
154                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
155                                description: Some("`resourceRules` is a slice of ResourcePolicyRules that identify matching requests according to their verb and the target resource. At least one of `resourceRules` and `nonResourceRules` has to be non-empty.".into()),
156                                ..Default::default()
157                            })),
158                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
159                            array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
160                                items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::flowcontrol::v1::ResourcePolicyRule>()))),
161                                ..Default::default()
162                            })),
163                            ..Default::default()
164                        }),
165                    ),
166                    (
167                        "subjects".into(),
168                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
169                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
170                                description: Some("subjects is the list of normal user, serviceaccount, or group that this rule cares about. There must be at least one member in this slice. A slice that includes both the system:authenticated and system:unauthenticated user groups matches every request. Required.".into()),
171                                ..Default::default()
172                            })),
173                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Array))),
174                            array: Some(std::boxed::Box::new(crate::schemars::schema::ArrayValidation {
175                                items: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(__gen.subschema_for::<crate::api::flowcontrol::v1::Subject>()))),
176                                ..Default::default()
177                            })),
178                            ..Default::default()
179                        }),
180                    ),
181                ].into(),
182                required: [
183                    "subjects".into(),
184                ].into(),
185                ..Default::default()
186            })),
187            ..Default::default()
188        })
189    }
190}