From f604ab77f0792147f78c4341b07a693b1a616fa5 Mon Sep 17 00:00:00 2001 From: Prowler Bot Date: Wed, 13 Nov 2024 21:17:20 +0100 Subject: [PATCH] chore(ec2): add name from image information to status_extended (#5758) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Rubén De la Torre Vico --- .../aws/services/ec2/ec2_ami_public/ec2_ami_public.py | 7 ++++--- prowler/providers/aws/services/ec2/ec2_service.py | 2 +- .../aws/services/ec2/ec2_ami_public/ec2_ami_public_test.py | 6 ++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/prowler/providers/aws/services/ec2/ec2_ami_public/ec2_ami_public.py b/prowler/providers/aws/services/ec2/ec2_ami_public/ec2_ami_public.py index 50979265d5a..1758a3ae02f 100644 --- a/prowler/providers/aws/services/ec2/ec2_ami_public/ec2_ami_public.py +++ b/prowler/providers/aws/services/ec2/ec2_ami_public/ec2_ami_public.py @@ -12,11 +12,12 @@ def execute(self): report.resource_arn = image.arn report.resource_tags = image.tags report.status = "PASS" - report.status_extended = f"EC2 AMI {image.id} is not public." + report.status_extended = ( + f"EC2 AMI {image.name if image.name else image.id} is not public." + ) if image.public: report.status = "FAIL" - report.status_extended = f"EC2 AMI {image.id} is currently public." - report.resource_id = image.id + report.status_extended = f"EC2 AMI {image.name if image.name else image.id} is currently public." findings.append(report) diff --git a/prowler/providers/aws/services/ec2/ec2_service.py b/prowler/providers/aws/services/ec2/ec2_service.py index dcf49f6066d..4c695c3110b 100644 --- a/prowler/providers/aws/services/ec2/ec2_service.py +++ b/prowler/providers/aws/services/ec2/ec2_service.py @@ -357,7 +357,7 @@ def _describe_images(self, regional_client): Image( id=image["ImageId"], arn=arn, - name=image.get("Name", None), + name=image.get("Name", ""), public=image.get("Public", False), region=regional_client.region, tags=image.get("Tags"), diff --git a/tests/providers/aws/services/ec2/ec2_ami_public/ec2_ami_public_test.py b/tests/providers/aws/services/ec2/ec2_ami_public/ec2_ami_public_test.py index c775c7cb0f5..593128f506d 100644 --- a/tests/providers/aws/services/ec2/ec2_ami_public/ec2_ami_public_test.py +++ b/tests/providers/aws/services/ec2/ec2_ami_public/ec2_ami_public_test.py @@ -72,7 +72,7 @@ def test_one_private_ami(self): assert len(result) == 1 assert result[0].status == "PASS" - assert result[0].status_extended == f"EC2 AMI {image_id} is not public." + assert result[0].status_extended == "EC2 AMI test-ami is not public." assert result[0].resource_id == image_id assert ( result[0].resource_arn @@ -124,9 +124,7 @@ def test_one_public_ami(self): assert len(result) == 1 assert result[0].status == "FAIL" - assert ( - result[0].status_extended == f"EC2 AMI {image_id} is currently public." - ) + assert result[0].status_extended == "EC2 AMI test-ami is currently public." assert result[0].resource_id == image_id assert ( result[0].resource_arn