openshift_openapi/v4_5/api/build/v1/
docker_strategy_options.rs

1// Generated from definition com.github.openshift.api.build.v1.DockerStrategyOptions
2
3/// DockerStrategyOptions contains extra strategy options for container image builds
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct DockerStrategyOptions {
6    /// Args contains any build arguments that are to be passed to Docker.  See https://docs.docker.com/engine/reference/builder/#/arg for more details
7    pub build_args: Option<Vec<k8s_openapi::api::core::v1::EnvVar>>,
8
9    /// noCache overrides the docker-strategy noCache option in the build config
10    pub no_cache: Option<bool>,
11}
12
13impl<'de> serde::Deserialize<'de> for DockerStrategyOptions {
14    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de> {
15        #[allow(non_camel_case_types)]
16        enum Field {
17            Key_build_args,
18            Key_no_cache,
19            Other,
20        }
21
22        impl<'de> serde::Deserialize<'de> for Field {
23            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: serde::Deserializer<'de> {
24                struct Visitor;
25
26                impl<'de> serde::de::Visitor<'de> for Visitor {
27                    type Value = Field;
28
29                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
30                        f.write_str("field identifier")
31                    }
32
33                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: serde::de::Error {
34                        Ok(match v {
35                            "buildArgs" => Field::Key_build_args,
36                            "noCache" => Field::Key_no_cache,
37                            _ => Field::Other,
38                        })
39                    }
40                }
41
42                deserializer.deserialize_identifier(Visitor)
43            }
44        }
45
46        struct Visitor;
47
48        impl<'de> serde::de::Visitor<'de> for Visitor {
49            type Value = DockerStrategyOptions;
50
51            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
52                f.write_str("DockerStrategyOptions")
53            }
54
55            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: serde::de::MapAccess<'de> {
56                let mut value_build_args: Option<Vec<k8s_openapi::api::core::v1::EnvVar>> = None;
57                let mut value_no_cache: Option<bool> = None;
58
59                while let Some(key) = serde::de::MapAccess::next_key::<Field>(&mut map)? {
60                    match key {
61                        Field::Key_build_args => value_build_args = serde::de::MapAccess::next_value(&mut map)?,
62                        Field::Key_no_cache => value_no_cache = serde::de::MapAccess::next_value(&mut map)?,
63                        Field::Other => { let _: serde::de::IgnoredAny = serde::de::MapAccess::next_value(&mut map)?; },
64                    }
65                }
66
67                Ok(DockerStrategyOptions {
68                    build_args: value_build_args,
69                    no_cache: value_no_cache,
70                })
71            }
72        }
73
74        deserializer.deserialize_struct(
75            "DockerStrategyOptions",
76            &[
77                "buildArgs",
78                "noCache",
79            ],
80            Visitor,
81        )
82    }
83}
84
85impl serde::Serialize for DockerStrategyOptions {
86    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: serde::Serializer {
87        let mut state = serializer.serialize_struct(
88            "DockerStrategyOptions",
89            self.build_args.as_ref().map_or(0, |_| 1) +
90            self.no_cache.as_ref().map_or(0, |_| 1),
91        )?;
92        if let Some(value) = &self.build_args {
93            serde::ser::SerializeStruct::serialize_field(&mut state, "buildArgs", value)?;
94        }
95        if let Some(value) = &self.no_cache {
96            serde::ser::SerializeStruct::serialize_field(&mut state, "noCache", value)?;
97        }
98        serde::ser::SerializeStruct::end(state)
99    }
100}