How to use the keepercommander.api.query_enterprise function in keepercommander

To help you get started, weā€™ve selected a few keepercommander 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 Keeper-Security / Commander / unit-tests / test_command_enterprise.py View on Github external
def test_enterprise_wrong_user(self):
        params = get_connected_params()
        api.query_enterprise(params)

        cmd = enterprise.EnterpriseUserCommand()
        with self.assertLogs(level=logging.WARNING):
            cmd.execute(params, lock=True, email='wrong.user@keepersecurity.com')
github Keeper-Security / Commander / unit-tests / test_command_enterprise.py View on Github external
def test_enterprise_role(self):
        params = get_connected_params()
        api.query_enterprise(params)

        cmd = enterprise.EnterpriseRoleCommand()
        with mock.patch('builtins.print'):
            cmd.execute(params, role=[ent_env.role1_name])

        TestEnterprise.expected_commands = ['role_user_add']
        cmd.execute(params, add_user=[ent_env.user2_email], role=[ent_env.role1_id])
        self.assertEqual(len(TestEnterprise.expected_commands), 0)

        TestEnterprise.expected_commands = ['role_user_remove']
        cmd.execute(params, remove_user=[ent_env.user2_email], role=[ent_env.role1_name])
        self.assertEqual(len(TestEnterprise.expected_commands), 0)

        with self.assertLogs(level=logging.WARNING):
            cmd.execute(params, add_user=[ent_env.user2_email], verbose=True, role=['Invalid'])
            with mock.patch('builtins.print'):
github Keeper-Security / Commander / tests / test_commands.py View on Github external
def tearDownClass(cls):
        params = cls.params # type: KeeperParams
        api.query_enterprise(params)
        for user in params.enterprise['users']:
            if user['status'] == 'actove' and user['lock'] != 0:
                request = {
                    'command': 'enterprise_user_lock',
                    'enterprise_user_id': user['enterprise_user_id'],
                    'lock': 'unlocked'
                }
                api.communicate(params, request)

        cli.do_command(params, 'logout')
github Keeper-Security / Commander / unit-tests / test_command_enterprise.py View on Github external
def test_enterprise_team_user(self):
        params = get_connected_params()
        api.query_enterprise(params)

        cmd = enterprise.EnterpriseTeamCommand()

        TestEnterprise.expected_commands = ['team_enterprise_user_add']
        cmd.execute(params, add_user=[ent_env.user2_email], team=[ent_env.team1_uid])
        self.assertEqual(len(TestEnterprise.expected_commands), 0)

        TestEnterprise.expected_commands = ['team_enterprise_user_remove']
        cmd.execute(params, remove_user=[ent_env.user2_email], team=[ent_env.team1_uid])
        self.assertEqual(len(TestEnterprise.expected_commands), 0)
github Keeper-Security / Commander / unit-tests / test_command_enterprise.py View on Github external
def test_enterprise_info_command(self):
        params = get_connected_params()
        api.query_enterprise(params)

        with mock.patch('builtins.print'):
            cmd = enterprise.EnterpriseInfoCommand()
            cmd.execute(params, verbose=True)
github Keeper-Security / Commander / unit-tests / test_command_enterprise.py View on Github external
def test_enterprise_push_command(self):
        params = get_connected_params()
        api.query_enterprise(params)

        cmd = enterprise.EnterprisePushCommand()

        template_body = '''
[
    {
        "title": "Record For ${user_name}",
        "login": "${user_email}",
        "password": "${generate_password}",
        "login_url": "https://keepersecurity.com",
        "notes": "notes",
        "custom_fields": {
            "key1": "value1",
            "key2": "${user_email}"
        }
    },
github Keeper-Security / Commander / unit-tests / test_command_enterprise.py View on Github external
def test_enterprise_lock_user(self):
        params = get_connected_params()
        api.query_enterprise(params)

        cmd = enterprise.EnterpriseUserCommand()
        TestEnterprise.expected_commands = ['enterprise_user_lock', 'enterprise_user_lock']
        cmd.execute(params, unlock=True, email=[ent_env.user2_email])
        cmd.execute(params, lock=True, email=[ent_env.user2_email])
        self.assertEqual(len(TestEnterprise.expected_commands), 0)
github Keeper-Security / Commander / unit-tests / test_command_enterprise.py View on Github external
def test_enterprise_add_user(self):
        params = get_connected_params()
        api.query_enterprise(params)

        cmd = enterprise.EnterpriseUserCommand()
        TestEnterprise.expected_commands = ['enterprise_user_add']
        cmd.execute(params, add=True, email='user2@keepercommander.com')
        self.assertEqual(len(TestEnterprise.expected_commands), 0)
github Keeper-Security / Commander / unit-tests / test_command_enterprise.py View on Github external
def test_enterprise_delete_user(self):
        params = get_connected_params()
        api.query_enterprise(params)

        cmd = enterprise.EnterpriseUserCommand()
        TestEnterprise.expected_commands = ['enterprise_user_delete']
        cmd.execute(params, delete=True, force=True, email=[ent_env.user2_email])
        self.assertEqual(len(TestEnterprise.expected_commands), 0)
github Keeper-Security / Commander / keepercommander / commands / enterprise.py View on Github external
elif rk['key_type'] == 'encrypted_by_public_key':
                                            role_key = api.decrypt_rsa(rk['encrypted_key'], params.rsa_key)
                                        if role_key:
                                            need_confirm = True
                                            rq['role_admin_key'] = api.encrypt_aes(role_key, public_key)
                                        break
                        if need_confirm and not admin_confirmed:
                            answer = 'y' if kwargs.get('force') else user_choice('Do you want to grant administrative privileges to {0}'.format(user['username']), 'yn', 'n')
                            if answer == 'y':
                                admin_confirmed = True
                            else:
                                return
                        rs = api.communicate(params, rq)
                        if rs['result'] == 'success':
                            logging.info('Role %s %s %s', role_name, 'added to' if is_add else 'removed from', user['username'])
                    api.query_enterprise(params)

            elif kwargs.get('add_team') or kwargs.get('remove_team'):
                teams = {}
                for is_add in [False, True]:
                    tl = kwargs.get('add_team') if is_add else kwargs.get('remove_team')
                    if tl:
                        for t in tl:
                            team_node = None
                            if 'teams' in params.enterprise:
                                for team in params.enterprise['teams']:
                                    if t in { team['team_uid'], team['name']}:
                                        team_node = team
                                        break
                            if team_node:
                                team_uid = team_node['team_uid']
                                teams[team_uid] = is_add, team_node['name']