Skip to content

Commit

Permalink
chore(sns): manage ResourceNotFoundException and add paralelism (#5347
Browse files Browse the repository at this point in the history
)

Co-authored-by: Rubén De la Torre Vico <[email protected]>
  • Loading branch information
prowler-bot and puchy22 authored Oct 9, 2024
1 parent f7ef0a0 commit a4e655b
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions prowler/providers/aws/services/sns/sns_service.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
from json import loads
from typing import Optional

from botocore.exceptions import ClientError
from pydantic import BaseModel

from prowler.lib.logger import logger
from prowler.lib.scan_filters.scan_filters import is_resource_filtered
from prowler.providers.aws.lib.service.service import AWSService


################################ SNS
class SNS(AWSService):
def __init__(self, provider):
# Call AWSService's __init__
super().__init__(__class__.__name__, provider)
self.topics = []
self.__threading_call__(self._list_topics)
self._get_topic_attributes(self.regional_clients)
self._list_tags_for_resource()
self.__threading_call__(self._list_tags_for_resource, self.topics)
self._list_subscriptions_by_topic()

def _list_topics(self, regional_client):
Expand Down Expand Up @@ -61,18 +61,24 @@ def _get_topic_attributes(self, regional_clients):
f"{regional_client.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
)

def _list_tags_for_resource(self):
logger.info("SNS - List Tags...")
def _list_tags_for_resource(self, resource):
logger.info("SNS - Listing Tags...")
try:
for topic in self.topics:
regional_client = self.regional_clients[topic.region]
response = regional_client.list_tags_for_resource(
ResourceArn=topic.arn
)["Tags"]
topic.tags = response
resource.tags = self.regional_clients[
resource.region
].list_tags_for_resource(ResourceArn=resource.arn)["Tags"]
except ClientError as error:
if error.response["Error"]["Code"] == "ResourceNotFoundException":
logger.warning(
f"{resource.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: Resource {resource.arn} not found while listing tags"
)
else:
logger.error(
f"{resource.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
)
except Exception as error:
logger.error(
f"{regional_client.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
f"{resource.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
)

def _list_subscriptions_by_topic(self):
Expand Down

0 comments on commit a4e655b

Please sign in to comment.