diff --git a/prowler/providers/aws/services/resourceexplorer2/resourceexplorer2_service.py b/prowler/providers/aws/services/resourceexplorer2/resourceexplorer2_service.py index 9e14379f..37ab1cfa 100644 --- a/prowler/providers/aws/services/resourceexplorer2/resourceexplorer2_service.py +++ b/prowler/providers/aws/services/resourceexplorer2/resourceexplorer2_service.py @@ -14,7 +14,13 @@ class ResourceExplorer2: self.session = audit_info.audit_session self.audit_resources = audit_info.audit_resources self.regional_clients = generate_regional_clients(self.service, audit_info) - self.region = audit_info.profile_region + # If the region is not set in the audit profile, + # we pick the first region from the regional clients list + self.region = ( + audit_info.profile_region + if audit_info.profile_region + else list(self.regional_clients.keys())[0] + ) self.indexes = [] self.__threading_call__(self.__list_indexes__) diff --git a/tests/providers/aws/services/resourceexplorer2/resourceexplorer2_indexes_found/resourceexplorer2_indexes_found_test.py b/tests/providers/aws/services/resourceexplorer2/resourceexplorer2_indexes_found/resourceexplorer2_indexes_found_test.py index 39a885c0..5f19f09a 100644 --- a/tests/providers/aws/services/resourceexplorer2/resourceexplorer2_indexes_found/resourceexplorer2_indexes_found_test.py +++ b/tests/providers/aws/services/resourceexplorer2/resourceexplorer2_indexes_found/resourceexplorer2_indexes_found_test.py @@ -1,7 +1,5 @@ from unittest import mock -from unittest.mock import patch -import botocore from boto3 import session from prowler.providers.aws.lib.audit_info.models import AWS_Audit_Info @@ -15,25 +13,6 @@ INDEX_ARN = "arn:aws:resource-explorer-2:ap-south-1:123456789012:index/123456-28 INDEX_REGION = "us-east-1" -# Mocking Backup Calls -make_api_call = botocore.client.BaseClient._make_api_call - - -def mock_make_api_call(self, operation_name, kwarg): - """ - Mock every AWS API call - """ - if operation_name == "ListIndexes": - return { - "Indexes": [ - {"Arn": INDEX_ARN, "Region": INDEX_REGION, "Type": "LOCAL"}, - ], - "NextToken": "string", - } - return make_api_call(self, operation_name, kwarg) - - -@patch("botocore.client.BaseClient._make_api_call", new=mock_make_api_call) class Test_resourceexplorer2_indexes_found: def set_mocked_audit_info(self): audit_info = AWS_Audit_Info( @@ -48,10 +27,10 @@ class Test_resourceexplorer2_indexes_found: audited_partition="aws", audited_identity_arn=None, profile=None, - profile_region="us-east-1", + profile_region=None, credentials=None, assumed_role_info=None, - audited_regions="us-east-1", + audited_regions=[AWS_REGION], organizations_metadata=None, audit_resources=None, )