Cloudtrail get_trail_status() also accept ARN in the Name parameter (#4544) (#4547)

This commit is contained in:
Kevin Park 2021-11-09 14:50:56 -05:00 committed by GitHub
parent 0bad68f9f0
commit 0e6922a4a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View File

@ -215,11 +215,19 @@ class CloudTrailBackend(BaseBackend):
def get_trail_status(self, name): def get_trail_status(self, name):
if len(name) < 3: if len(name) < 3:
raise TrailNameTooShort(actual_length=len(name)) raise TrailNameTooShort(actual_length=len(name))
if name not in self.trails: trail_name = next(
(
trail.trail_name
for trail in self.trails.values()
if trail.trail_name == name or trail.arn == name
),
None,
)
if not trail_name:
# This particular method returns the ARN as part of the error message # This particular method returns the ARN as part of the error message
arn = f"arn:aws:cloudtrail:{self.region_name}:{ACCOUNT_ID}:trail/{name}" arn = f"arn:aws:cloudtrail:{self.region_name}:{ACCOUNT_ID}:trail/{name}"
raise TrailNotFoundException(name=arn) raise TrailNotFoundException(name=arn)
trail = self.trails[name] trail = self.trails[trail_name]
return trail.status return trail.status
def describe_trails(self, include_shadow_trails): def describe_trails(self, include_shadow_trails):

View File

@ -251,6 +251,22 @@ def test_get_trail_status_inactive():
status.shouldnt.have.key("StartLoggingTime") status.shouldnt.have.key("StartLoggingTime")
@mock_cloudtrail
@mock_s3
def test_get_trail_status_arn_inactive():
client = boto3.client("cloudtrail", region_name="us-east-1")
_, resp, _ = create_trail_simple()
status = client.get_trail_status(Name=resp["TrailARN"])
status.should.have.key("IsLogging").equal(False)
status.should.have.key("LatestDeliveryAttemptTime").equal("")
status.should.have.key("LatestNotificationAttemptTime").equal("")
status.should.have.key("LatestNotificationAttemptSucceeded").equal("")
status.should.have.key("LatestDeliveryAttemptSucceeded").equal("")
status.should.have.key("TimeLoggingStarted").equal("")
status.should.have.key("TimeLoggingStopped").equal("")
status.shouldnt.have.key("StartLoggingTime")
@mock_cloudtrail @mock_cloudtrail
@mock_s3 @mock_s3
def test_get_trail_status_after_starting(): def test_get_trail_status_after_starting():