def set_up_credentials(given_profile, given_region, interactive, force_non_interactive=False): if given_profile: # Profile already set at abstractController profile = given_profile elif os.environ.get('AWS_ACCESS_KEY_ID') and os.environ.get('AWS_SECRET_ACCESS_KEY'): profile = None else: profile = 'eb-cli' aws.set_profile(profile) profile, _ = check_credentials(profile, given_profile, given_region, interactive, force_non_interactive) if not credentials_are_valid(): setup_credentials() else: fileoperations.write_config_setting('global', 'profile', profile)
def set_up_credentials(given_profile, given_region, interactive, force_non_interactive=False): if given_profile: # Profile already set at abstractController profile = given_profile else: profile = 'eb-cli' aws.set_profile(profile) profile, region = check_credentials(profile, given_profile, given_region, interactive, force_non_interactive) if not initializeops.credentials_are_valid(): initializeops.setup_credentials() else: fileoperations.write_config_setting('global', 'profile', profile) return region
def check_credentials(profile, given_profile, given_region, interactive, force_non_interactive): try: # Note, region is None unless explicitly set or read from old eb initializeops.credentials_are_valid() return profile, given_region except NoRegionError: region = get_region(None, interactive, force_non_interactive) aws.set_region(region) return profile, region except InvalidProfileError as e: if given_profile: # Provided profile is invalid, raise exception raise e else: # eb-cli profile doesnt exist, revert to default # try again profile = None aws.set_profile(profile) return check_credentials(profile, given_profile, given_region, interactive, force_non_interactive)
def check_credentials(profile, given_profile, given_region, interactive, force_non_interactive): try: # Note, region is None unless explicitly set or read from old eb initializeops.credentials_are_valid() return profile, given_region except NoRegionError: region = get_region(None, interactive, force_non_interactive) aws.set_region(region) return profile, region except InvalidProfileError: if given_profile: # Provided profile is invalid, raise exception raise else: # eb-cli profile doesnt exist, revert to default # try again profile = None aws.set_profile(profile) return check_credentials(profile, given_profile, given_region, interactive, force_non_interactive)
def ssh(self): aws.set_region(self.region) aws.set_profile(self.profile) if self.environment_name is None: environment_names = get_all_environment_names() if environment_names: error = "Please chose one of the following environment names:\n\n" error += "\n".join(sorted(environment_names)) + "\n" io.log_error(error) else: io.log_error( "The current Elastic Beanstalk application has no environments" ) sys.exit() instances = get_instance_ids(self.environment_name) if len(instances) == 1: instance = instances[0] else: io.echo() io.echo('Select an instance to ssh into') instance = utils.prompt_for_item_in_list(instances) params = [ "aws", "ssm", "start-session", "--document-name", "AWS-StartInteractiveCommand", "--parameters", "command='bash -l'", "--profile", self.profile, "--region", self.region, "--target", instance, ] os.system(" ".join(params))
def check_credentials(self, profile): given_profile = self.app.pargs.profile try: # Note, region is None unless explicitly set ## or read from old eb initializeops.credentials_are_valid() return profile except NoRegionError: self.region = self.get_region() aws.set_region(self.region) return profile except InvalidProfileError: if given_profile: # Provided profile is invalid, raise exception raise else: # eb-cli profile doesnt exist, revert to default # try again profile = None aws.set_profile(profile) return self.check_credentials(profile)
def main(): """ Main function called from console_scripts """ logger = logging.getLogger('ebi') logger.propagate = True logger.setLevel(logging.INFO) logger.addHandler(logging.StreamHandler()) parser = argparse.ArgumentParser() subparsers = parser.add_subparsers() parser_bgdeploy = subparsers.add_parser('bgdeploy') parser_clonedeploy = subparsers.add_parser('clonedeploy') parser_create = subparsers.add_parser('create') parser_deploy = subparsers.add_parser('deploy') apply_args_bgdeploy(parser_bgdeploy) apply_args_clonedeploy(parser_clonedeploy) apply_args_create(parser_create) apply_args_deploy(parser_deploy) parsed = parser.parse_args() if not hasattr(parsed, 'func'): parser.print_help() return conf = {} if parsed.profile: conf['profile_name'] = parsed.profile if parsed.region: conf['region_name'] = parsed.region boto3.setup_default_session(**conf) session = boto3._get_default_session() ebaws.set_region(session._session.get_config_variable('region')) ebaws.set_profile(session.profile_name) parsed.func(parsed)
def default(self): """ Creates a space separated list of possible completions. We actually do not need to calculate the completions. We can simply just generate a list of ALL possibilities, and then the bash completer module is smart enough to filter out the ones that don't match. Results must be printed through stdin for the completer module to read then. """ commands = self.app.pargs.cmplt.strip('"') # Get commands, filter out last one commands = commands.split(' ') word_so_far = commands[-1] commands = commands[0:-1] commands = list(filter(lambda x: len(x) > 0, commands)) #Get the list of controllers self.controllers = handler.list('controller') self._filter_controllers() ctrlr = self._get_desired_controller(commands) if not ctrlr: return # command entered so far is invalid, we dont need to ## worry about completion if word_so_far.startswith('--'): # Get all base option flags self.complete_options(ctrlr) else: if ctrlr == self.base_controller: # Get standard command list io.echo(*[ c.Meta.label for c in self.controllers if not hasattr(c.Meta, 'stacked_type') ]) else: # A command has been provided. Complete at a deeper level ctrlr = ctrlr() # Instantiate so we can read all arguments if not hasattr(ctrlr, 'complete_command'): return # Controller does not support completion try: #Set up aws profile just in case we need to make a service call profile = commonops.get_default_profile() if profile: aws.set_profile(profile) ctrlr.complete_command(commands) except: #We want to swallow ALL exceptions. We can ## not print any output when trying to tab-complete ## because any output gets passed to the user as ## completion candidates ### Exceptions here are normally thrown because the service ### can not be contacted for things such as environment ### list and solution stack list. Typically, credentials ### are not set up yet pass