def collect_credentials(): # Log the csv files found in the vault directory for csv in glob(vault + '/*.csv'): logging.info("Found csv file: %s" % csv) csv_credentials = AWS_keypair_management.AWS_keypair_management() (credentials, bad_files) = csv_credentials.Get_Working_Credentials(vault) # If there is more than one AWS key pair then display them using a menu, otherwise just select the one if len(credentials) > 1: # Log the valid AWS credentials that are found logging.info("Multiple AWS credentials found:") for credential in credentials: logging.info( "AWS credential found: %s : %s" % (credential, credentials[credential]['Creds'][0]['Access_Key_Id'])) title = "Which AWS credentials do you want to use? Below is the list of user names." top_instructions = "Use the arrow keys make your selection and press return to continue" bottom_instructions = "" user_input = curses_menu.curses_menu( credentials, title=title, top_instructions=top_instructions, bottom_instructions=bottom_instructions) user_id = credentials.keys()[int(user_input)] logging.info( "AWS credential selected: %s : %s" % (user_id, credentials[user_id]['Creds'][0]['Access_Key_Id'])) elif len(credentials) == 1: user_id = credentials.keys()[0] logging.info("One AWS credential found and selected: %s : %s" % (user_id, credentials.keys()[0])) else: logging.info("No AWS credentials found") sys.exit("No AWS credentials found.") entry = credentials[user_id] key_id = entry['Creds'][0]['Access_Key_Id'] secret_key = entry['Creds'][0]['Secret_Access_Key'] try: s3 = boto.connect_s3(aws_access_key_id=key_id, aws_secret_access_key=secret_key) except Exception, e: logging.info("There was an error connecting to AWS: %s" % e) sys.exit("There was an error connecting to AWS: %s" % e)
def collect_credentials(): # Log the csv files found in the vault directory for csv in glob(vault+'/*.csv'): logging.info("Found csv file: %s" % csv) csv_credentials = AWS_keypair_management.AWS_keypair_management() (credentials, bad_files) = csv_credentials.Get_Working_Credentials(vault) # If there is more than one AWS key pair then display them using a menu, otherwise just select the one if len(credentials) > 1: # Log the valid AWS credentials that are found logging.info("Multiple AWS credentials found:") for credential in credentials: logging.info("AWS credential found: %s : %s" % (credential, credentials[credential]['Creds'][0]['Access_Key_Id'])) title = "Which AWS credentials do you want to use? Below is the list of user names." top_instructions = "Use the arrow keys make your selection and press return to continue" bottom_instructions = "" user_input = curses_menu.curses_menu(credentials, title=title, top_instructions=top_instructions, bottom_instructions=bottom_instructions) user_id = credentials.keys()[int(user_input)] logging.info("AWS credential selected: %s : %s" % (user_id, credentials[user_id]['Creds'][0]['Access_Key_Id'])) elif len(credentials) == 1: user_id = credentials.keys()[0] logging.info("One AWS credential found and selected: %s : %s" % (user_id, credentials.keys()[0])) else: logging.info("No AWS credentials found") sys.exit("No AWS credentials found.") entry = credentials[user_id] key_id = entry['Creds'][0]['Access_Key_Id'] secret_key = entry['Creds'][0]['Secret_Access_Key'] try: # TODO: make us-east-1 variable conn = boto.ec2.connect_to_region("us-east-1", aws_access_key_id=key_id, aws_secret_access_key=secret_key) except Exception, e: logging.info("There was an error connecting to AWS: %s" % e) sys.exit("There was an error connecting to AWS: %s" % e)
logging.info("Found .pem file: %s" % pem_file) # Display the .pem files using a menu, otherwise just select the one if len(pem_files) > 0: # Log the pem files found logging.info("Multiple .pem files found:") for pem_file in pem_files: logging.info("Found .pem file: %s " % pem_file) # Add an option in case the user doesn't have the .pem file pem_files.append("I don't have the EMR .pem file") title = "Selected the .pem file provided by the course TA to use with EMR? Below is the list of .pem files." top_instructions = "Use the arrow keys make your selection and press return to continue" bottom_instructions = "" user_input = curses_menu.curses_menu(pem_files, title=title, top_instructions=top_instructions, bottom_instructions=bottom_instructions) if len(pem_files) == int(user_input) + 1: pem = "" logging.info("Selected .pem file: I don't have the EMR .pem file") else: pem = pem_files[int(user_input)] logging.info("Selected .pem file: %s " % pem) else: logging.info("No .pem files found in vault: %s" % vault) new_credentials = {} # If a Creds.pkl file already exists, make a copy, read the non 'launcher' credentials if os.path.isfile(vault + "/Creds.pkl"): logging.info("Found existing %s/Creds.pkl" % vault) # Make a copy of vault/Creds.pkl before making any changes old_credentials = vault + "/Creds_%s.pkl" % str(int(time.time()))
# Display the .pem files using a menu, otherwise just select the one if len(pem_files) > 0: # Log the pem files found logging.info("Multiple .pem files found:") for pem_file in pem_files: logging.info("Found .pem file: %s " % pem_file) # Add an option in case the user doesn't have the .pem file pem_files.append("I don't have the EMR .pem file") title = "Selected the .pem file provided by the course TA to use with EMR? Below is the list of .pem files." top_instructions = "Use the arrow keys make your selection and press return to continue" bottom_instructions = "" user_input = curses_menu.curses_menu( pem_files, title=title, top_instructions=top_instructions, bottom_instructions=bottom_instructions) if len(pem_files) == int(user_input) + 1: pem = "" logging.info("Selected .pem file: I don't have the EMR .pem file") else: pem = pem_files[int(user_input)] logging.info("Selected .pem file: %s " % pem) else: logging.info("No .pem files found in vault: %s" % vault) new_credentials = {} # If a Creds.pkl file already exists, make a copy, read the non 'launcher' credentials if os.path.isfile(vault + "/Creds.pkl"): logging.info("Found existing %s/Creds.pkl" % vault)