def credentials_are_valid(): try: elasticbeanstalk.get_available_solution_stacks(fail_on_empty_response=False) return True except CredentialsError: return False except NotAuthorizedError as e: io.log_error('The current user does not have the correct permissions. ' 'Reason: {0}'.format(e.message)) return False
def get_solution_stack_from_customer(module_name=None): """ Method prompts customer for a platform name, and if applicable, a platform version name :param module_name: An `module_name` to choose a platform corresponding to a particular module in the EB application. This is applicable if the directory is being `eb init`-ed with the `--modules` argument. :return: A SolutionStack object representing the the customers choice of platform """ solution_stacks = elasticbeanstalk.get_available_solution_stacks() solution_stacks_grouped_by_language_name = SolutionStack.group_solution_stacks_by_language_name(solution_stacks) language_names_to_display = [solution_stack['LanguageName'] for solution_stack in solution_stacks_grouped_by_language_name] custom_platforms = platformops.list_custom_platform_versions() if custom_platforms: language_names_to_display.append(CUSTOM_PLATFORM_OPTION) chosen_language_name = prompt_for_language_name(language_names_to_display, module_name) if chosen_language_name == CUSTOM_PLATFORM_OPTION: return platformops.get_custom_platform_from_customer(custom_platforms) return SolutionStack(resolve_language_version(chosen_language_name, solution_stacks))
def complete_command(self, commands): app_name = fileoperations.get_application_name() self.complete_region(commands) # We only care about top command, because there are no positional ## args for this command cmd = commands[-1] if cmd in ['-t', '--tier']: io.echo(*Tier.get_all_tiers()) if cmd in ['-s', '--solution']: io.echo(*elasticbeanstalk.get_available_solution_stacks()) if cmd in ['-vl', '--versionlabel']: io.echo(*elasticbeanstalk.get_app_version_labels(app_name))
def find_solution_stack_from_string(solution_string, find_newer=False): """ Method returns a SolutionStack object representing the given `solution_string`. If the `solution_string` matches ARNs and complete names of solution stacks, the exact match is returned. In the event when there are multiple matches, the latest version is returned. :param solution_string: A string in one of the following (case-insensitive) forms: - PlatformArn: - EB-managed: 'arn:aws:elasticbeanstalk:us-west-2::platform/Multi-container Docker running on 64bit Amazon Linux/2.8.0' - Custom: arn:aws:elasticbeanstalk:us-west-2:123412341234:platform/custom_platform/1.0.0 - complete name: '64bit Amazon Linux 2017.03 v2.7.5 running Multi-container Docker 17.03.2-ce (Generic)' - shorthand: 'Multi-container Docker 17.03.2-ce (Generic)' - language name: 'Multi-container Docker' - pythonified shorthand: 'multi-container-docker-17.03.2-ce-(generic)' :param find_newer: If solution_string is a complete name or a PlatformArn that uniquely matches a solution stack or platform, find the newest version of the solution stack. :return: A SolutionStack object representing the latest version of the `solution_string`. In case of a custom platform, the return value is a PlatformVersion object. """ # Compare input with PlatformARNs match = None if PlatformVersion.is_eb_managed_platform_arn(solution_string): if find_newer: match = platformops.get_latest_eb_managed_platform(solution_string) else: match = platform_arn_to_solution_stack(solution_string) elif PlatformVersion.is_custom_platform_arn(solution_string): if find_newer: match = platformops.get_latest_custom_platform(solution_string) else: match = platformops.find_custom_platform_from_string(solution_string) # Compare input with complete SolutionStack name and retrieve latest SolutionStack # in the series if `find_newer` is set to True if not match: available_solution_stacks = elasticbeanstalk.get_available_solution_stacks() match = SolutionStack.match_with_complete_solution_string(available_solution_stacks, solution_string) if match and find_newer: language_name = SolutionStack(solution_string).language_name match = SolutionStack.match_with_solution_string_language_name(available_solution_stacks, language_name) # Compare input with other forms for solution_string_matcher in [ SolutionStack.match_with_solution_string_shorthand, SolutionStack.match_with_solution_string_language_name, SolutionStack.match_with_pythonified_solution_string, ]: if not match: match = solution_string_matcher(available_solution_stacks, solution_string) # Compare input with custom platform names if not match: match = platformops.find_custom_platform_from_string(solution_string) if not match: raise NotFoundError('Platform "{}" does not appear to be valid'.format(solution_string)) return match
def complete_command(self, commands): self.complete_region(commands) #Note, completing solution stacks is only going to work ## if they already have their keys set up with region if commands[-1] in ['-s', '--solution']: io.echo(*elasticbeanstalk.get_available_solution_stacks())
def get_all_platforms(): return elasticbeanstalk.get_available_solution_stacks()