fix(aws_regions): Get enabled regions (#3095)

This commit is contained in:
Pepe Fagoaga
2023-12-11 14:09:39 +01:00
committed by GitHub
parent 7b5b14dbd0
commit c9cb9774c6
7 changed files with 51 additions and 14 deletions

View File

@@ -15,6 +15,8 @@ AWS_REGION_EU_WEST_1 = "eu-west-1"
AWS_REGION_EU_WEST_1_AZA = "eu-west-1a"
AWS_REGION_EU_WEST_1_AZB = "eu-west-1b"
AWS_REGION_EU_WEST_2 = "eu-west-2"
AWS_REGION_CN_NORTHWEST_1 = "cn-northwest-1"
AWS_REGION_CN_NORTH_1 = "cn-north-1"
AWS_REGION_EU_SOUTH_2 = "eu-south-2"
AWS_REGION_US_WEST_2 = "us-west-2"
AWS_REGION_US_EAST_2 = "us-east-2"
@@ -51,6 +53,7 @@ def set_mocked_aws_audit_info(
botocore_session=None,
),
original_session: session.Session = None,
enabled_regions: set = None,
):
audit_info = AWS_Audit_Info(
session_config=None,
@@ -77,5 +80,6 @@ def set_mocked_aws_audit_info(
),
audit_config=audit_config,
ignore_unused_services=ignore_unused_services,
enabled_regions=enabled_regions if enabled_regions else set(audited_regions),
)
return audit_info

View File

@@ -280,7 +280,7 @@ class Test_AWS_Provider:
role_name = "test-role"
role_arn = f"arn:aws:iam::{AWS_ACCOUNT_NUMBER}:role/{role_name}"
session_duration_seconds = 900
AWS_REGION_US_EAST_1 = "eu-west-1"
AWS_REGION_US_EAST_1 = AWS_REGION_EU_WEST_1
sts_endpoint_region = AWS_REGION_US_EAST_1
sessionName = "ProwlerAsessmentSession"
@@ -352,6 +352,7 @@ class Test_AWS_Provider:
audit_session=boto3.session.Session(
region_name=AWS_REGION_US_EAST_1,
),
enabled_regions=audited_regions,
)
generate_regional_clients_response = generate_regional_clients(
@@ -367,6 +368,7 @@ class Test_AWS_Provider:
audit_session=boto3.session.Session(
region_name=AWS_REGION_US_EAST_1,
),
enabled_regions=audited_regions,
)
generate_regional_clients_response = generate_regional_clients(
"shield", audit_info
@@ -430,7 +432,7 @@ class Test_AWS_Provider:
"eu-north-1",
"eu-south-1",
"eu-south-2",
"eu-west-1",
AWS_REGION_EU_WEST_1,
"eu-west-2",
"eu-west-3",
"me-central-1",
@@ -446,9 +448,9 @@ class Test_AWS_Provider:
}
},
):
assert get_available_aws_service_regions("ec2", audit_info) == [
assert get_available_aws_service_regions("ec2", audit_info) == {
AWS_REGION_US_EAST_1
]
}
def test_get_available_aws_service_regions_with_all_regions_audited(self):
audit_info = set_mocked_aws_audit_info()
@@ -467,7 +469,7 @@ class Test_AWS_Provider:
"eu-north-1",
"eu-south-1",
"eu-south-2",
"eu-west-1",
AWS_REGION_EU_WEST_1,
"eu-west-2",
"eu-west-3",
"me-central-1",