mirror of
https://github.com/prowler-cloud/prowler.git
synced 2025-12-19 05:17:47 +00:00
chore(mongodbatlas): store location as lowercase (#9554)
Co-authored-by: Andoni Alonso <14891798+andoniaf@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
251fc6d4e3
commit
d4b90abd10
@@ -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)
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user