How to use the awsume.awsumepy.lib.exceptions.EarlyExit function in awsume

To help you get started, we’ve selected a few awsume examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github trek10inc / awsume / awsume / awsumepy / default_plugins.py View on Github external
def post_collect_aws_profiles(config: dict, arguments: argparse.Namespace, profiles: dict):
    logger.debug('Post collect AWS profiles')
    if arguments.list_profiles:
        logger.debug('Listing profiles')
        profile_lib.list_profile_data(profiles, arguments.list_profiles == 'more')
        raise exceptions.EarlyExit()
github trek10inc / awsume / awsume / awsumepy / app.py View on Github external
args = argument_parser.parse_args(system_arguments)
        logger.debug('Handling arguments')
        if args.refresh_autocomplete:
            autocomplete_file = Path('~/.awsume/autocomplete.json').expanduser()
            result = self.plugin_manager.hook.get_profile_names(
                config=self.config,
                arguments=args,
            )
            profile_names = [y for x in result for y in x]
            json.dump({'profile-names': profile_names}, open(autocomplete_file, 'w'))
            raise exceptions.EarlyExit()
        if args.list_plugins:
            for plugin_name, _ in self.plugin_manager.list_name_plugin():
                if 'default_plugins' not in plugin_name:
                    safe_print(plugin_name, color=colorama.Fore.LIGHTCYAN_EX)
            raise exceptions.EarlyExit()
        self.plugin_manager.hook.post_add_arguments(
            config=self.config,
            arguments=args,
            parser=argument_parser,
        )
        args.system_arguments = system_arguments
        return args
github trek10inc / awsume / awsume / awsumepy / default_plugins.py View on Github external
def post_add_arguments(config: dict, arguments: argparse.Namespace, parser: argparse.ArgumentParser):
    logger.debug('Post add arguments')
    logger.debug(json.dumps(vars(arguments)))
    if arguments.auto_refresh:
        if arguments.role_arn:
            raise exceptions.ValidationException('Cannot use autoawsume with a given role_arn')
        if arguments.json:
            raise exceptions.ValidationException('Cannot use autoawsume with json')
    if arguments.version:
        logger.debug('Logging version')
        safe_print(__data__.version)
        raise exceptions.EarlyExit()
    if arguments.unset_variables:
        logger.debug('Unsetting environment variables')
        print('Unset', [])
        raise exceptions.EarlyExit()
    if type(arguments.config) is list:
        config_lib.handle_config(arguments.config)
        raise exceptions.EarlyExit()
    if arguments.kill:
        kill(arguments)
        raise exceptions.EarlyExit()

    if arguments.with_saml:
        if bool(arguments.role_arn) is not bool(arguments.principal_arn):
            parser.error('both or neither --principal-arn and --role-arn must be specified with saml')
    if not arguments.with_saml and arguments.principal_arn:
        parser.error('--principal-arn can only be specified with --with-saml')
github trek10inc / awsume / awsume / awsumepy / app.py View on Github external
self.plugin_manager.hook.add_arguments(
            config=self.config,
            parser=argument_parser,
        )
        logger.debug('Parsing arguments')
        args = argument_parser.parse_args(system_arguments)
        logger.debug('Handling arguments')
        if args.refresh_autocomplete:
            autocomplete_file = Path('~/.awsume/autocomplete.json').expanduser()
            result = self.plugin_manager.hook.get_profile_names(
                config=self.config,
                arguments=args,
            )
            profile_names = [y for x in result for y in x]
            json.dump({'profile-names': profile_names}, open(autocomplete_file, 'w'))
            raise exceptions.EarlyExit()
        if args.list_plugins:
            for plugin_name, _ in self.plugin_manager.list_name_plugin():
                if 'default_plugins' not in plugin_name:
                    safe_print(plugin_name, color=colorama.Fore.LIGHTCYAN_EX)
            raise exceptions.EarlyExit()
        self.plugin_manager.hook.post_add_arguments(
            config=self.config,
            arguments=args,
            parser=argument_parser,
        )
        args.system_arguments = system_arguments
        return args
