@@ -89,6 +89,8 @@ class AWSConstants:
8989 "us-gov-west-1" ,
9090 ]
9191
92+ _services : List [str ] = ["ec2" , "cloudtrail" , "s3" ]
93+
9294
9395class S3AccessWriter (Writer ):
9496 def __init__ (self , output , headers ):
@@ -121,6 +123,7 @@ def aws_arn(
121123 account_id = self .aws_account_id ()
122124
123125 # TODO: There are a WHOLE bunch more rules here to take care of
126+ # Also figure out how to handle if resource-type is specificed
124127 if resource_id is None :
125128 if service == "iam" :
126129 resource_id = self .generator .random_element (elements = ["root" , f"user/{ self .generator .user_name ()} " ])
@@ -306,7 +309,7 @@ def http_status(self) -> str:
306309 return str (self ._http_status_code ())
307310
308311 def error_code (self ) -> str :
309- return self .generator .random_element (elements = ("NoSuchBucket" , "NoSuchLifecycleConfiguration" "-" ))
312+ return self .generator .random_element (elements = ("NoSuchBucket" , "NoSuchLifecycleConfiguration" , "-" ))
310313
311314 def bytes_sent (self , total_object_size : Optional [int ] = None ) -> str :
312315 return self .generator .random_element (
@@ -408,3 +411,32 @@ def _http_status_code(self, response_type: Optional[str] = None) -> int:
408411
409412# then add new provider to faker instance
410413# fake.add_provider(S3AccessLogs)
414+
415+
416+ class CloudTrailLogs (AWSProvider ):
417+ def event_version (self ) -> str :
418+ return "1.0"
419+
420+ def event_time (self ) -> str :
421+ return self .generator .iso8601 ()
422+
423+ def event_source (self ) -> str :
424+ return self .generator .random_element (AWSConstants ._services ) + ".amazonaws.com"
425+
426+ def user_id_with_iam_user (self ) -> str :
427+ """
428+ "userIdentity": {
429+ "type": "IAMUser",
430+ "principalId": "AIDAJ45Q7YFFAREXAMPLE",
431+ "arn": "arn:aws:iam::123456789012:user/Alice",
432+ "accountId": "123456789012",
433+ "accessKeyId": "",
434+ "userName": "Alice"
435+ }
436+ """
437+ return {
438+ "type" : "IAMUser" ,
439+ "principalId" : "AIDAJ45Q7YFFAREXAMPLE" ,
440+ "arn" : self .aws_arn (service = "iam" , resource_type = "user" ),
441+ "accountId" : self .aws_account_id (),
442+ }
0 commit comments