openshift_openapi/v4_5/api/authorization/v1/
policy_rule.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct PolicyRule {
6 pub api_groups: Vec<String>,
8
9 pub attribute_restrictions: Option<k8s_openapi::apimachinery::pkg::runtime::RawExtension>,
11
12 pub non_resource_urls: Option<Vec<String>>,
14
15 pub resource_names: Option<Vec<String>>,
17
18 pub resources: Vec<String>,
20
21 pub verbs: Vec<String>,
23}
24
25impl<'de> serde::Deserialize<'de> for PolicyRule {
26 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de> {
27 #[allow(non_camel_case_types)]
28 enum Field {
29 Key_api_groups,
30 Key_attribute_restrictions,
31 Key_non_resource_urls,
32 Key_resource_names,
33 Key_resources,
34 Key_verbs,
35 Other,
36 }
37
38 impl<'de> serde::Deserialize<'de> for Field {
39 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de> {
40 struct Visitor;
41
42 impl<'de> serde::de::Visitor<'de> for Visitor {
43 type Value = Field;
44
45 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
46 f.write_str("field identifier")
47 }
48
49 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: serde::de::Error {
50 Ok(match v {
51 "apiGroups" => Field::Key_api_groups,
52 "attributeRestrictions" => Field::Key_attribute_restrictions,
53 "nonResourceURLs" => Field::Key_non_resource_urls,
54 "resourceNames" => Field::Key_resource_names,
55 "resources" => Field::Key_resources,
56 "verbs" => Field::Key_verbs,
57 _ => Field::Other,
58 })
59 }
60 }
61
62 deserializer.deserialize_identifier(Visitor)
63 }
64 }
65
66 struct Visitor;
67
68 impl<'de> serde::de::Visitor<'de> for Visitor {
69 type Value = PolicyRule;
70
71 fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
72 f.write_str("PolicyRule")
73 }
74
75 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: serde::de::MapAccess<'de> {
76 let mut value_api_groups: Option<Vec<String>> = None;
77 let mut value_attribute_restrictions: Option<k8s_openapi::apimachinery::pkg::runtime::RawExtension> = None;
78 let mut value_non_resource_urls: Option<Vec<String>> = None;
79 let mut value_resource_names: Option<Vec<String>> = None;
80 let mut value_resources: Option<Vec<String>> = None;
81 let mut value_verbs: Option<Vec<String>> = None;
82
83 while let Some(key) = serde::de::MapAccess::next_key::<Field>(&mut map)? {
84 match key {
85 Field::Key_api_groups => value_api_groups = Some(serde::de::MapAccess::next_value(&mut map)?),
86 Field::Key_attribute_restrictions => value_attribute_restrictions = serde::de::MapAccess::next_value(&mut map)?,
87 Field::Key_non_resource_urls => value_non_resource_urls = serde::de::MapAccess::next_value(&mut map)?,
88 Field::Key_resource_names => value_resource_names = serde::de::MapAccess::next_value(&mut map)?,
89 Field::Key_resources => value_resources = Some(serde::de::MapAccess::next_value(&mut map)?),
90 Field::Key_verbs => value_verbs = Some(serde::de::MapAccess::next_value(&mut map)?),
91 Field::Other => { let _: serde::de::IgnoredAny = serde::de::MapAccess::next_value(&mut map)?; },
92 }
93 }
94
95 Ok(PolicyRule {
96 api_groups: value_api_groups.ok_or_else(|| serde::de::Error::missing_field("apiGroups"))?,
97 attribute_restrictions: value_attribute_restrictions,
98 non_resource_urls: value_non_resource_urls,
99 resource_names: value_resource_names,
100 resources: value_resources.ok_or_else(|| serde::de::Error::missing_field("resources"))?,
101 verbs: value_verbs.ok_or_else(|| serde::de::Error::missing_field("verbs"))?,
102 })
103 }
104 }
105
106 deserializer.deserialize_struct(
107 "PolicyRule",
108 &[
109 "apiGroups",
110 "attributeRestrictions",
111 "nonResourceURLs",
112 "resourceNames",
113 "resources",
114 "verbs",
115 ],
116 Visitor,
117 )
118 }
119}
120
121impl serde::Serialize for PolicyRule {
122 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer {
123 let mut state = serializer.serialize_struct(
124 "PolicyRule",
125 3 +
126 self.attribute_restrictions.as_ref().map_or(0, |_| 1) +
127 self.non_resource_urls.as_ref().map_or(0, |_| 1) +
128 self.resource_names.as_ref().map_or(0, |_| 1),
129 )?;
130 serde::ser::SerializeStruct::serialize_field(&mut state, "apiGroups", &self.api_groups)?;
131 if let Some(value) = &self.attribute_restrictions {
132 serde::ser::SerializeStruct::serialize_field(&mut state, "attributeRestrictions", value)?;
133 }
134 if let Some(value) = &self.non_resource_urls {
135 serde::ser::SerializeStruct::serialize_field(&mut state, "nonResourceURLs", value)?;
136 }
137 if let Some(value) = &self.resource_names {
138 serde::ser::SerializeStruct::serialize_field(&mut state, "resourceNames", value)?;
139 }
140 serde::ser::SerializeStruct::serialize_field(&mut state, "resources", &self.resources)?;
141 serde::ser::SerializeStruct::serialize_field(&mut state, "verbs", &self.verbs)?;
142 serde::ser::SerializeStruct::end(state)
143 }
144}