fix(dax): Call list_tags using the cluster ARN (#2167)

This commit is contained in:
Pepe Fagoaga
2023-04-04 09:30:36 +02:00
committed by GitHub
parent cde9519a76
commit 8c6606ad95
2 changed files with 25 additions and 11 deletions

View File

@@ -1,6 +1,7 @@
import threading import threading
from typing import Optional from typing import Optional
from botocore.client import ClientError
from pydantic import BaseModel from pydantic import BaseModel
from prowler.lib.logger import logger from prowler.lib.logger import logger
@@ -168,15 +169,24 @@ class DAX:
def __list_tags_for_resource__(self): def __list_tags_for_resource__(self):
logger.info("DAX - List Tags...") logger.info("DAX - List Tags...")
try: for cluster in self.clusters:
for cluster in self.clusters: try:
regional_client = self.regional_clients[cluster.region] regional_client = self.regional_clients[cluster.region]
response = regional_client.list_tags(ResourceName=cluster.name)["Tags"] # In the DAX service to call list_tags we need to pass the cluster ARN as the resource name
response = regional_client.list_tags(ResourceName=cluster.arn)["Tags"]
cluster.tags = response cluster.tags = response
except Exception as error:
logger.error( except ClientError as error:
f"{regional_client.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}" if error.response["Error"]["Code"] != "InvalidARNFault":
) logger.warning(
f"{regional_client.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
)
continue
except Exception as error:
logger.error(
f"{regional_client.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
)
class Table(BaseModel): class Table(BaseModel):

View File

@@ -136,7 +136,7 @@ class Test_DynamoDB_Service:
{"Key": "test", "Value": "test"}, {"Key": "test", "Value": "test"},
] ]
# Test DynamoDB Describe Table # Test DynamoDB Describe Continuous Backups
@mock_dynamodb @mock_dynamodb
def test__describe_continuous_backups__(self): def test__describe_continuous_backups__(self):
# Generate DynamoDB Client # Generate DynamoDB Client
@@ -167,7 +167,7 @@ class Test_DynamoDB_Service:
assert dynamo.tables[0].pitr assert dynamo.tables[0].pitr
assert dynamo.tables[0].region == AWS_REGION assert dynamo.tables[0].region == AWS_REGION
# Test DAX List Tables # Test DAX Describe Clusters
@mock_dax @mock_dax
def test__describe_clusters__(self): def test__describe_clusters__(self):
# Generate DAX Client # Generate DAX Client
@@ -198,13 +198,17 @@ class Test_DynamoDB_Service:
audit_info = self.set_mocked_audit_info() audit_info = self.set_mocked_audit_info()
dax = DAX(audit_info) dax = DAX(audit_info)
assert len(dax.clusters) == 2 assert len(dax.clusters) == 2
assert dax.clusters[0].name == "daxcluster1" assert dax.clusters[0].name == "daxcluster1"
assert dax.clusters[1].name == "daxcluster2"
assert dax.clusters[0].region == AWS_REGION assert dax.clusters[0].region == AWS_REGION
assert dax.clusters[1].region == AWS_REGION assert dax.clusters[0].encryption
assert dax.clusters[0].tags == [ assert dax.clusters[0].tags == [
{"Key": "test", "Value": "test"}, {"Key": "test", "Value": "test"},
] ]
assert dax.clusters[1].name == "daxcluster2"
assert dax.clusters[1].region == AWS_REGION
assert dax.clusters[1].encryption
assert dax.clusters[1].tags == [ assert dax.clusters[1].tags == [
{"Key": "test", "Value": "test"}, {"Key": "test", "Value": "test"},
] ]