How to use the keepercommander.api.communicate 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 / tests / test_commands.py View on Github external
def wipe_out_data(cls):
        params = cls.params # type: KeeperParams
        managed_roles = set()
        for mn in params.enterprise['managed_nodes']:
            managed_roles.add(mn['role_id'])

        for ru in params.enterprise['role_users']:
            if ru['role_id'] not in managed_roles:
                request = {
                    'command': 'role_user_remove',
                    'role_id': ru['role_id'],
                    'enterprise_user_id': ru['enterprise_user_id']
                }
                api.communicate(params, request)

        for user in params.enterprise['users']:
            if user['username'] in ['integration.enterprise@keepersecurity.com', 'integration.tests@keepersecurity.com']:
                if user['lock'] != 0:
                    request = {
                        'command': 'enterprise_user_lock',
                        'enterprise_user_id': user['enterprise_user_id'],
                        'lock': 'unlocked'
                    }
                    api.communicate(params, request)
            else:
                request = {
                    'command': 'enterprise_user_delete',
                    'enterprise_user_id': user['enterprise_user_id']
                }
                api.communicate(params, request)
github Keeper-Security / Commander / tests / test_commands.py View on Github external
'object_type': 'user_folder',
                        'delete_resolution': 'unlink'
                    } for x in folder_uids
                ]
            }
            rs = api.communicate(params, request)
            request = {
                'command': 'delete',
                'pre_delete_token': rs['pre_delete_response']['pre_delete_token']
            }
            rs = api.communicate(params, request)

        request = {
            'command': 'purge_deleted_records'
        }
        rs = api.communicate(params, request)
        params.revision = 0
        api.sync_down(params)
github Keeper-Security / Commander / keepercommander / importer / imp_exp.py View on Github external
uploads = None

        file_no = 0
        file_size = 0
        for _, att in chunk:
            file_no += 1
            file_size += att.size or 0

        #TODO check storage subscription
        rq = {
            'command': 'request_upload',
            'file_count': file_no
        }
        try:
            rs = api.communicate(params, rq)
            if rs['result'] == 'success':
                uploads = rs['file_uploads']
        except Exception as e:
            print(e)
            return

        uploaded = {}
        for record_id, atta in chunk:
            if not uploads:
                break

            try:
                upload = uploads.pop()
                buffer = io.BytesIO()
                cipher = None
                key = atta.key
github Keeper-Security / Commander / keepercommander / commands / register.py View on Github external
name = kwargs.get('name')
            if name:
                data['displayname'] = name
            else:
                logging.error('\'name\' parameter is required for enterprise users')
                return
            rq = {
                'command': 'enterprise_user_add',
                'enterprise_user_id': EnterpriseCommand.get_enterprise_id(params),
                'enterprise_user_username': email,
                'encrypted_data': api.encrypt_aes(json.dumps(data).encode('utf-8'), params.enterprise['unencrypted_tree_key']),
                'node_id': node_id,
                'suppress_email_invite': True
            }
            try:
                rs = api.communicate(params, rq)
                if rs['result'] == 'success':
                    verification_code = rs.get('verification_code')
                    # re-read password rules
                    rq = {
                        'command': 'pre_register',
                        'email': email
                    }
                    rs = api.run_command(params, rq)
                    if 'password_rules' in rs:
                        password_rules = rs['password_rules']
            except:
                pass

        password = kwargs['password'] if 'password' in kwargs else None
        generate = kwargs['generate'] if 'generate' in kwargs else None
        if generate:
github Keeper-Security / Commander / keepercommander / commands / register.py View on Github external
share_action = 'update_records'
                            else:
                                share_action = 'remove_records'
                    else:
                        if action == 'grant':
                            ro['can_edit'] = ce
                            ro['can_share'] = cs
                            rec = params.record_cache[record_uid]
                            ro['record_key'] = api.encrypt_aes(rec['record_key_unencrypted'], sh_fol['shared_folder_key_unencrypted'])
                            share_action = 'add_records'

                    if share_action:
                        if not share_action in request:
                            request[share_action] = []
                        request[share_action].append(ro)
            response = api.communicate(params, request)
            params.sync_data = True

            for node in ['add_teams', 'update_teams', 'remove_teams']:
                if node in response:
                    for t in response[node]:
                        team = api.get_team(params, t['team_uid'])
                        if t['status'] == 'success':
                            logging.warning('Team share \'%s\' %s', team.name, 'added' if node == 'add_teams' else 'updated' if node == 'update_teams' else 'removed')
                        else:
                            logging.error('Team share \'%s\' failed', team.name)

            for node in ['add_users', 'update_users', 'remove_users']:
                if node in response:
                    for s in response[node]:
                        if s['status'] == 'success':
                            logging.warning('User share \'%s\' %s', s['username'], 'added' if node == 'add_users' else 'updated' if node == 'update_users' else 'removed')
github Keeper-Security / Commander / keepercommander / importer / commands.py View on Github external
def open(self):
        rq = {
            'command': 'request_download',
            'file_ids': [self.file_id],
        }
        api.resolve_record_access_path(self.params, self.record_uid, path=rq)

        rs = api.communicate(self.params, rq)
        if rs['result'] == 'success':
            dl = rs['downloads'][0]
            if 'url' in dl:
                with requests.get(dl['url'], stream=True) as rq_http:
                    yield rq_http.raw
github Keeper-Security / Commander / keepercommander / commands / utils.py View on Github external
def execute(self, params, **kwargs):
        uc = user_choice('Are you sure you want to delete all Keeper records on the server?', 'yn', default='n')
        if uc.lower() == 'y':
            api.sync_down(params)
            if len(params.record_cache) == 0:
                logging.warning('No records to delete')
                return

            request = {
                'command': 'record_update',
                'delete_records': [key for key in params.record_cache.keys()]
            }
            logging.info('removing %s records from Keeper', len(params.record_cache))
            response_json = api.communicate(params, request)
            success = [info for info in response_json['delete_records'] if info['status'] == 'success']
            if len(success) > 0:
                logging.info("%s records deleted successfully", len(success))
            failures = [info for info in response_json['delete_records'] if info['status'] != 'success']
            if len(failures) > 0:
                logging.warning("%s records failed to delete", len(failures))

            params.revision = 0
            params.sync_data = True
github Keeper-Security / Commander / keepercommander / commands / record.py View on Github external
if rs['result'] == 'success':
            pdr = rs['pre_delete_response']

            force = kwargs['force'] if 'force' in kwargs else None
            np = 'y'
            if not force:
                summary = pdr['would_delete']['deletion_summary']
                for x in summary:
                    print(x)
                np = user_choice('Do you want to proceed with deletion?', 'yn', default='n')
            if np.lower() == 'y':
                rq = {
                    'command': 'delete',
                    'pre_delete_token': pdr['pre_delete_token']
                }
                api.communicate(params, rq)
                params.sync_data = True