|
| 1 | +use chrono::{DateTime, Utc}; |
1 | 2 | use serde::{Deserialize, Serialize};
|
2 | 3 | use serde_json::Value;
|
3 | 4 |
|
@@ -26,23 +27,89 @@ pub struct AWSAPICall<I = Value, O = Value> {
|
26 | 27 |
|
27 | 28 | #[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
|
28 | 29 | #[serde(rename_all = "camelCase")]
|
29 |
| -pub struct UserIdentity { |
| 30 | +pub struct SessionIssuer { |
30 | 31 | pub r#type: String,
|
| 32 | + pub user_name: Option<String>, |
31 | 33 | pub principal_id: String,
|
32 | 34 | pub arn: String,
|
33 | 35 | pub account_id: String,
|
34 |
| - pub session_context: Option<SessionContext>, |
35 | 36 | }
|
36 | 37 |
|
37 | 38 | #[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
|
38 | 39 | #[serde(rename_all = "camelCase")]
|
39 |
| -pub struct SessionContext { |
40 |
| - pub attributes: Attributes, |
| 40 | +pub struct WebIdFederationData { |
| 41 | + pub federated_provider: Option<String>, |
| 42 | + pub attributes: Option<String>, |
41 | 43 | }
|
42 | 44 |
|
43 | 45 | #[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
|
44 | 46 | #[serde(rename_all = "camelCase")]
|
45 | 47 | pub struct Attributes {
|
46 | 48 | pub mfa_authenticated: String,
|
47 |
| - pub creation_date: String, |
| 49 | + pub creation_date: DateTime<Utc>, |
| 50 | +} |
| 51 | + |
| 52 | +#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] |
| 53 | +#[serde(rename_all = "camelCase")] |
| 54 | +pub struct SessionContext { |
| 55 | + pub session_issuer: Option<SessionIssuer>, |
| 56 | + pub web_id_federation_data: Option<WebIdFederationData>, |
| 57 | + pub attributes: Attributes, |
| 58 | + pub source_identity: Option<String>, |
| 59 | + pub ec2_role_delivery: Option<String>, |
| 60 | +} |
| 61 | + |
| 62 | +#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] |
| 63 | +#[serde(rename_all = "camelCase")] |
| 64 | +pub struct OnBehalfOf { |
| 65 | + pub user_id: String, |
| 66 | + pub identity_store_arn: String, |
| 67 | +} |
| 68 | + |
| 69 | +// https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-event-reference-user-identity.html |
| 70 | +#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)] |
| 71 | +#[serde(rename_all = "camelCase")] |
| 72 | +pub struct UserIdentity { |
| 73 | + pub r#type: String, |
| 74 | + pub account_id: Option<String>, |
| 75 | + pub arn: Option<String>, |
| 76 | + pub credential_id: Option<String>, |
| 77 | + pub invoked_by: Option<String>, |
| 78 | + pub principal_id: Option<String>, |
| 79 | + pub session_context: Option<SessionContext>, |
| 80 | + pub user_name: Option<String>, |
| 81 | + pub on_behalf_of: Option<OnBehalfOf>, |
| 82 | +} |
| 83 | + |
| 84 | +#[cfg(test)] |
| 85 | +mod tests { |
| 86 | + use super::AWSAPICall; |
| 87 | + |
| 88 | + #[test] |
| 89 | + #[cfg(feature = "cloudwatch_events")] |
| 90 | + fn example_cloudwatch_cloudtrail_unknown_assumed_role() { |
| 91 | + let data = include_bytes!("../../fixtures/example-cloudwatch-cloudtrail-assumed-role.json"); |
| 92 | + let parsed: AWSAPICall = serde_json::from_slice(data).unwrap(); |
| 93 | + let output: String = serde_json::to_string(&parsed).unwrap(); |
| 94 | + let reparsed: AWSAPICall = serde_json::from_slice(&output.as_bytes()).unwrap(); |
| 95 | + assert_eq!(parsed, reparsed); |
| 96 | + } |
| 97 | + #[test] |
| 98 | + #[cfg(feature = "cloudwatch_events")] |
| 99 | + fn example_cloudwatch_cloudtrail_unknown_federate() { |
| 100 | + let data = include_bytes!("../../fixtures/example-cloudwatch-cloudtrail-unknown-federate.json"); |
| 101 | + let parsed: AWSAPICall = serde_json::from_slice(data).unwrap(); |
| 102 | + let output: String = serde_json::to_string(&parsed).unwrap(); |
| 103 | + let reparsed: AWSAPICall = serde_json::from_slice(&output.as_bytes()).unwrap(); |
| 104 | + assert_eq!(parsed, reparsed); |
| 105 | + } |
| 106 | + #[test] |
| 107 | + #[cfg(feature = "cloudwatch_events")] |
| 108 | + fn example_cloudwatch_cloudtrail_assumed_role() { |
| 109 | + let data = include_bytes!("../../fixtures/example-cloudwatch-cloudtrail-unknown-user-auth.json"); |
| 110 | + let parsed: AWSAPICall = serde_json::from_slice(data).unwrap(); |
| 111 | + let output: String = serde_json::to_string(&parsed).unwrap(); |
| 112 | + let reparsed: AWSAPICall = serde_json::from_slice(&output.as_bytes()).unwrap(); |
| 113 | + assert_eq!(parsed, reparsed); |
| 114 | + } |
48 | 115 | }
|
0 commit comments