How to use the awsume.awsumepy.lib.safe_print.safe_print 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 / test / unit / awsume / awsumepy / lib / test_safe_print.py View on Github external
def test_safe_print_color(open: MagicMock, stderr: MagicMock, yaml_load: MagicMock):
    yaml_load.return_value = {'colors': True}
    with patch.object(os, 'name', 'nt'):
        safe_print('Text', color=colorama.Fore.RED)
    assert colorama.Fore.RED not in stderr.getvalue()
    with patch.object(os, 'name', 'darwin'):
        safe_print('Text', color=colorama.Fore.RED)
    assert colorama.Fore.RED in stderr.getvalue()
github trek10inc / awsume / test / unit / awsume / awsumepy / lib / test_safe_print.py View on Github external
def test_safe_print_color(open: MagicMock, stderr: MagicMock, yaml_load: MagicMock):
    yaml_load.return_value = {'colors': True}
    with patch.object(os, 'name', 'nt'):
        safe_print('Text', color=colorama.Fore.RED)
    assert colorama.Fore.RED not in stderr.getvalue()
    with patch.object(os, 'name', 'darwin'):
        safe_print('Text', color=colorama.Fore.RED)
    assert colorama.Fore.RED in stderr.getvalue()
github trek10inc / awsume / awsume / awsumepy / app.py View on Github external
choice = principal_plus_role_arn
            elif args.profile_name:
                profile_role_arn = profiles.get(args.profile_name, {}).get('role_arn')
                principal_arn = profiles.get(args.profile_name, {}).get('principal_arn')
                if profile_role_arn is None or principal_arn is None:
                    raise exceptions.InvalidProfileError(args.profile_name, 'both role_arn and principal_arn are necessary for saml profiles')
                principal_plus_profile_role_arn = ','.join([principal_arn, profile_role_arn])
                if principal_plus_profile_role_arn in roles:
                    choice = principal_plus_profile_role_arn
                else:
                    raise exceptions.SAMLRoleNotFoundError(principal_arn, profile_role_arn)
                safe_print('Match: {}'.format(choice))
            else:
                for index, choice in enumerate(roles):
                    safe_print('{}) {}'.format(index, choice), color=colorama.Fore.LIGHTYELLOW_EX)
                safe_print('Which role do you want to assume? > ', end='', color=colorama.Fore.LIGHTCYAN_EX)
                response = input()
                if response.isnumeric():
                    choice = roles[int(response)]
                else:
                    choice = difflib.get_close_matches(response, roles, cutoff=0)[0]
            role_arn = choice.split(',')[1]
            principal_arn = choice.split(',')[0]
        else:
            role_arn = roles[0].split(',')[1]
            principal_arn = roles[0].split(',')[0]
        safe_print('Assuming role: {},{}'.format(principal_arn, role_arn), color=colorama.Fore.GREEN)
        credentials = aws_lib.assume_role_with_saml(
            role_arn,
            principal_arn,
            assertion,
            region=None,
github trek10inc / awsume / awsume / awsumepy / app.py View on Github external
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 / profile.py View on Github external
def get_mfa_token() -> str:
    token_pattern = re.compile('^[0-9]{6}$')
    safe_print('Enter MFA token: ', colorama.Fore.CYAN, end='')
    while True:
        mfa_token = input()
        if token_pattern.match(mfa_token):
            return mfa_token
        else:
            safe_print('Please enter a valid MFA token: ', colorama.Fore.CYAN, end='')
github trek10inc / awsume / awsume / awsumepy / lib / config_management.py View on Github external
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']:
        default_value = get_dict_parts(defaults, operations[1])
        if default_value is None:
            raise exceptions.ConfigOperationException('Key does not have a default: {}'.format(operations[1]), colorama.Fore.YELLOW)
        config = update_dict_parts(config, operations[1], default_value)
        safe_print('Reset key {} to {}'.format(operations[1], default_value), colorama.Fore.YELLOW)

    if operations[0].lower() in ['clear']:
        config, deleted = delete_dict_value_parts(config, operations[1])
        if deleted:
            safe_print('Deleted key {}'.format(operations[1]), colorama.Fore.YELLOW)

    write_config(config)
github trek10inc / awsume / awsume / awsumepy / lib / config_management.py View on Github external
def write_config(config: dict):
    if not os.path.exists(str(constants.AWSUME_DIR)):
        os.makedirs(str(constants.AWSUME_DIR))
    if not os.path.isfile(str(constants.AWSUME_CONFIG)):
        open(str(constants.AWSUME_CONFIG), 'a').close()

    try:
        yaml.safe_dump(config, open(str(constants.AWSUME_CONFIG), 'w'), width=1000)
    except Exception as e:
        safe_print('Unable to write config: {}'.format(e), colorama.Fore.RED)
github trek10inc / awsume / awsume / awsumepy / lib / profile.py View on Github external
def get_mfa_token() -> str:
    token_pattern = re.compile('^[0-9]{6}$')
    safe_print('Enter MFA token: ', colorama.Fore.CYAN, end='')
    while True:
        mfa_token = input()
        if token_pattern.match(mfa_token):
            return mfa_token
        else:
            safe_print('Please enter a valid MFA token: ', colorama.Fore.CYAN, end='')