def output_instructions(self, docker_file, bash_file): if Common.get_output_format() == Common.quiet_out: Common.echo( message='export AWS_PROFILE={}'.format(self.profile), always_stdout=True ) elif Common.get_output_format() == Common.long_out: Common.echo( message='\nAWS keys generated.\nTo use with docker-compose include\n' + '\tenv_file:\n\t - {}\n'.format(docker_file) + 'To use with shell scripts include\n\tsource {}\n'.format(bash_file) + 'to use in the current interactive shell run\n\texport AWS_PROFILE={}\n'.format(self.profile) ) else: Common.echo( message='Add the "-i" flag for how to use credentials and override defaults or just run:\n\n' + 'export AWS_PROFILE={}\n'.format(self.profile) )
def choose_role(self): """ Look for a default role defined and, if not, prompt the user for one Allow the user to also specify the role is the default to be used from now on :return: a tuple of the chosen role and whether it is the new default :rtype: AwsRole, bool """ # throw an error if no roles are provided # (defensive coding only - this should not be possible) if not self.possible_roles: Common.dump_err( message='No AWS Role was assigned to this application!') raise ValueError( 'Unexpected configuration - No AWS role assigned to Okta login.' ) # use the one provided if there is only one if len(self.possible_roles) == 1: role = self.possible_roles[0] if self.role_preference and role.role_arn != self.role_preference: Common.dump_err( message= 'Your cofigured role "{notfound}" was not found; using "{found}" role' .format(notfound=self.role_preference, found=role.role_name)) elif Common.is_debug(): Common.echo(message="Using default role '{role}'".format( role=role.role_arn)) return role, False # use the configured role if it matches one from the the SAML assertion for role in self.possible_roles: if role.role_arn == self.role_preference: message = "Using default role '{}'".format(role.role_name) extra_message = '. Run "clokta --no-default-role" to override.' if Common.get_output_format() == Common.long_out: Common.echo(message + extra_message) else: Common.echo(message) return role, True # make the user choose return self.__prompt_for_role(with_set_default_option=True)