#
k8s_openapi/v1_35/api/core/v1/
env_from_source.rs

    1// Generated from definition io.k8s.api.core.v1.EnvFromSource
    2
    3/// EnvFromSource represents the source of a set of ConfigMaps or Secrets
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct EnvFromSource {
    6    /// The ConfigMap to select from
    7    pub config_map_ref: Option<crate::api::core::v1::ConfigMapEnvSource>,
    8
    9    /// Optional text to prepend to the name of each environment variable. May consist of any printable ASCII characters except '='.
    10    pub prefix: Option<std::string::String>,
    11
    12    /// The Secret to select from
    13    pub secret_ref: Option<crate::api::core::v1::SecretEnvSource>,
    14}
    15
    16impl crate::DeepMerge for EnvFromSource {
    17    fn merge_from(&mut self, other: Self) {
    18        crate::DeepMerge::merge_from(&mut self.config_map_ref, other.config_map_ref);
    19        crate::DeepMerge::merge_from(&mut self.prefix, other.prefix);
    20        crate::DeepMerge::merge_from(&mut self.secret_ref, other.secret_ref);
    21    }
    22}
    23
    24impl<'de> crate::serde::Deserialize<'de> for EnvFromSource {
    25    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    26        #[allow(non_camel_case_types)]
    27        enum Field {
    28            Key_config_map_ref,
    29            Key_prefix,
    30            Key_secret_ref,
    31            Other,
    32        }
    33
    34        impl<'de> crate::serde::Deserialize<'de> for Field {
    35            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    36                struct Visitor;
    37
    38                impl crate::serde::de::Visitor<'_> for Visitor {
    39                    type Value = Field;
    40
    41                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    42                        f.write_str("field identifier")
    43                    }
    44
    45                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    46                        Ok(match v {
    47                            "configMapRef" => Field::Key_config_map_ref,
    48                            "prefix" => Field::Key_prefix,
    49                            "secretRef" => Field::Key_secret_ref,
    50                            _ => Field::Other,
    51                        })
    52                    }
    53                }
    54
    55                deserializer.deserialize_identifier(Visitor)
    56            }
    57        }
    58
    59        struct Visitor;
    60
    61        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    62            type Value = EnvFromSource;
    63
    64            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    65                f.write_str("EnvFromSource")
    66            }
    67
    68            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    69                let mut value_config_map_ref: Option<crate::api::core::v1::ConfigMapEnvSource> = None;
    70                let mut value_prefix: Option<std::string::String> = None;
    71                let mut value_secret_ref: Option<crate::api::core::v1::SecretEnvSource> = None;
    72
    73                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    74                    match key {
    75                        Field::Key_config_map_ref => value_config_map_ref = crate::serde::de::MapAccess::next_value(&mut map)?,
    76                        Field::Key_prefix => value_prefix = crate::serde::de::MapAccess::next_value(&mut map)?,
    77                        Field::Key_secret_ref => value_secret_ref = crate::serde::de::MapAccess::next_value(&mut map)?,
    78                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    79                    }
    80                }
    81
    82                Ok(EnvFromSource {
    83                    config_map_ref: value_config_map_ref,
    84                    prefix: value_prefix,
    85                    secret_ref: value_secret_ref,
    86                })
    87            }
    88        }
    89
    90        deserializer.deserialize_struct(
    91            "EnvFromSource",
    92            &[
    93                "configMapRef",
    94                "prefix",
    95                "secretRef",
    96            ],
    97            Visitor,
    98        )
    99    }
    100}
    101
    102impl crate::serde::Serialize for EnvFromSource {
    103    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    104        let mut state = serializer.serialize_struct(
    105            "EnvFromSource",
    106            self.config_map_ref.as_ref().map_or(0, |_| 1) +
    107            self.prefix.as_ref().map_or(0, |_| 1) +
    108            self.secret_ref.as_ref().map_or(0, |_| 1),
    109        )?;
    110        if let Some(value) = &self.config_map_ref {
    111            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "configMapRef", value)?;
    112        }
    113        if let Some(value) = &self.prefix {
    114            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "prefix", value)?;
    115        }
    116        if let Some(value) = &self.secret_ref {
    117            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "secretRef", value)?;
    118        }
    119        crate::serde::ser::SerializeStruct::end(state)
    120    }
    121}
    122
    123#[cfg(feature = "schemars")]
    124impl crate::schemars::JsonSchema for EnvFromSource {
    125    fn schema_name() -> std::borrow::Cow<'static, str> {
    126        "io.k8s.api.core.v1.EnvFromSource".into()
    127    }
    128
    129    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    130        crate::schemars::json_schema!({
    131            "description": "EnvFromSource represents the source of a set of ConfigMaps or Secrets",
    132            "type": "object",
    133            "properties": {
    134                "configMapRef": ({
    135                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::ConfigMapEnvSource>();
    136                    schema_obj.ensure_object().insert("description".into(), "The ConfigMap to select from".into());
    137                    schema_obj
    138                }),
    139                "prefix": {
    140                    "description": "Optional text to prepend to the name of each environment variable. May consist of any printable ASCII characters except '='.",
    141                    "type": "string",
    142                },
    143                "secretRef": ({
    144                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::SecretEnvSource>();
    145                    schema_obj.ensure_object().insert("description".into(), "The Secret to select from".into());
    146                    schema_obj
    147                }),
    148            },
    149        })
    150    }
    151}