k8s_openapi/v1_34/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<std::string::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<std::string::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<std::string::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 core::fmt::Formatter<'_>) -> core::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 core::fmt::Formatter<'_>) -> core::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<std::string::String> = None;
90                let mut value_namespace: Option<std::string::String> = None;
91                let mut value_parameter_not_found_action: Option<std::string::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() -> std::borrow::Cow<'static, str> {
154        "io.k8s.api.admissionregistration.v1alpha1.ParamRef".into()
155    }
156
157    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
158        crate::schemars::json_schema!({
159            "description": "ParamRef describes how to locate the params to be used as input to expressions of rules applied by a policy binding.",
160            "type": "object",
161            "properties": {
162                "name": {
163                    "description": "`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.",
164                    "type": "string",
165                },
166                "namespace": {
167                    "description": "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.",
168                    "type": "string",
169                },
170                "parameterNotFoundAction": {
171                    "description": "`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`",
172                    "type": "string",
173                },
174                "selector": ({
175                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>();
176                    schema_obj.ensure_object().insert("description".into(), "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.".into());
177                    schema_obj
178                }),
179            },
180        })
181    }
182}