#[derive(Clone, Debug, Default, PartialEq)]
pub struct ValidatingWebhook {
pub admission_review_versions: Option<Vec<String>>,
pub client_config: crate::api::admissionregistration::v1beta1::WebhookClientConfig,
pub failure_policy: Option<String>,
pub match_policy: Option<String>,
pub name: String,
pub namespace_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>,
pub object_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector>,
pub rules: Option<Vec<crate::api::admissionregistration::v1beta1::RuleWithOperations>>,
pub side_effects: Option<String>,
pub timeout_seconds: Option<i32>,
}
impl<'de> serde::Deserialize<'de> for ValidatingWebhook {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de> {
#[allow(non_camel_case_types)]
enum Field {
Key_admission_review_versions,
Key_client_config,
Key_failure_policy,
Key_match_policy,
Key_name,
Key_namespace_selector,
Key_object_selector,
Key_rules,
Key_side_effects,
Key_timeout_seconds,
Other,
}
impl<'de> serde::Deserialize<'de> for Field {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de> {
struct Visitor;
impl<'de> serde::de::Visitor<'de> for Visitor {
type Value = Field;
fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("field identifier")
}
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: serde::de::Error {
Ok(match v {
"admissionReviewVersions" => Field::Key_admission_review_versions,
"clientConfig" => Field::Key_client_config,
"failurePolicy" => Field::Key_failure_policy,
"matchPolicy" => Field::Key_match_policy,
"name" => Field::Key_name,
"namespaceSelector" => Field::Key_namespace_selector,
"objectSelector" => Field::Key_object_selector,
"rules" => Field::Key_rules,
"sideEffects" => Field::Key_side_effects,
"timeoutSeconds" => Field::Key_timeout_seconds,
_ => Field::Other,
})
}
}
deserializer.deserialize_identifier(Visitor)
}
}
struct Visitor;
impl<'de> serde::de::Visitor<'de> for Visitor {
type Value = ValidatingWebhook;
fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("ValidatingWebhook")
}
fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: serde::de::MapAccess<'de> {
let mut value_admission_review_versions: Option<Vec<String>> = None;
let mut value_client_config: Option<crate::api::admissionregistration::v1beta1::WebhookClientConfig> = None;
let mut value_failure_policy: Option<String> = None;
let mut value_match_policy: Option<String> = None;
let mut value_name: Option<String> = None;
let mut value_namespace_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector> = None;
let mut value_object_selector: Option<crate::apimachinery::pkg::apis::meta::v1::LabelSelector> = None;
let mut value_rules: Option<Vec<crate::api::admissionregistration::v1beta1::RuleWithOperations>> = None;
let mut value_side_effects: Option<String> = None;
let mut value_timeout_seconds: Option<i32> = None;
while let Some(key) = serde::de::MapAccess::next_key::<Field>(&mut map)? {
match key {
Field::Key_admission_review_versions => value_admission_review_versions = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_client_config => value_client_config = Some(serde::de::MapAccess::next_value(&mut map)?),
Field::Key_failure_policy => value_failure_policy = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_match_policy => value_match_policy = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_name => value_name = Some(serde::de::MapAccess::next_value(&mut map)?),
Field::Key_namespace_selector => value_namespace_selector = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_object_selector => value_object_selector = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_rules => value_rules = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_side_effects => value_side_effects = serde::de::MapAccess::next_value(&mut map)?,
Field::Key_timeout_seconds => value_timeout_seconds = serde::de::MapAccess::next_value(&mut map)?,
Field::Other => { let _: serde::de::IgnoredAny = serde::de::MapAccess::next_value(&mut map)?; },
}
}
Ok(ValidatingWebhook {
admission_review_versions: value_admission_review_versions,
client_config: value_client_config.ok_or_else(|| serde::de::Error::missing_field("clientConfig"))?,
failure_policy: value_failure_policy,
match_policy: value_match_policy,
name: value_name.ok_or_else(|| serde::de::Error::missing_field("name"))?,
namespace_selector: value_namespace_selector,
object_selector: value_object_selector,
rules: value_rules,
side_effects: value_side_effects,
timeout_seconds: value_timeout_seconds,
})
}
}
deserializer.deserialize_struct(
"ValidatingWebhook",
&[
"admissionReviewVersions",
"clientConfig",
"failurePolicy",
"matchPolicy",
"name",
"namespaceSelector",
"objectSelector",
"rules",
"sideEffects",
"timeoutSeconds",
],
Visitor,
)
}
}
impl serde::Serialize for ValidatingWebhook {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer {
let mut state = serializer.serialize_struct(
"ValidatingWebhook",
2 +
self.admission_review_versions.as_ref().map_or(0, |_| 1) +
self.failure_policy.as_ref().map_or(0, |_| 1) +
self.match_policy.as_ref().map_or(0, |_| 1) +
self.namespace_selector.as_ref().map_or(0, |_| 1) +
self.object_selector.as_ref().map_or(0, |_| 1) +
self.rules.as_ref().map_or(0, |_| 1) +
self.side_effects.as_ref().map_or(0, |_| 1) +
self.timeout_seconds.as_ref().map_or(0, |_| 1),
)?;
if let Some(value) = &self.admission_review_versions {
serde::ser::SerializeStruct::serialize_field(&mut state, "admissionReviewVersions", value)?;
}
serde::ser::SerializeStruct::serialize_field(&mut state, "clientConfig", &self.client_config)?;
if let Some(value) = &self.failure_policy {
serde::ser::SerializeStruct::serialize_field(&mut state, "failurePolicy", value)?;
}
if let Some(value) = &self.match_policy {
serde::ser::SerializeStruct::serialize_field(&mut state, "matchPolicy", value)?;
}
serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
if let Some(value) = &self.namespace_selector {
serde::ser::SerializeStruct::serialize_field(&mut state, "namespaceSelector", value)?;
}
if let Some(value) = &self.object_selector {
serde::ser::SerializeStruct::serialize_field(&mut state, "objectSelector", value)?;
}
if let Some(value) = &self.rules {
serde::ser::SerializeStruct::serialize_field(&mut state, "rules", value)?;
}
if let Some(value) = &self.side_effects {
serde::ser::SerializeStruct::serialize_field(&mut state, "sideEffects", value)?;
}
if let Some(value) = &self.timeout_seconds {
serde::ser::SerializeStruct::serialize_field(&mut state, "timeoutSeconds", value)?;
}
serde::ser::SerializeStruct::end(state)
}
}