first pass at some pretty basic metaprogramming to make our lives easier using eval and callable

This commit is contained in:
cktricky
2018-03-04 13:06:15 -05:00
parent 62e811968a
commit 6ebadcd1ce

View File

@@ -14,7 +14,9 @@ from botocore.exceptions import ClientError
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("-s", "--step", help="list the step you would like to run", parser.add_argument("-s", "--step", help="list the step you would like to run",
action="store", type=int, required=True) action="store", type=str, required=True)
parser.add_argument("-t", "--target", help="Give your target a name so we can track results",
action="store", type=str, required=True)
parser.add_argument("-v", "--verbosity", help="increase output verbosity", parser.add_argument("-v", "--verbosity", help="increase output verbosity",
action="store_true") action="store_true")
args = parser.parse_args() args = parser.parse_args()
@@ -25,6 +27,17 @@ def perform_credential_check():
account_id = client.get_caller_identity()["Account"] account_id = client.get_caller_identity()["Account"]
except ClientError as e: except ClientError as e:
print("The AWS Access Keys are not valid/active") print("The AWS Access Keys are not valid/active")
#exit(1)
def step_something():
print("!!!")
def method_create():
try:
arg = eval("step_" + args.step)
return arg
except NameError:
print("That step does not exist")
exit(1) exit(1)
# Need to figure out if we have keys in the ENV or not # Need to figure out if we have keys in the ENV or not
@@ -32,17 +45,14 @@ if AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY:
perform_credential_check() perform_credential_check()
else: else:
print("Please supply keys as outlined in our README.md file") print("Please supply keys as outlined in our README.md file")
exit(1) #exit(1)
# We need the user to tell us the step they want to proceed on # We need the user to tell us the step they want to proceed on
if (args.step == 1): if (args.step):
print("Beginning step 1") arg = method_create()
elif (args.step == 2): if callable(arg):
print("Beginning step 2") arg()
elif (args.step == 3):
print("Beginning step 3")
else:
print("We need a valid step to continue...")
# Allow the user to specify verbosity for debugging # Allow the user to specify verbosity for debugging