Skip to main content

aws_lambda_events/event/codedeploy/
mod.rs

1#[cfg(feature = "builders")]
2use bon::Builder;
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5#[cfg(feature = "catch-all-fields")]
6use serde_json::Value;
7
8pub type CodeDeployDeploymentState = String;
9
10/// `CodeDeployEvent` is documented at:
11/// <https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/EventTypes.html#acd_event_types>
12#[non_exhaustive]
13#[cfg_attr(feature = "builders", derive(Builder))]
14#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
15#[serde(rename_all = "camelCase")]
16pub struct CodeDeployEvent {
17    /// AccountID is the id of the AWS account from which the event originated.
18    #[serde(default)]
19    #[serde(rename = "account")]
20    pub account_id: Option<String>,
21    /// Region is the AWS region from which the event originated.
22    #[serde(default)]
23    pub region: Option<String>,
24    /// DetailType informs the schema of the Detail field. For deployment state-change
25    /// events, the value should be equal to CodeDeployDeploymentEventDetailType.
26    /// For instance state-change events, the value should be equal to
27    /// CodeDeployInstanceEventDetailType.
28    #[serde(default)]
29    #[serde(rename = "detail-type")]
30    pub detail_type: Option<String>,
31    /// Source should be equal to CodeDeployEventSource.
32    #[serde(default)]
33    pub source: Option<String>,
34    /// Version is the version of the event's schema.
35    #[serde(default)]
36    pub version: Option<String>,
37    /// Time is the event's timestamp.
38    pub time: DateTime<Utc>,
39    /// ID is the GUID of this event.
40    #[serde(default)]
41    pub id: Option<String>,
42    /// Resources is a list of ARNs of CodeDeploy applications and deployment
43    /// groups that this event pertains to.
44    pub resources: Vec<String>,
45    /// Detail contains information specific to a deployment event.
46    pub detail: CodeDeployEventDetail,
47    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
48    /// Enabled with Cargo feature `catch-all-fields`.
49    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
50    #[cfg(feature = "catch-all-fields")]
51    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
52    #[serde(flatten)]
53    #[cfg_attr(feature = "builders", builder(default))]
54    pub other: serde_json::Map<String, Value>,
55}
56
57#[non_exhaustive]
58#[cfg_attr(feature = "builders", derive(Builder))]
59#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
60#[serde(rename_all = "camelCase")]
61pub struct CodeDeployEventDetail {
62    /// InstanceGroupID is the ID of the instance group.
63    #[serde(default)]
64    pub instance_group_id: Option<String>,
65    /// InstanceID is the id of the instance. This field is non-empty only if
66    /// the DetailType of the complete event is CodeDeployInstanceEventDetailType.
67    pub instance_id: Option<String>,
68    /// Region is the AWS region that the event originated from.
69    #[serde(default)]
70    pub region: Option<String>,
71    /// Application is the name of the CodeDeploy application.
72    #[serde(default)]
73    pub application: Option<String>,
74    /// DeploymentID is the id of the deployment.
75    #[serde(default)]
76    pub deployment_id: Option<String>,
77    /// State is the new state of the deployment.
78    pub state: CodeDeployDeploymentState,
79    /// DeploymentGroup is the name of the deployment group.
80    #[serde(default)]
81    pub deployment_group: Option<String>,
82    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
83    /// Enabled with Cargo feature `catch-all-fields`.
84    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
85    #[cfg(feature = "catch-all-fields")]
86    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
87    #[serde(flatten)]
88    #[cfg_attr(feature = "builders", builder(default))]
89    pub other: serde_json::Map<String, Value>,
90}
91
92#[non_exhaustive]
93#[cfg_attr(feature = "builders", derive(Builder))]
94#[derive(Debug, Default, Clone, Deserialize, Serialize, Eq, PartialEq)]
95#[serde(rename_all = "PascalCase")]
96pub struct CodeDeployLifecycleEvent {
97    pub deployment_id: String,
98    pub lifecycle_event_hook_execution_id: String,
99    /// Catchall to catch any additional fields that were present but not explicitly defined by this struct.
100    /// Enabled with Cargo feature `catch-all-fields`.
101    /// If `catch-all-fields` is disabled, any additional fields that are present will be ignored.
102    #[cfg(feature = "catch-all-fields")]
103    #[cfg_attr(docsrs, doc(cfg(feature = "catch-all-fields")))]
104    #[serde(flatten)]
105    #[cfg_attr(feature = "builders", builder(default))]
106    pub other: serde_json::Map<String, Value>,
107}
108
109#[cfg(test)]
110mod test {
111    use super::*;
112
113    #[test]
114    #[cfg(feature = "codedeploy")]
115    fn example_codedeploy_lifecycle_event() {
116        let data = include_bytes!("../../fixtures/example-codedeploy-lifecycle-event.json");
117        let parsed: CodeDeployLifecycleEvent = serde_json::from_slice(data).unwrap();
118
119        assert_eq!(parsed.deployment_id, "d-deploymentId".to_string());
120        assert_eq!(parsed.lifecycle_event_hook_execution_id, "eyJlbmNyeXB0ZWREYXRhIjoiY3VHU2NjdkJXUTJQUENVd2dkYUNGRVg0dWlpME9UWVdHTVhZcDRXVW5LYUVKc21EaUFPMkNLNXMwMWFrNDlYVStlbXdRb29xS3NJTUNVQ3RYRGFZSXc1VTFwUllvMDhmMzdlbDZFeDVVdjZrNFc0eU5waGh6YTRvdkNWcmVveVR6OWdERlM2SmlIYW1TZz09IiwiaXZQYXJhbWV0ZXJTcGVjIjoiTm1ZNFR6RzZxQVhHamhhLyIsIm1hdGVyaWFsU2V0U2VyaWFsIjoxfQ==".to_string());
121
122        let output: String = serde_json::to_string(&parsed).unwrap();
123        let reparsed: CodeDeployLifecycleEvent = serde_json::from_slice(output.as_bytes()).unwrap();
124        assert_eq!(parsed, reparsed);
125    }
126
127    #[test]
128    #[cfg(feature = "codedeploy")]
129    fn example_codedeploy_deployment_event() {
130        let data = include_bytes!("../../fixtures/example-codedeploy-deployment-event.json");
131        let parsed: CodeDeployEvent = serde_json::from_slice(data).unwrap();
132        let output: String = serde_json::to_string(&parsed).unwrap();
133        let reparsed: CodeDeployEvent = serde_json::from_slice(output.as_bytes()).unwrap();
134        assert_eq!(parsed, reparsed);
135    }
136
137    #[test]
138    #[cfg(feature = "codedeploy")]
139    fn example_codedeploy_instance_event() {
140        let data = include_bytes!("../../fixtures/example-codedeploy-instance-event.json");
141        let parsed: CodeDeployEvent = serde_json::from_slice(data).unwrap();
142        let output: String = serde_json::to_string(&parsed).unwrap();
143        let reparsed: CodeDeployEvent = serde_json::from_slice(output.as_bytes()).unwrap();
144        assert_eq!(parsed, reparsed);
145    }
146}