From d4b90abd1013db1bfd72743750e25b2a06488fb9 Mon Sep 17 00:00:00 2001 From: Daniel Barranquero <74871504+danibarranqueroo@users.noreply.github.com> Date: Tue, 16 Dec 2025 10:40:49 +0100 Subject: [PATCH] chore(mongodbatlas): store location as lowercase (#9554) Co-authored-by: Andoni Alonso <14891798+andoniaf@users.noreply.github.com> --- prowler/CHANGELOG.md | 1 + .../services/clusters/clusters_service.py | 26 ++++++++++++++++--- .../mutelist/mongodbatlas_mutelist_test.py | 4 +-- .../clusters/clusters_service_test.py | 4 +-- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/prowler/CHANGELOG.md b/prowler/CHANGELOG.md index f8c1e81894..352651e1ba 100644 --- a/prowler/CHANGELOG.md +++ b/prowler/CHANGELOG.md @@ -21,6 +21,7 @@ All notable changes to the **Prowler SDK** are documented in this file. ### Fixed - Fix typo `trustboundaries` category to `trust-boundaries` [(#9536)](https://github.com/prowler-cloud/prowler/pull/9536) +- Store MongoDB Atlas provider regions as lowercase [(#9554)](https://github.com/prowler-cloud/prowler/pull/9554) --- diff --git a/prowler/providers/mongodbatlas/services/clusters/clusters_service.py b/prowler/providers/mongodbatlas/services/clusters/clusters_service.py index 6d46014121..d5e9e2c18a 100644 --- a/prowler/providers/mongodbatlas/services/clusters/clusters_service.py +++ b/prowler/providers/mongodbatlas/services/clusters/clusters_service.py @@ -17,6 +17,28 @@ class Clusters(MongoDBAtlasService): super().__init__(__class__.__name__, provider) self.clusters = self._list_clusters() + def _extract_location(self, cluster_data: dict) -> str: + """ + Extract location from cluster data and convert to lowercase + + Args: + cluster_data: Cluster data from API + + Returns: + str: Location in lowercase, empty string if not found + """ + try: + replication_specs = cluster_data.get("replicationSpecs", []) + if replication_specs and len(replication_specs) > 0: + region_configs = replication_specs[0].get("regionConfigs", []) + if region_configs and len(region_configs) > 0: + region_name = region_configs[0].get("regionName", "") + if region_name: + return region_name.lower() + except (KeyError, IndexError, AttributeError): + pass + return "" + def _list_clusters(self): """ List all MongoDB Atlas clusters across all projects @@ -89,9 +111,7 @@ class Clusters(MongoDBAtlasService): "connectionStrings", {} ), tags=cluster_data.get("tags", []), - location=cluster_data.get("replicationSpecs", {})[0] - .get("regionConfigs", {})[0] - .get("regionName", ""), + location=self._extract_location(cluster_data), ) # Use a unique key combining project_id and cluster_name diff --git a/tests/providers/mongodbatlas/lib/mutelist/mongodbatlas_mutelist_test.py b/tests/providers/mongodbatlas/lib/mutelist/mongodbatlas_mutelist_test.py index 182184d666..d3a06fe530 100644 --- a/tests/providers/mongodbatlas/lib/mutelist/mongodbatlas_mutelist_test.py +++ b/tests/providers/mongodbatlas/lib/mutelist/mongodbatlas_mutelist_test.py @@ -157,7 +157,7 @@ class TestMongoDBAtlasMutelist: "*": { "Checks": { "clusters_backup_enabled": { - "Regions": ["WESTERN_EUROPE"], + "Regions": ["western_europe"], "Resources": ["*"], } } @@ -172,7 +172,7 @@ class TestMongoDBAtlasMutelist: finding.check_metadata.CheckID = "clusters_backup_enabled" finding.status = "FAIL" finding.resource_name = "any-cluster" - finding.location = "WESTERN_EUROPE" + finding.location = "western_europe" finding.resource_tags = [] assert mutelist.is_finding_muted(finding, "any-org-id") diff --git a/tests/providers/mongodbatlas/services/clusters/clusters_service_test.py b/tests/providers/mongodbatlas/services/clusters/clusters_service_test.py index 10e013bcc6..cb58f2afa9 100644 --- a/tests/providers/mongodbatlas/services/clusters/clusters_service_test.py +++ b/tests/providers/mongodbatlas/services/clusters/clusters_service_test.py @@ -64,7 +64,7 @@ def mock_clusters_list_clusters(_): pit_enabled=True, connection_strings={"standard": "mongodb://cluster.mongodb.net"}, tags=[{"key": "environment", "value": "test"}], - location="US_EAST_1", + location="us_east_1", ) } @@ -109,4 +109,4 @@ class Test_Clusters_Service: assert cluster.connection_strings["standard"] == "mongodb://cluster.mongodb.net" assert cluster.tags[0]["key"] == "environment" assert cluster.tags[0]["value"] == "test" - assert cluster.location == "US_EAST_1" + assert cluster.location == "us_east_1"