Example #1
0
    def test_basic(self):
        parser = OneLoginAWSArgumentParser()
        args = parser.parse_args([
            '-C', 'my_config', '--profile', 'my_profile', '-u', 'my_username'
        ])

        self.assertEqual(args.config_name, 'my_config')
        self.assertEqual(args.profile, 'my_profile')
        self.assertEqual(args.username, 'my_username')
Example #2
0
    def test_legacy_renew_seconds(self):
        parser = OneLoginAWSArgumentParser()
        args = parser.parse_args(['--renewSeconds', '30'])

        self.assertEqual(args.renew_seconds_legacy, 30)

        with self.assertRaises(SystemExit) as cm:
            parser.parse_args([
                '--renewSeconds',
                '30',
                '--renew-seconds',
                '30',
            ])

        self.assertEqual(cm.exception.code, 2)
Example #3
0
    def test_version(self):
        parser = OneLoginAWSArgumentParser()
        mock_stdout = StringIO()

        with self.assertRaises(SystemExit) as cm:
            with contextlib.redirect_stdout(mock_stdout):
                parser.parse_args(['--version'])

        # This spits out the nosetest prog name.
        # I'm ok with that, as what is important is that the version is
        # correct
        version = pkg_resources.get_distribution('onelogin_aws_cli').version
        self.assertRegex(mock_stdout.getvalue(), re.escape(version) + r'$')

        self.assertEqual(cm.exception.code, 0)
Example #4
0
def login(args=sys.argv[1:]):
    """
    Entrypoint for `onelogin-aws-login`
    :param args:
    """

    debug = environ.get('ONELOGIN_AWS_CLI_DEBUG', '0') == '1'
    try:

        cfg = ConfigurationFile()
        parser = OneLoginAWSArgumentParser()
        config_section, args = _load_config(parser, cfg, args)

        # Handle legacy `--renewSeconds` option while it is deprecated
        if args.renew_seconds or args.renew_seconds_legacy:
            print("ERROR: --renewSeconds  and --renew-seconds have been "
                  "deprecated due to longer AWS STS sessions.")
            print("These options will be removed completely in "
                  "a future version.")
            sys.exit(1)

        config_section.set_overrides(vars(args))

        api = OneloginAWS(config_section)
        api.save_credentials()

    except Exception as e:
        if debug:
            raise e

        print(str(e))
        sys.exit(1)
    def test_environment_variable(self):
        environ['ONELOGIN_AWS_CLI_CONFIG_NAME'] = 'mock-config'
        environ['ONELOGIN_AWS_CLI_PROFILE'] = 'mock-profile'
        environ['ONELOGIN_AWS_CLI_USERNAME'] = '******'
        environ['ONELOGIN_AWS_CLI_DURATION_SECONDS'] = '10'

        parser = OneLoginAWSArgumentParser()

        args = parser.parse_args([])

        self.assertEqual('mock-config', args.config_name)
        self.assertEqual('mock-profile', args.profile)
        self.assertEqual('mock-username', args.username)
        self.assertEqual(10, args.duration_seconds)

        del environ['ONELOGIN_AWS_CLI_CONFIG_NAME']
        del environ['ONELOGIN_AWS_CLI_PROFILE']
        del environ['ONELOGIN_AWS_CLI_USERNAME']
        del environ['ONELOGIN_AWS_CLI_DURATION_SECONDS']
    def test_add_cli_options(self):
        parser = OneLoginAWSArgumentParser()
        args = parser.parse_args([
            '-C',
            'my_config',
            '--profile',
            'my_profile',
            '-u',
            'my_username',
            '-c',
            '-d',
            '43200',
        ])

        self.assertEqual(args.config_name, 'my_config')
        self.assertEqual(args.profile, 'my_profile')
        self.assertEqual(args.username, 'my_username')
        self.assertTrue(args.configure)
        self.assertEqual(args.duration_seconds, 43200)
Example #7
0
def login(args=sys.argv[1:]):
    """
    Entrypoint for `onelogin-aws-login`
    :param args:
    """

    cfg = ConfigurationFile()
    parser = OneLoginAWSArgumentParser()
    config_section, args = _load_config(parser, cfg, args)

    # Handle legacy `--renewSeconds` option while it is deprecated
    if args.renew_seconds or args.renew_seconds_legacy:
        print("ERROR: --renewSeconds  and --renew-seconds have been "
              "deprecated due to longer AWS STS sessions.")
        print("These options will be removed completely in a future version.")
        sys.exit(1)

    config_section.set_overrides(vars(args))

    api = OneloginAWS(config_section)
    api.save_credentials()
Example #8
0
def login(args=sys.argv[1:]):
    """
    Entrypoint for `onelogin-aws-login`
    :param args:
    """

    debug = environ.get('ONELOGIN_AWS_CLI_DEBUG', '0') == '1'
    try:

        cfg = ConfigurationFile()
        parser = OneLoginAWSArgumentParser()
        config_section, args = _load_config(parser, cfg, args)

        config_section.set_overrides(vars(args))

        api = OneloginAWS(config_section)
        api.save_credentials()

    except Exception as e:
        if debug:
            raise e

        print(str(e))
        sys.exit(1)
Example #9
0
 def test_default_duration(self):
     parser = OneLoginAWSArgumentParser()
     args = parser.parse_args([])
     self.assertEqual(args.duration_seconds, 3600)