1// Generated from definition io.k8s.api.admissionregistration.v1alpha1.ParamRef
23/// ParamRef describes how to locate the params to be used as input to expressions of rules applied by a policy binding.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ParamRef {
6/// `name` is the name of the resource being referenced.
7 ///
8 /// `name` and `selector` are mutually exclusive properties. If one is set, the other must be unset.
9pub name: Option<String>,
1011/// namespace is the namespace of the referenced resource. Allows limiting the search for params to a specific namespace. Applies to both `name` and `selector` fields.
12 ///
13 /// A per-namespace parameter may be used by specifying a namespace-scoped `paramKind` in the policy and leaving this field empty.
14 ///
15 /// - If `paramKind` is cluster-scoped, this field MUST be unset. Setting this field results in a configuration error.
16 ///
17 /// - If `paramKind` is namespace-scoped, the namespace of the object being evaluated for admission will be used when this field is left unset. Take care that if this is left empty the binding must not match any cluster-scoped resources, which will result in an error.
18pub namespace: Option<String>,
1920/// `parameterNotFoundAction` controls the behavior of the binding when the resource exists, and name or selector is valid, but there are no parameters matched by the binding. If the value is set to `Allow`, then no matched parameters will be treated as successful validation by the binding. If set to `Deny`, then no matched parameters will be subject to the `failurePolicy` of the policy.
21 ///
22 /// Allowed values are `Allow` or `Deny` Default to `Deny`
23pub parameter_not_found_action: Option<String>,
2425/// selector can be used to match multiple param objects based on their labels. Supply selector: {} to match all resources of the ParamKind.
26 ///
27 /// If multiple params are found, they are all evaluated with the policy expressions and the results are ANDed together.
28 ///
29 /// One of `name` or `selector` must be set, but `name` and `selector` are mutually exclusive properties. If one is set, the other must be unset.
30pub selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>,
31}
3233impl crate::DeepMerge for ParamRef {
34fn merge_from(&mut self, other: Self) {
35crate::DeepMerge::merge_from(&mut self.name, other.name);
36crate::DeepMerge::merge_from(&mut self.namespace, other.namespace);
37crate::DeepMerge::merge_from(&mut self.parameter_not_found_action, other.parameter_not_found_action);
38crate::DeepMerge::merge_from(&mut self.selector, other.selector);
39 }
40}
4142impl<'de> crate::serde::Deserialize<'de> for ParamRef {
43fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
44#[allow(non_camel_case_types)]
45enum Field {
46 Key_name,
47 Key_namespace,
48 Key_parameter_not_found_action,
49 Key_selector,
50 Other,
51 }
5253impl<'de> crate::serde::Deserialize<'de> for Field {
54fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
55struct Visitor;
5657impl<'de> crate::serde::de::Visitor<'de> for Visitor {
58type Value = Field;
5960fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
61 f.write_str("field identifier")
62 }
6364fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
65Ok(match v {
66"name" => Field::Key_name,
67"namespace" => Field::Key_namespace,
68"parameterNotFoundAction" => Field::Key_parameter_not_found_action,
69"selector" => Field::Key_selector,
70_ => Field::Other,
71 })
72 }
73 }
7475 deserializer.deserialize_identifier(Visitor)
76 }
77 }
7879struct Visitor;
8081impl<'de> crate::serde::de::Visitor<'de> for Visitor {
82type Value = ParamRef;
8384fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
85 f.write_str("ParamRef")
86 }
8788fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
89let mut value_name: Option<String> = None;
90let mut value_namespace: Option<String> = None;
91let mut value_parameter_not_found_action: Option<String> = None;
92let mut value_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector> = None;
9394while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
95match key {
96 Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
97 Field::Key_namespace => value_namespace = crate::serde::de::MapAccess::next_value(&mut map)?,
98 Field::Key_parameter_not_found_action => value_parameter_not_found_action = crate::serde::de::MapAccess::next_value(&mut map)?,
99 Field::Key_selector => value_selector = crate::serde::de::MapAccess::next_value(&mut map)?,
100 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
101 }
102 }
103104Ok(ParamRef {
105 name: value_name,
106 namespace: value_namespace,
107 parameter_not_found_action: value_parameter_not_found_action,
108 selector: value_selector,
109 })
110 }
111 }
112113 deserializer.deserialize_struct(
114"ParamRef",
115&[
116"name",
117"namespace",
118"parameterNotFoundAction",
119"selector",
120 ],
121 Visitor,
122 )
123 }
124}
125126impl crate::serde::Serialize for ParamRef {
127fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
128let mut state = serializer.serialize_struct(
129"ParamRef",
130self.name.as_ref().map_or(0, |_| 1) +
131self.namespace.as_ref().map_or(0, |_| 1) +
132self.parameter_not_found_action.as_ref().map_or(0, |_| 1) +
133self.selector.as_ref().map_or(0, |_| 1),
134 )?;
135if let Some(value) = &self.name {
136crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", value)?;
137 }
138if let Some(value) = &self.namespace {
139crate::serde::ser::SerializeStruct::serialize_field(&mut state, "namespace", value)?;
140 }
141if let Some(value) = &self.parameter_not_found_action {
142crate::serde::ser::SerializeStruct::serialize_field(&mut state, "parameterNotFoundAction", value)?;
143 }
144if let Some(value) = &self.selector {
145crate::serde::ser::SerializeStruct::serialize_field(&mut state, "selector", value)?;
146 }
147crate::serde::ser::SerializeStruct::end(state)
148 }
149}
150151#[cfg(feature = "schemars")]
152impl crate::schemars::JsonSchema for ParamRef {
153fn schema_name() -> String {
154"io.k8s.api.admissionregistration.v1alpha1.ParamRef".to_owned()
155 }
156157fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
158crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
159 metadata: Some(Box::new(crate::schemars::schema::Metadata {
160 description: Some("ParamRef describes how to locate the params to be used as input to expressions of rules applied by a policy binding.".to_owned()),
161 ..Default::default()
162 })),
163 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
164 object: Some(Box::new(crate::schemars::schema::ObjectValidation {
165 properties: [
166 (
167"name".to_owned(),
168crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
169 metadata: Some(Box::new(crate::schemars::schema::Metadata {
170 description: Some("`name` is the name of the resource being referenced.\n\n`name` and `selector` are mutually exclusive properties. If one is set, the other must be unset.".to_owned()),
171 ..Default::default()
172 })),
173 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
174 ..Default::default()
175 }),
176 ),
177 (
178"namespace".to_owned(),
179crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
180 metadata: Some(Box::new(crate::schemars::schema::Metadata {
181 description: Some("namespace is the namespace of the referenced resource. Allows limiting the search for params to a specific namespace. Applies to both `name` and `selector` fields.\n\nA per-namespace parameter may be used by specifying a namespace-scoped `paramKind` in the policy and leaving this field empty.\n\n- If `paramKind` is cluster-scoped, this field MUST be unset. Setting this field results in a configuration error.\n\n- If `paramKind` is namespace-scoped, the namespace of the object being evaluated for admission will be used when this field is left unset. Take care that if this is left empty the binding must not match any cluster-scoped resources, which will result in an error.".to_owned()),
182 ..Default::default()
183 })),
184 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
185 ..Default::default()
186 }),
187 ),
188 (
189"parameterNotFoundAction".to_owned(),
190crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
191 metadata: Some(Box::new(crate::schemars::schema::Metadata {
192 description: Some("`parameterNotFoundAction` controls the behavior of the binding when the resource exists, and name or selector is valid, but there are no parameters matched by the binding. If the value is set to `Allow`, then no matched parameters will be treated as successful validation by the binding. If set to `Deny`, then no matched parameters will be subject to the `failurePolicy` of the policy.\n\nAllowed values are `Allow` or `Deny` Default to `Deny`".to_owned()),
193 ..Default::default()
194 })),
195 instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::String))),
196 ..Default::default()
197 }),
198 ),
199 (
200"selector".to_owned(),
201 {
202let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>().into_object();
203 schema_obj.metadata = Some(Box::new(crate::schemars::schema::Metadata {
204 description: Some("selector can be used to match multiple param objects based on their labels. Supply selector: {} to match all resources of the ParamKind.\n\nIf multiple params are found, they are all evaluated with the policy expressions and the results are ANDed together.\n\nOne of `name` or `selector` must be set, but `name` and `selector` are mutually exclusive properties. If one is set, the other must be unset.".to_owned()),
205 ..Default::default()
206 }));
207crate::schemars::schema::Schema::Object(schema_obj)
208 },
209 ),
210 ].into(),
211 ..Default::default()
212 })),
213 ..Default::default()
214 })
215 }
216}