How to use awsume - 10 common examples

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 / test_app.py View on Github external
def test_app_init(init: MagicMock, get_plugin_manager: MagicMock, load_config: MagicMock):
    obj = app.Awsume()

    init.assert_called_with(autoreset=True)

    get_plugin_manager.assert_called()
    load_config.assert_called()
    assert obj.config == load_config.return_value
    assert obj.plugin_manager == get_plugin_manager.return_value
github trek10inc / awsume / test / unit / awsume / awsumepy / test_default_plugins.py View on Github external
def test_post_add_arguments_role_arn_explicit(safe_print: MagicMock):
    config = {}
    arguments = argparse.Namespace(
        role_arn='arn:aws:iam::123123123123:role/myrole',
        auto_refresh=False,
        version=False,
        unset_variables=False,
        config=None,
        kill=False,
        profile_name=None,
    )
    parser = argparse.ArgumentParser()
    default_plugins.post_add_arguments(config, arguments, parser)
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 / test / unit / awsume / awsumepy / test_app.py View on Github external
@patch.object(app.Awsume, '__init__')
def test_get_credentials(__init__: MagicMock, isatty: MagicMock):
    __init__.return_value = None
    args = argparse.Namespace(json=None, with_saml=False, with_web_identity=False)
    profiles = {}
    obj = app.Awsume()
    obj.config = {}
    obj.plugin_manager = MagicMock()
    isatty.return_value = True
    obj.plugin_manager.hook.get_credentials.return_value = [{'AccessKeyId': 'AKIA...', 'SecretAccessKey': 'SECRET', 'SessionToken': 'LONGSECRET', 'Region': 'us-east-1'}]

    result = obj.get_credentials(args, profiles)

    obj.plugin_manager.hook.get_credentials.assert_called_with(config=obj.config, arguments=args, profiles=profiles)
    assert result == {'AccessKeyId': 'AKIA...', 'SecretAccessKey': 'SECRET', 'SessionToken': 'LONGSECRET', 'Region': 'us-east-1'}
github trek10inc / awsume / test / unit / awsume / awsumepy / test_app.py View on Github external
def test_get_credentials_profile_not_found_error(__init__: MagicMock, safe_print: MagicMock, isatty: MagicMock):
    __init__.return_value = None
    args = argparse.Namespace(json=None, with_saml=False, with_web_identity=False)
    profiles = {}
    obj = app.Awsume()
    obj.config = {}
    obj.plugin_manager = MagicMock()
    isatty.return_value = True

    obj.plugin_manager.hook.get_credentials.side_effect = ProfileNotFoundError()
    with pytest.raises(SystemExit):
        obj.get_credentials(args, profiles)
    obj.plugin_manager.hook.catch_profile_not_found_exception.assert_called_with(config=obj.config, arguments=args, error=obj.plugin_manager.hook.get_credentials.side_effect, profiles=profiles)
github trek10inc / awsume / test / unit / awsume / awsumepy / test_app.py View on Github external
def test_get_credentials_role_authentication_error(__init__: MagicMock, safe_print: MagicMock, isatty: MagicMock):
    __init__.return_value = None
    args = argparse.Namespace(json=None, with_saml=False, with_web_identity=False)
    profiles = {}
    obj = app.Awsume()
    obj.config = {}
    obj.plugin_manager = MagicMock()
    isatty.return_value = True

    obj.plugin_manager.hook.get_credentials.side_effect = RoleAuthenticationError()
    with pytest.raises(SystemExit):
        obj.get_credentials(args, profiles)
    obj.plugin_manager.hook.catch_role_authentication_error.assert_called_with(config=obj.config, arguments=args, error=obj.plugin_manager.hook.get_credentials.side_effect, profiles=profiles)
github trek10inc / awsume / test / unit / awsume / awsumepy / test_app.py View on Github external
def test_get_plugin_manager(__init__: MagicMock, PluginManager: MagicMock):
    __init__.return_value = None
    pm = MagicMock()
    PluginManager.return_value = pm

    obj = app.Awsume()
    response = obj.get_plugin_manager()

    PluginManager.assert_called_with('awsume')
    pm.add_hookspecs.assert_called_once_with(hookspec)
    pm.register.assert_called_once()
    pm.load_setuptools_entrypoints.assert_called_once_with('awsume')
    assert response == pm
github trek10inc / awsume / test / unit / awsume / awsumepy / test_app.py View on Github external
def test_run_auto_refresh(__init__: MagicMock, isatty: MagicMock):
    __init__.return_value = None
    obj = app.Awsume()
    obj.config = {}
    obj.plugin_manager = MagicMock()
    obj.parse_args = MagicMock()
    obj.get_profiles = MagicMock()
    obj.export_data = MagicMock()
    obj.get_credentials = MagicMock()
    obj.parse_args.return_value = argparse.Namespace(with_saml=False, with_web_identity=False, auto_refresh=True, target_profile_name='default', json=None)
    obj.get_credentials.return_value = {'AccessKeyId': 'AKIA...', 'SecretAccessKey': 'SECRET', 'SessionToken': 'LONGSECRET', 'Region': 'us-east-1'}
    isatty.return_value = True

    obj.run([])

    obj.export_data.assert_called_with('Auto', [
        'autoawsume-default', 'us-east-1', 'default'
    ])
github trek10inc / awsume / test / unit / awsume / awsumepy / test_app.py View on Github external
def test_get_credentials_invalid_profile_error(__init__: MagicMock, safe_print: MagicMock, isatty: MagicMock):
    __init__.return_value = None
    args = argparse.Namespace(json=None, with_saml=False, with_web_identity=False)
    profiles = {}
    obj = app.Awsume()
    obj.config = {}
    obj.plugin_manager = MagicMock()
    isatty.return_value = True

    obj.plugin_manager.hook.get_credentials.side_effect = InvalidProfileError(profile_name='profile')
    with pytest.raises(SystemExit):
        obj.get_credentials(args, profiles)
    obj.plugin_manager.hook.catch_invalid_profile_exception.assert_called_with(config=obj.config, arguments=args, error=obj.plugin_manager.hook.get_credentials.side_effect, profiles=profiles)