Fixes issue #50
This commit is contained in:
25
libs/sns.py
25
libs/sns.py
@@ -11,18 +11,23 @@ regions = ['us-east-1', 'us-east-2', 'us-west-1', 'us-west-2', 'ca-central-1', '
|
|||||||
session = boto3.Session()
|
session = boto3.Session()
|
||||||
credentials = session.get_credentials()
|
credentials = session.get_credentials()
|
||||||
AWS_ACCESS_KEY_ID = credentials.access_key
|
AWS_ACCESS_KEY_ID = credentials.access_key
|
||||||
|
topics_list = {}
|
||||||
|
|
||||||
def list_sns_topics():
|
def list_sns_topics(should_i_print=True):
|
||||||
title = "SNS Topics"
|
title = "SNS Topics"
|
||||||
|
if should_i_print:
|
||||||
print(title)
|
print(title)
|
||||||
print("-" * len(title))
|
print("-" * len(title))
|
||||||
try:
|
try:
|
||||||
for region in regions:
|
for region in regions:
|
||||||
client = boto3.client('sns', region_name=region)
|
client = boto3.client('sns', region_name=region)
|
||||||
topics = client.list_topics()
|
topics = client.list_topics()
|
||||||
|
if should_i_print:
|
||||||
print(region)
|
print(region)
|
||||||
print("=" * len(region))
|
print("=" * len(region))
|
||||||
if topics['Topics']:
|
if topics['Topics']:
|
||||||
|
topics_list[region] = topics['Topics']
|
||||||
|
if should_i_print:
|
||||||
for topic in topics['Topics']:
|
for topic in topics['Topics']:
|
||||||
print(topic)
|
print(topic)
|
||||||
except botocore.exceptions.ClientError as e:
|
except botocore.exceptions.ClientError as e:
|
||||||
@@ -79,6 +84,20 @@ def delete_sns_topic(topic, region):
|
|||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("CTRL-C received, exiting...")
|
print("CTRL-C received, exiting...")
|
||||||
|
|
||||||
|
def list_all_sns_subscribers():
|
||||||
|
print("Scanning regions....")
|
||||||
|
list_sns_topics(False)
|
||||||
|
for region,topics in topics_list.items():
|
||||||
|
for topic in topics:
|
||||||
|
region_title = "Region: {}".format(region)
|
||||||
|
print(region_title)
|
||||||
|
print("=" * len(region_title))
|
||||||
|
list_sns_subscribers(topic['TopicArn'],region)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def delete_sns_subscriber(endpoint, region):
|
def delete_sns_subscriber(endpoint, region):
|
||||||
try:
|
try:
|
||||||
client = boto3.client('sns', region_name=region)
|
client = boto3.client('sns', region_name=region)
|
||||||
@@ -90,8 +109,8 @@ def delete_sns_subscriber(endpoint, region):
|
|||||||
print('{} : Is NOT a root key' .format(AWS_ACCESS_KEY_ID))
|
print('{} : Is NOT a root key' .format(AWS_ACCESS_KEY_ID))
|
||||||
elif e.response['Error']['Code'] == 'SubscriptionRequiredException':
|
elif e.response['Error']['Code'] == 'SubscriptionRequiredException':
|
||||||
print('{} : Has permissions but isnt signed up for service - usually means you have a root account' .format(AWS_ACCESS_KEY_ID))
|
print('{} : Has permissions but isnt signed up for service - usually means you have a root account' .format(AWS_ACCESS_KEY_ID))
|
||||||
#elif e.response['Error']['Code'] == 'InvalidParameter':
|
elif e.response['Error']['Code'] == 'InvalidParameter':
|
||||||
# print('The region you provided ({}) is invalid for the Subscriber endpoint. Are you sure this subscriber exists in this region?'.format(region))
|
print('The region you provided ({}) is invalid for the Subscriber endpoint. Are you sure this subscriber exists in this region?'.format(region))
|
||||||
else:
|
else:
|
||||||
print("Unexpected error: {}" .format(e))
|
print("Unexpected error: {}" .format(e))
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
|||||||
@@ -22,6 +22,13 @@ def module_sns_list_subscribers(*args):
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
print("Please provide a topic arn *AND* region, ex: -a arn:aws:sns:us-east-1:123456789123:sometopic,us-east-1")
|
print("Please provide a topic arn *AND* region, ex: -a arn:aws:sns:us-east-1:123456789123:sometopic,us-east-1")
|
||||||
|
|
||||||
|
def module_sns_list_all_subscribers():
|
||||||
|
'''
|
||||||
|
Rather than listing a single topics subscribers, we'll list all topics and all subscribersself.
|
||||||
|
python3 weirdAAL.py -m sns_list_all_subscribers
|
||||||
|
'''
|
||||||
|
list_all_sns_subscribers()
|
||||||
|
|
||||||
def module_sns_delete_topic(*args):
|
def module_sns_delete_topic(*args):
|
||||||
'''
|
'''
|
||||||
SNS delete a topic. Takes two arguments - the topic arn and the region.
|
SNS delete a topic. Takes two arguments - the topic arn and the region.
|
||||||
|
|||||||
0
target.txt
Normal file
0
target.txt
Normal file
Reference in New Issue
Block a user