コード例 #1
0
ファイル: cli.py プロジェクト: teitei-tk/onelogin-aws-cli
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)
コード例 #2
0
    def test_initialise(self):
        str = StringIO()
        cfg = ConfigurationFile(str)
        with patch('builtins.input',
                   side_effect=['2', 'mock_client_id', 'mock_client_secret',
                                'mock_aws_app_id', 'mock_subdomain']):
            cfg.initialise()
        str.seek(0)

        self.assertEqual("""[defaults]
base_uri = https://api.eu.onelogin.com/
client_id = mock_client_id
client_secret = mock_client_secret
aws_app_id = mock_aws_app_id
subdomain = mock_subdomain

""", str.getvalue())
コード例 #3
0
    def test_has_defaults(self):
        content = StringIO()
        cf = ConfigurationFile(content)
        self.assertFalse(cf.has_defaults)

        cf = helper.build_config("""[defaults]
first=foo""")
        self.assertTrue(cf.has_defaults)
コード例 #4
0
    def test_is_initialised(self):

        content = StringIO()
        cf = ConfigurationFile(content)
        self.assertFalse(cf.is_initialised)

        cf = self._helper_build_config("""[section]
first=foo""")
        self.assertTrue(cf.is_initialised)
コード例 #5
0
ファイル: cli.py プロジェクト: glnds/onelogin-aws-cli
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()
コード例 #6
0
ファイル: cli.py プロジェクト: zaccafferty/onelogin-aws-cli
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)
コード例 #7
0
ファイル: cli.py プロジェクト: glnds/onelogin-aws-cli
def _load_config(parser, config_file: ConfigurationFile, args=sys.argv[1:]):
    cli_args = parser.parse_args(args)

    with open(DEFAULT_CONFIG_PATH, 'a+') as fp:
        fp.seek(0, 0)
        config_file.file = fp
        config_file.load()

    if (cli_args.configure or not config_file.is_initialised):
        config_file.initialise(cli_args.config_name)

    config_section = config_file.section(cli_args.config_name)

    if config_section is None:
        sys.exit(
            "Configuration '{}' not defined. "
            "Please run 'onelogin-aws-login -c'".format(
                cli_args.config_name
            )
        )

    return config_section, cli_args
コード例 #8
0
 def _helper_build_config(self, config_content: str):
     str = StringIO()
     str.write(config_content)
     str.seek(0)
     return ConfigurationFile(str)
コード例 #9
0
def build_config(config_content: str):
    str = StringIO()
    str.write(config_content)
    str.seek(0)
    return ConfigurationFile(str)