Merge branch 'master' into stsroles

This commit is contained in:
Kenneth Toler
2018-09-25 17:11:52 -04:00
63 changed files with 178 additions and 79 deletions

View File

@@ -16,7 +16,7 @@ import pprint
import sys
from libs.sql import *
from libs.aws.sql import *
pp = pprint.PrettyPrinter(indent=5, width=80)

View File

@@ -10,7 +10,7 @@ import pprint
import sys
import time
from libs.sql import *
from libs.aws.sql import *
pp = pprint.PrettyPrinter(indent=5, width=80)

View File

@@ -11,20 +11,25 @@ regions = ['us-east-1', 'us-east-2', 'us-west-1', 'us-west-2', 'ca-central-1', '
session = boto3.Session()
credentials = session.get_credentials()
AWS_ACCESS_KEY_ID = credentials.access_key
topics_list = {}
def list_sns_topics():
def list_sns_topics(should_i_print=True):
title = "SNS Topics"
print(title)
print("-" * len(title))
if should_i_print:
print(title)
print("-" * len(title))
try:
for region in regions:
client = boto3.client('sns', region_name=region)
topics = client.list_topics()
print(region)
print("=" * len(region))
if should_i_print:
print(region)
print("=" * len(region))
if topics['Topics']:
for topic in topics['Topics']:
print(topic)
topics_list[region] = topics['Topics']
if should_i_print:
for topic in topics['Topics']:
print(topic)
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == 'InvalidClientTokenId':
sys.exit("The AWS KEY IS INVALID. Exiting")
@@ -79,6 +84,20 @@ def delete_sns_topic(topic, region):
except KeyboardInterrupt:
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):
try:
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))
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))
#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))
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))
else:
print("Unexpected error: {}" .format(e))
except KeyboardInterrupt:

View File

@@ -5,8 +5,13 @@ def list_all_files(directory):
array = []
for file in list_of_files:
filename_and_ext = os.path.splitext(file)
if (filename_and_ext[1] == ".py") and not (filename_and_ext[0].startswith("__")):
array.append(filename_and_ext[0])
path ="modules"
for (dirpath, dirnames, filenames) in os.walk(path):
if ( not (dirpath == os.path.basename(directory)) and
(os.path.isdir(dirpath))
and not (os.path.basename(dirpath).startswith('__')) ):
for file in filenames:
list_path_name = dirpath.split('/')
if not (file.startswith('.')):
array.append(".".join(list_path_name) + "." + os.path.splitext(file)[0])
return array