Esempio n. 1
0
    def initialise(self, config_name='defaults'):
        """
        Prompt the user for configurations, and save them to the
        onelogin-aws-cli config file
        """
        print("Configure Onelogin and AWS\n\n")
        config_section = self.section(config_name)
        if config_section is None:
            self.add_section(config_name)
            config_section = self.section(config_name)

        config_section['base_uri'] = user_choice(
            "Pick a Onelogin API server:", [
                "https://api.us.onelogin.com/",
                "https://api.eu.onelogin.com/"
            ]
        )

        print("\nOnelogin API credentials. These can be found at:\n"
              "https://admin.us.onelogin.com/api_credentials")
        config_section['client_id'] = input("Onelogin API Client ID: ")
        config_section['client_secret'] = input("Onelogin API Client Secret: ")
        print("\nOnelogin AWS App ID. This can be found at:\n"
              "https://admin.us.onelogin.com/apps")
        config_section['aws_app_id'] = input("Onelogin App ID for AWS: ")
        print("\nOnelogin subdomain is 'company' for login domain of "
              "'comany.onelogin.com'")
        config_section['subdomain'] = input("Onelogin subdomain: ")

        self.save()
    def test_user_choice_bad(self):
        mock_stdout = StringIO()

        with patch('builtins.input', side_effect=['bar', '2']):
            with contextlib.redirect_stdout(mock_stdout):
                result = user_choice('one', ['hallo', 'world', 'foo'])

        output = mock_stdout.getvalue()
        assert result == "world"
        assert "Invalid option" in output
Esempio n. 3
0
    def select_device(self, devices: List[Device]):
        """Given a list of MFA devices, select one for use"""

        self._devices = devices

        self.device = user_choice(
            'Pick an OTP Device:',
            self._devices,
            renderer=lambda d: d.type,
            saved_choice=self._config.get("otp_device"),
        )
    def test_user_choice_bad_preselected(self):
        mock_stdout = StringIO()

        with patch('builtins.input', side_effect=['2']):
            with contextlib.redirect_stdout(mock_stdout):
                result = user_choice('one', ['foo', 'bar'], saved_choice='baz')

        output = mock_stdout.getvalue()
        assert result == "bar"
        assert "Invalid option" not in output
        assert "Ignoring invalid saved choice" in output
 def test_user_choice_preselected(self):
     result = user_choice('one', ['foo', 'bar'], saved_choice='bar')
     self.assertEqual('bar', result)
 def test_user_choice_one_option(self):
     result = user_choice('one', ['foo'])
     self.assertEqual('foo', result)
 def test_user_choice_no_options(self):
     with self.assertRaises(Exception):
         user_choice('one', [])