k8s_openapi/v1_34/api/flowcontrol/v1/
policy_rules_with_subjects.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct PolicyRulesWithSubjects {
6 pub non_resource_rules: Option<std::vec::Vec<crate::api::flowcontrol::v1::NonResourcePolicyRule>>,
8
9 pub resource_rules: Option<std::vec::Vec<crate::api::flowcontrol::v1::ResourcePolicyRule>>,
11
12 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::borrow::Cow<'static, str> {
124 "io.k8s.api.flowcontrol.v1.PolicyRulesWithSubjects".into()
125 }
126
127 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
128 crate::schemars::json_schema!({
129 "description": "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.",
130 "type": "object",
131 "properties": {
132 "nonResourceRules": {
133 "description": "`nonResourceRules` is a list of NonResourcePolicyRules that identify matching requests according to their verb and the target non-resource URL.",
134 "type": "array",
135 "items": (__gen.subschema_for::<crate::api::flowcontrol::v1::NonResourcePolicyRule>()),
136 },
137 "resourceRules": {
138 "description": "`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.",
139 "type": "array",
140 "items": (__gen.subschema_for::<crate::api::flowcontrol::v1::ResourcePolicyRule>()),
141 },
142 "subjects": {
143 "description": "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.",
144 "type": "array",
145 "items": (__gen.subschema_for::<crate::api::flowcontrol::v1::Subject>()),
146 },
147 },
148 "required": [
149 "subjects",
150 ],
151 })
152 }
153}