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

    1// Generated from definition io.k8s.api.core.v1.Secret
    2
    3/// Secret holds secret data of a certain type. The total bytes of the values in the Data field must be less than MaxSecretSize bytes.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct Secret {
    6    /// Data contains the secret data. Each key must consist of alphanumeric characters, '-', '_' or '.'. The serialized form of the secret data is a base64 encoded string, representing the arbitrary (possibly non-string) data value here. Described in https://tools.ietf.org/html/rfc4648#section-4
    7    pub data: Option<std::collections::BTreeMap<std::string::String, crate::ByteString>>,
    8
    9    /// Immutable, if set to true, ensures that data stored in the Secret cannot be updated (only object metadata can be modified). If not set to true, the field can be modified at any time. Defaulted to nil.
    10    pub immutable: Option<bool>,
    11
    12    /// Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
    13    pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
    14
    15    /// stringData allows specifying non-binary secret data in string form. It is provided as a write-only input field for convenience. All keys and values are merged into the data field on write, overwriting any existing values. The stringData field is never output when reading from the API.
    16    pub string_data: Option<std::collections::BTreeMap<std::string::String, std::string::String>>,
    17
    18    /// Used to facilitate programmatic handling of secret data. More info: https://kubernetes.io/docs/concepts/configuration/secret/#secret-types
    19    pub type_: Option<std::string::String>,
    20}
    21
    22impl crate::Resource for Secret {
    23    const API_VERSION: &'static str = "v1";
    24    const GROUP: &'static str = "";
    25    const KIND: &'static str = "Secret";
    26    const VERSION: &'static str = "v1";
    27    const URL_PATH_SEGMENT: &'static str = "secrets";
    28    type Scope = crate::NamespaceResourceScope;
    29}
    30
    31impl crate::ListableResource for Secret {
    32    const LIST_KIND: &'static str = "SecretList";
    33}
    34
    35impl crate::Metadata for Secret {
    36    type Ty = crate::apimachinery::pkg::apis::meta::v1::ObjectMeta;
    37
    38    fn metadata(&self) -> &<Self as crate::Metadata>::Ty {
    39        &self.metadata
    40    }
    41
    42    fn metadata_mut(&mut self) -> &mut<Self as crate::Metadata>::Ty {
    43        &mut self.metadata
    44    }
    45}
    46
    47impl crate::DeepMerge for Secret {
    48    fn merge_from(&mut self, other: Self) {
    49        crate::merge_strategies::map::granular(&mut self.data, other.data, |current_item, other_item| {
    50            crate::DeepMerge::merge_from(current_item, other_item);
    51        });
    52        crate::DeepMerge::merge_from(&mut self.immutable, other.immutable);
    53        crate::DeepMerge::merge_from(&mut self.metadata, other.metadata);
    54        crate::merge_strategies::map::granular(&mut self.string_data, other.string_data, |current_item, other_item| {
    55            crate::DeepMerge::merge_from(current_item, other_item);
    56        });
    57        crate::DeepMerge::merge_from(&mut self.type_, other.type_);
    58    }
    59}
    60
    61impl<'de> crate::serde::Deserialize<'de> for Secret {
    62    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    63        #[allow(non_camel_case_types)]
    64        enum Field {
    65            Key_api_version,
    66            Key_kind,
    67            Key_data,
    68            Key_immutable,
    69            Key_metadata,
    70            Key_string_data,
    71            Key_type_,
    72            Other,
    73        }
    74
    75        impl<'de> crate::serde::Deserialize<'de> for Field {
    76            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    77                struct Visitor;
    78
    79                impl crate::serde::de::Visitor<'_> for Visitor {
    80                    type Value = Field;
    81
    82                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    83                        f.write_str("field identifier")
    84                    }
    85
    86                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    87                        Ok(match v {
    88                            "apiVersion" => Field::Key_api_version,
    89                            "kind" => Field::Key_kind,
    90                            "data" => Field::Key_data,
    91                            "immutable" => Field::Key_immutable,
    92                            "metadata" => Field::Key_metadata,
    93                            "stringData" => Field::Key_string_data,
    94                            "type" => Field::Key_type_,
    95                            _ => Field::Other,
    96                        })
    97                    }
    98                }
    99
    100                deserializer.deserialize_identifier(Visitor)
    101            }
    102        }
    103
    104        struct Visitor;
    105
    106        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    107            type Value = Secret;
    108
    109            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    110                f.write_str(<Self::Value as crate::Resource>::KIND)
    111            }
    112
    113            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    114                let mut value_data: Option<std::collections::BTreeMap<std::string::String, crate::ByteString>> = None;
    115                let mut value_immutable: Option<bool> = None;
    116                let mut value_metadata: Option<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta> = None;
    117                let mut value_string_data: Option<std::collections::BTreeMap<std::string::String, std::string::String>> = None;
    118                let mut value_type_: Option<std::string::String> = None;
    119
    120                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    121                    match key {
    122                        Field::Key_api_version => {
    123                            let value_api_version: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
    124                            if value_api_version != <Self::Value as crate::Resource>::API_VERSION {
    125                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_api_version), &<Self::Value as crate::Resource>::API_VERSION));
    126                            }
    127                        },
    128                        Field::Key_kind => {
    129                            let value_kind: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
    130                            if value_kind != <Self::Value as crate::Resource>::KIND {
    131                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_kind), &<Self::Value as crate::Resource>::KIND));
    132                            }
    133                        },
    134                        Field::Key_data => value_data = crate::serde::de::MapAccess::next_value(&mut map)?,
    135                        Field::Key_immutable => value_immutable = crate::serde::de::MapAccess::next_value(&mut map)?,
    136                        Field::Key_metadata => value_metadata = crate::serde::de::MapAccess::next_value(&mut map)?,
    137                        Field::Key_string_data => value_string_data = crate::serde::de::MapAccess::next_value(&mut map)?,
    138                        Field::Key_type_ => value_type_ = crate::serde::de::MapAccess::next_value(&mut map)?,
    139                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    140                    }
    141                }
    142
    143                Ok(Secret {
    144                    data: value_data,
    145                    immutable: value_immutable,
    146                    metadata: value_metadata.unwrap_or_default(),
    147                    string_data: value_string_data,
    148                    type_: value_type_,
    149                })
    150            }
    151        }
    152
    153        deserializer.deserialize_struct(
    154            <Self as crate::Resource>::KIND,
    155            &[
    156                "apiVersion",
    157                "kind",
    158                "data",
    159                "immutable",
    160                "metadata",
    161                "stringData",
    162                "type",
    163            ],
    164            Visitor,
    165        )
    166    }
    167}
    168
    169impl crate::serde::Serialize for Secret {
    170    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    171        let mut state = serializer.serialize_struct(
    172            <Self as crate::Resource>::KIND,
    173            3 +
    174            self.data.as_ref().map_or(0, |_| 1) +
    175            self.immutable.as_ref().map_or(0, |_| 1) +
    176            self.string_data.as_ref().map_or(0, |_| 1) +
    177            self.type_.as_ref().map_or(0, |_| 1),
    178        )?;
    179        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as crate::Resource>::API_VERSION)?;
    180        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as crate::Resource>::KIND)?;
    181        if let Some(value) = &self.data {
    182            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "data", value)?;
    183        }
    184        if let Some(value) = &self.immutable {
    185            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "immutable", value)?;
    186        }
    187        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
    188        if let Some(value) = &self.string_data {
    189            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "stringData", value)?;
    190        }
    191        if let Some(value) = &self.type_ {
    192            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "type", value)?;
    193        }
    194        crate::serde::ser::SerializeStruct::end(state)
    195    }
    196}
    197
    198#[cfg(feature = "schemars")]
    199impl crate::schemars::JsonSchema for Secret {
    200    fn schema_name() -> std::borrow::Cow<'static, str> {
    201        "io.k8s.api.core.v1.Secret".into()
    202    }
    203
    204    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    205        crate::schemars::json_schema!({
    206            "description": "Secret holds secret data of a certain type. The total bytes of the values in the Data field must be less than MaxSecretSize bytes.",
    207            "type": "object",
    208            "properties": {
    209                "apiVersion": {
    210                    "description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
    211                    "type": "string",
    212                },
    213                "data": {
    214                    "description": "Data contains the secret data. Each key must consist of alphanumeric characters, '-', '_' or '.'. The serialized form of the secret data is a base64 encoded string, representing the arbitrary (possibly non-string) data value here. Described in https://tools.ietf.org/html/rfc4648#section-4",
    215                    "type": "object",
    216                    "additionalProperties": {
    217                        "type": "string",
    218                        "format": "byte",
    219                    },
    220                },
    221                "immutable": {
    222                    "description": "Immutable, if set to true, ensures that data stored in the Secret cannot be updated (only object metadata can be modified). If not set to true, the field can be modified at any time. Defaulted to nil.",
    223                    "type": "boolean",
    224                },
    225                "kind": {
    226                    "description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
    227                    "type": "string",
    228                },
    229                "metadata": ({
    230                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>();
    231                    schema_obj.ensure_object().insert("description".into(), "Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata".into());
    232                    schema_obj
    233                }),
    234                "stringData": {
    235                    "description": "stringData allows specifying non-binary secret data in string form. It is provided as a write-only input field for convenience. All keys and values are merged into the data field on write, overwriting any existing values. The stringData field is never output when reading from the API.",
    236                    "type": "object",
    237                    "additionalProperties": {
    238                        "type": "string",
    239                    },
    240                },
    241                "type": {
    242                    "description": "Used to facilitate programmatic handling of secret data. More info: https://kubernetes.io/docs/concepts/configuration/secret/#secret-types",
    243                    "type": "string",
    244                },
    245            },
    246            "required": [
    247                "metadata",
    248            ],
    249        })
    250    }
    251}