github trek10inc / awsume / awsume / awsumepy / lib / config_management.py View on Github external
def handle_config(operations: list):
    logger.debug('Updating config: {}'.format(', '.join(operations)))
    config = load_config()

    if not len(operations):
        raise exceptions.ConfigOperationException('Must supply a config management operand')

    if operations[0].lower() == 'help':
        safe_print(CONFIG_MANAGEMENT_HELP)
        raise exceptions.EarlyExit()

    if operations[0].lower() == 'get':
        if len(operations) != 2:
            raise exceptions.ConfigOperationException('Must supply value to get')
        logger.debug('Getting {}'.format(operations[1]))
        value = get_dict_parts(config, operations[1])
        safe_print(json.dumps(value))
        raise exceptions.EarlyExit()

    if operations[0].lower() == 'list':
        if len(operations) != 1:
            raise exceptions.ConfigOperationException('No operands are valid for operation "list"')
        logger.debug('Listing config')
        yaml.safe_dump(config, sys.stderr, width=1000)
        raise exceptions.EarlyExit()
github trek10inc / awsume / awsume / awsumepy / lib / config_management.py View on Github external
config = load_config()

    if not len(operations):
        raise exceptions.ConfigOperationException('Must supply a config management operand')

    if operations[0].lower() == 'help':
        safe_print(CONFIG_MANAGEMENT_HELP)
        raise exceptions.EarlyExit()

    if operations[0].lower() == 'get':
        if len(operations) != 2:
            raise exceptions.ConfigOperationException('Must supply value to get')
        logger.debug('Getting {}'.format(operations[1]))
        value = get_dict_parts(config, operations[1])
        safe_print(json.dumps(value))
        raise exceptions.EarlyExit()

    if operations[0].lower() == 'list':
        if len(operations) != 1:
            raise exceptions.ConfigOperationException('No operands are valid for operation "list"')
        logger.debug('Listing config')
        yaml.safe_dump(config, sys.stderr, width=1000)
        raise exceptions.EarlyExit()

    if operations[0].lower() == 'set':
        if len(operations) < 3:
            raise exceptions.ConfigOperationException('Must supply value to set {} to'.format(operations[1]))
        logger.debug('Setting {} to {}'.format(operations[1], operations[2]))
        value = get_value_from_args(operations[2:])
        config = update_dict_parts(config, operations[1], value)

    if operations[0].lower() in ['reset']:
github trek10inc / awsume / awsume / awsumepy / default_plugins.py View on Github external
if arguments.json:
            raise exceptions.ValidationException('Cannot use autoawsume with json')
    if arguments.version:
        logger.debug('Logging version')
        safe_print(__data__.version)
        raise exceptions.EarlyExit()
    if arguments.unset_variables:
        logger.debug('Unsetting environment variables')
        print('Unset', [])
        raise exceptions.EarlyExit()
    if type(arguments.config) is list:
        config_lib.handle_config(arguments.config)
        raise exceptions.EarlyExit()
    if arguments.kill:
        kill(arguments)
        raise exceptions.EarlyExit()

    if arguments.with_saml:
        if bool(arguments.role_arn) is not bool(arguments.principal_arn):
            parser.error('both or neither --principal-arn and --role-arn must be specified with saml')
    if not arguments.with_saml and arguments.principal_arn:
        parser.error('--principal-arn can only be specified with --with-saml')

    if arguments.role_arn and not arguments.role_arn.startswith('arn:'):
        logger.debug('Using short-hand role arn syntax')
        parts = arguments.role_arn.split(':')
        if len(parts) == 2:
            partition = 'aws'
            account_id = parts[0]
            role_name = parts[1]
        elif len(parts) == 3:
            partition = parts[0]