bp-check/services/sns.py

47 lines
1.4 KiB
Python
Raw Normal View History

2024-08-12 10:27:53 +00:00
from models import RuleCheckResult
2024-08-05 02:30:34 +00:00
import boto3
2024-08-12 02:17:57 +00:00
client = boto3.client("sns")
2024-08-05 02:30:34 +00:00
def sns_encrypted_kms():
2024-08-12 02:17:57 +00:00
compliant_resources = []
non_compliant_resources = []
topics = client.list_topics()["Topics"]
for topic in topics:
topic = client.get_topic_attributes(TopicArn=topic["TopicArn"])["Attributes"]
if "KmsMasterKeyId" in topic:
compliant_resources.append(topic["TopicArn"])
else:
non_compliant_resources.append(topic["TopicArn"])
2024-08-05 02:30:34 +00:00
return RuleCheckResult(
2024-08-12 02:17:57 +00:00
passed=not non_compliant_resources,
compliant_resources=compliant_resources,
non_compliant_resources=non_compliant_resources,
2024-08-05 02:30:34 +00:00
)
def sns_topic_message_delivery_notification_enabled():
2024-08-12 02:17:57 +00:00
compliant_resources = []
non_compliant_resources = []
topics = client.list_topics()["Topics"]
for topic in topics:
topic = client.get_topic_attributes(TopicArn=topic["TopicArn"])["Attributes"]
for key in topic.keys():
if key.endswith("FeedbackRoleArn") == True:
compliant_resources.append(topic["TopicArn"])
break
else:
non_compliant_resources.append(topic["TopicArn"])
2024-08-05 02:30:34 +00:00
return RuleCheckResult(
2024-08-12 02:17:57 +00:00
passed=not non_compliant_resources,
compliant_resources=compliant_resources,
non_compliant_resources=non_compliant_resources,
2024-08-05 02:30:34 +00:00
)