aws_lambda_events/event/codebuild/
mod.rs

1use crate::{
2    custom_serde::{codebuild_time, CodeBuildNumber},
3    encodings::{MinuteDuration, SecondDuration},
4};
5use chrono::{DateTime, Utc};
6use serde::{de::DeserializeOwned, Deserialize, Serialize};
7use serde_json::Value;
8
9pub type CodeBuildPhaseStatus = String;
10
11pub type CodeBuildPhaseType = String;
12
13/// `CodeBuildEvent` is documented at:
14/// <https://docs.aws.amazon.com/codebuild/latest/userguide/sample-build-notifications.html#sample-build-notifications-ref>
15#[non_exhaustive]
16#[derive(Debug, Default, Clone, PartialEq, Deserialize, Serialize)]
17#[serde(rename_all = "camelCase")]
18pub struct CodeBuildEvent {
19    /// AccountID is the id of the AWS account from which the event originated.
20    #[serde(default)]
21    #[serde(rename = "account")]
22    pub account_id: Option<String>,
23    /// Region is the AWS region from which the event originated.
24    #[serde(default)]
25    pub region: Option<String>,
26    /// DetailType informs the schema of the Detail field. For build state-change
27    /// events, the value will be CodeBuildStateChangeDetailType. For phase-change
28    /// events, it will be CodeBuildPhaseChangeDetailType.
29    #[serde(default)]
30    #[serde(rename = "detail-type")]
31    pub detail_type: Option<String>,
32    /// Source should be equal to CodeBuildEventSource.
33    #[serde(default)]
34    pub source: Option<String>,
35    /// Version is the version of the event's schema.
36    #[serde(default)]
37    pub version: Option<String>,
38    /// Time is the event's timestamp.
39    pub time: DateTime<Utc>,
40    /// ID is the GUID of this event.
41    #[serde(default)]
42    pub id: Option<String>,
43    /// Resources is a list of ARNs of CodeBuild builds that this event pertains to.
44    pub resources: Vec<String>,
45    /// Detail contains information specific to a build state-change or
46    /// build phase-change event.
47    pub detail: CodeBuildEventDetail,
48    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
49    /// Enabled with Cargo feature `catch-all-fields`.
50    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
51    #[cfg(feature = "catch-all-fields")]
52    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
53    #[serde(flatten)]
54    pub other: serde_json::Map<String, Value>,
55}
56
57/// `CodeBuildEventDetail` represents the all details related to the code build event
58#[non_exhaustive]
59#[derive(Debug, Default, Clone, PartialEq, Deserialize, Serialize)]
60#[serde(rename_all = "camelCase")]
61pub struct CodeBuildEventDetail {
62    #[serde(rename = "build-status")]
63    pub build_status: Option<CodeBuildPhaseStatus>,
64    #[serde(default)]
65    #[serde(rename = "project-name")]
66    pub project_name: Option<String>,
67    #[serde(default)]
68    #[serde(rename = "build-id")]
69    pub build_id: Option<String>,
70    #[serde(rename = "additional-information")]
71    pub additional_information: CodeBuildEventAdditionalInformation,
72    #[serde(rename = "current-phase")]
73    pub current_phase: Option<CodeBuildPhaseType>,
74    #[serde(default)]
75    #[serde(rename = "current-phase-context")]
76    pub current_phase_context: Option<String>,
77    #[serde(default)]
78    pub version: Option<String>,
79    #[serde(rename = "completed-phase-status")]
80    pub completed_phase_status: Option<CodeBuildPhaseStatus>,
81    #[serde(rename = "completed-phase")]
82    pub completed_phase: Option<CodeBuildPhaseType>,
83    #[serde(default)]
84    #[serde(rename = "completed-phase-context")]
85    pub completed_phase_context: Option<String>,
86    #[serde(rename = "completed-phase-duration-seconds")]
87    pub completed_phase_duration: Option<SecondDuration>,
88    #[serde(rename = "completed-phase-start")]
89    #[serde(default)]
90    #[serde(with = "codebuild_time::optional_time")]
91    pub completed_phase_start: Option<CodeBuildTime>,
92    #[serde(rename = "completed-phase-end")]
93    #[serde(default)]
94    #[serde(with = "codebuild_time::optional_time")]
95    pub completed_phase_end: Option<CodeBuildTime>,
96    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
97    /// Enabled with Cargo feature `catch-all-fields`.
98    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
99    #[cfg(feature = "catch-all-fields")]
100    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
101    #[serde(flatten)]
102    pub other: serde_json::Map<String, Value>,
103}
104
105/// `CodeBuildEventAdditionalInformation` represents additional information to the code build event
106#[non_exhaustive]
107#[derive(Debug, Default, Clone, PartialEq, Deserialize, Serialize)]
108#[serde(rename_all = "camelCase")]
109pub struct CodeBuildEventAdditionalInformation {
110    pub artifact: CodeBuildArtifact,
111    pub environment: CodeBuildEnvironment,
112    #[serde(rename = "timeout-in-minutes")]
113    pub timeout: MinuteDuration,
114    #[serde(rename = "build-complete")]
115    pub build_complete: bool,
116    #[serde(rename = "build-number")]
117    pub build_number: Option<CodeBuildNumber>,
118    #[serde(default)]
119    pub initiator: Option<String>,
120    #[serde(rename = "build-start-time")]
121    #[serde(with = "codebuild_time::str_time")]
122    pub build_start_time: CodeBuildTime,
123    pub source: CodeBuildSource,
124    #[serde(default)]
125    #[serde(rename = "source-version")]
126    pub source_version: Option<String>,
127    pub logs: CodeBuildLogs,
128    pub phases: Vec<CodeBuildPhase>,
129    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
130    /// Enabled with Cargo feature `catch-all-fields`.
131    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
132    #[cfg(feature = "catch-all-fields")]
133    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
134    #[serde(flatten)]
135    pub other: serde_json::Map<String, Value>,
136}
137
138/// `CodeBuildArtifact` represents the artifact provided to build
139#[non_exhaustive]
140#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
141#[serde(rename_all = "camelCase")]
142pub struct CodeBuildArtifact {
143    #[serde(default)]
144    #[serde(rename = "md5sum")]
145    pub md5_sum: Option<String>,
146    #[serde(default)]
147    #[serde(rename = "sha256sum")]
148    pub sha256_sum: Option<String>,
149    #[serde(default)]
150    pub location: Option<String>,
151    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
152    /// Enabled with Cargo feature `catch-all-fields`.
153    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
154    #[cfg(feature = "catch-all-fields")]
155    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
156    #[serde(flatten)]
157    pub other: serde_json::Map<String, Value>,
158}
159
160/// `CodeBuildEnvironment` represents the environment for a build
161#[non_exhaustive]
162#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
163#[serde(rename_all = "camelCase")]
164pub struct CodeBuildEnvironment {
165    #[serde(default)]
166    pub image: Option<String>,
167    #[serde(rename = "privileged-mode")]
168    pub privileged_mode: bool,
169    #[serde(default)]
170    #[serde(rename = "compute-type")]
171    pub compute_type: Option<String>,
172    #[serde(default)]
173    pub type_: Option<String>,
174    #[serde(rename = "environment-variables")]
175    pub environment_variables: Vec<CodeBuildEnvironmentVariable>,
176    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
177    /// Enabled with Cargo feature `catch-all-fields`.
178    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
179    #[cfg(feature = "catch-all-fields")]
180    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
181    #[serde(flatten)]
182    pub other: serde_json::Map<String, Value>,
183}
184
185/// `CodeBuildEnvironmentVariable` encapsulate environment variables for the code build
186#[non_exhaustive]
187#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
188#[serde(rename_all = "camelCase")]
189pub struct CodeBuildEnvironmentVariable {
190    /// Name is the name of the environment variable.
191    #[serde(default)]
192    pub name: Option<String>,
193    /// Type is PLAINTEXT or PARAMETER_STORE.
194    #[serde(default)]
195    pub type_: Option<String>,
196    /// Value is the value of the environment variable.
197    #[serde(default)]
198    pub value: Option<String>,
199    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
200    /// Enabled with Cargo feature `catch-all-fields`.
201    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
202    #[cfg(feature = "catch-all-fields")]
203    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
204    #[serde(flatten)]
205    pub other: serde_json::Map<String, Value>,
206}
207
208/// `CodeBuildSource` represent the code source will be build
209#[non_exhaustive]
210#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
211#[serde(rename_all = "camelCase")]
212pub struct CodeBuildSource {
213    #[serde(default)]
214    pub location: Option<String>,
215    #[serde(default)]
216    pub type_: Option<String>,
217    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
218    /// Enabled with Cargo feature `catch-all-fields`.
219    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
220    #[cfg(feature = "catch-all-fields")]
221    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
222    #[serde(flatten)]
223    pub other: serde_json::Map<String, Value>,
224}
225
226/// `CodeBuildLogs` gives the log details of a code build
227#[non_exhaustive]
228#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
229#[serde(rename_all = "camelCase")]
230pub struct CodeBuildLogs {
231    #[serde(default)]
232    #[serde(rename = "group-name")]
233    pub group_name: Option<String>,
234    #[serde(default)]
235    #[serde(rename = "stream-name")]
236    pub stream_name: Option<String>,
237    #[serde(default)]
238    #[serde(rename = "deep-link")]
239    pub deep_link: Option<String>,
240    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
241    /// Enabled with Cargo feature `catch-all-fields`.
242    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
243    #[cfg(feature = "catch-all-fields")]
244    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
245    #[serde(flatten)]
246    pub other: serde_json::Map<String, Value>,
247}
248
249/// `CodeBuildPhase` represents the phase of a build and its details
250#[non_exhaustive]
251#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
252#[serde(rename_all = "camelCase")]
253pub struct CodeBuildPhase<T1 = Value>
254where
255    T1: DeserializeOwned,
256    T1: Serialize,
257{
258    #[serde(bound = "")]
259    #[serde(rename = "phase-context")]
260    pub phase_context: Option<Vec<T1>>,
261    #[serde(rename = "start-time")]
262    #[serde(with = "codebuild_time::str_time")]
263    pub start_time: CodeBuildTime,
264    #[serde(rename = "end-time")]
265    #[serde(default)]
266    #[serde(with = "codebuild_time::optional_time")]
267    pub end_time: Option<CodeBuildTime>,
268    #[serde(rename = "duration-in-seconds")]
269    pub duration: Option<SecondDuration>,
270    #[serde(rename = "phase-type")]
271    pub phase_type: CodeBuildPhaseType,
272    #[serde(rename = "phase-status")]
273    pub phase_status: Option<CodeBuildPhaseStatus>,
274    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
275    /// Enabled with Cargo feature `catch-all-fields`.
276    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
277    #[cfg(feature = "catch-all-fields")]
278    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
279    #[serde(flatten)]
280    pub other: serde_json::Map<String, Value>,
281}
282
283pub type CodeBuildTime = DateTime<Utc>;
284
285#[cfg(test)]
286mod test {
287    use super::*;
288
289    #[test]
290    #[cfg(feature = "codebuild")]
291    fn example_codebuild_phase_change() {
292        let data = include_bytes!("../../fixtures/example-codebuild-phase-change.json");
293        let parsed: CodeBuildEvent = serde_json::from_slice(data).unwrap();
294        let output: String = serde_json::to_string(&parsed).unwrap();
295        let reparsed: CodeBuildEvent = serde_json::from_slice(output.as_bytes()).unwrap();
296        assert_eq!(parsed, reparsed);
297    }
298
299    #[test]
300    #[cfg(feature = "codebuild")]
301    fn example_codebuild_state_change() {
302        let data = include_bytes!("../../fixtures/example-codebuild-state-change.json");
303        let parsed: CodeBuildEvent = serde_json::from_slice(data).unwrap();
304        let output: String = serde_json::to_string(&parsed).unwrap();
305        let reparsed: CodeBuildEvent = serde_json::from_slice(output.as_bytes()).unwrap();
306        assert_eq!(parsed, reparsed);
307    }
308}