From 69526ba18c57ae15291034fd6b0be926a4b9f43e Mon Sep 17 00:00:00 2001 From: cktricky Date: Fri, 21 Sep 2018 20:59:32 -0400 Subject: [PATCH] sweeeeet. now i just need the table formatted correctly and we are rockin and rollin --- weirdAAL.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/weirdAAL.py b/weirdAAL.py index efabcfb..b16bbd4 100755 --- a/weirdAAL.py +++ b/weirdAAL.py @@ -13,6 +13,7 @@ from botocore.exceptions import ClientError from modules import * import sys import builtins +import re os.environ['AWS_SHARED_CREDENTIALS_FILE'] = '.env' @@ -24,6 +25,7 @@ for module in all_modules: exec("from %s import *" % module) + parser = argparse.ArgumentParser() parser.add_argument("-m", "--module", help="list the module you would like to run", action="store", type=str, required=False) parser.add_argument("-t", "--target", help="Give your target a name so we can track results", action="store", type=str, required=False) @@ -35,6 +37,7 @@ args = parser.parse_args() # Provides us with a global var "db_name" we can access anywhere builtins.db_name = "weirdAAL.db" + def perform_credential_check(): ''' Check that the AWS keys work before we go any further. It picks the keys up from the local .env file @@ -59,6 +62,48 @@ def method_create(): print("That module does not exist") exit(1) +builtins.aws_module_methods_info = {} +builtins.gcp_module_methods_info = {} + +def get_methods_for_classname(classname): + methods = [] + all_methods = dir(sys.modules[classname]) + for meth in all_methods: + if meth.startswith("module_"): + narg = "{}.__doc__".format(meth) + narg = eval(narg) + nhash = {} + nhash[meth] = narg + methods.append(nhash) + return methods + + +def make_list_of_methods(cloud_service, mod): + meths = get_methods_for_classname(mod) + if cloud_service == 'aws': + new_mod_name = re.sub("modules.aws.", "", mod) + aws_module_methods_info[new_mod_name.upper()] = meths + elif cloud_service == 'gcp': + new_mod_name = re.sub("modules.gcp.", "", mod) + gcp_module_methods_info[new_mod_name.upper()] = meths + + +def make_the_list(): + for m in sys.modules.keys(): + if (m.startswith("modules.aws") + and not (m == "modules.aws")): + make_list_of_methods("aws", m) + elif ((m.startswith("modules.gcp")) + and not (m == "modules.gcp")): + make_list_of_methods("gcp", m) + +def print_the_list(): + print("AWS") + print("---") + for (k) in aws_module_methods_info: + print(k) + print(aws_module_methods_info[k]) + print("....") # Need to figure out if we have keys in the ENV or not try: @@ -68,8 +113,8 @@ except: sys.exit(1) if (args.list): - for module in all_modules: - print(dir(module)) + make_the_list() + print_the_list() # arg_list has to be defined otherwise will cause an exception