k8s_openapi/v1_32/api/admissionregistration/v1alpha1/
param_ref.rs

1// Generated from definition io.k8s.api.admissionregistration.v1alpha1.ParamRef
2
3/// 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.
9    pub name: Option<String>,
10
11    /// 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.
18    pub namespace: Option<String>,
19
20    /// `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`
23    pub parameter_not_found_action: Option<String>,
24
25    /// 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.
30    pub selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>,
31}
32
33impl crate::DeepMerge for ParamRef {
34    fn merge_from(&mut self, other: Self) {
35        crate::DeepMerge::merge_from(&mut self.name, other.name);
36        crate::DeepMerge::merge_from(&mut self.namespace, other.namespace);
37        crate::DeepMerge::merge_from(&mut self.parameter_not_found_action, other.parameter_not_found_action);
38        crate::DeepMerge::merge_from(&mut self.selector, other.selector);
39    }
40}
41
42impl<'de> crate::serde::Deserialize<'de> for ParamRef {
43    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
44        #[allow(non_camel_case_types)]
45        enum Field {
46            Key_name,
47            Key_namespace,
48            Key_parameter_not_found_action,
49            Key_selector,
50            Other,
51        }
52
53        impl<'de> crate::serde::Deserialize<'de> for Field {
54            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
55                struct Visitor;
56
57                impl crate::serde::de::Visitor<'_> for Visitor {
58                    type Value = Field;
59
60                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
61                        f.write_str("field identifier")
62                    }
63
64                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
65                        Ok(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                }
74
75                deserializer.deserialize_identifier(Visitor)
76            }
77        }
78
79        struct Visitor;
80
81        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
82            type Value = ParamRef;
83
84            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
85                f.write_str("ParamRef")
86            }
87
88            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
89                let mut value_name: Option<String> = None;
90                let mut value_namespace: Option<String> = None;
91                let mut value_parameter_not_found_action: Option<String> = None;
92                let mut value_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector> = None;
93
94                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
95                    match 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                }
103
104                Ok(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        }
112
113        deserializer.deserialize_struct(
114            "ParamRef",
115            &[
116                "name",
117                "namespace",
118                "parameterNotFoundAction",
119                "selector",
120            ],
121            Visitor,
122        )
123    }
124}
125
126impl crate::serde::Serialize for ParamRef {
127    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
128        let mut state = serializer.serialize_struct(
129            "ParamRef",
130            self.name.as_ref().map_or(0, |_| 1) +
131            self.namespace.as_ref().map_or(0, |_| 1) +
132            self.parameter_not_found_action.as_ref().map_or(0, |_| 1) +
133            self.selector.as_ref().map_or(0, |_| 1),
134        )?;
135        if let Some(value) = &self.name {
136            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", value)?;
137        }
138        if let Some(value) = &self.namespace {
139            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "namespace", value)?;
140        }
141        if let Some(value) = &self.parameter_not_found_action {
142            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "parameterNotFoundAction", value)?;
143        }
144        if let Some(value) = &self.selector {
145            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "selector", value)?;
146        }
147        crate::serde::ser::SerializeStruct::end(state)
148    }
149}
150
151#[cfg(feature = "schemars")]
152impl crate::schemars::JsonSchema for ParamRef {
153    fn schema_name() -> String {
154        "io.k8s.api.admissionregistration.v1alpha1.ParamRef".to_owned()
155    }
156
157    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
158        crate::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(),
168                        crate::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(),
179                        crate::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(),
190                        crate::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                        {
202                            let 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                            }));
207                            crate::schemars::schema::Schema::Object(schema_obj)
208                        },
209                    ),
210                ].into(),
211                ..Default::default()
212            })),
213            ..Default::default()
214        })
215    }
216}