How to use the keepercommander.subfolder.BaseFolderNode 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 / keepercommander / commands / record.py View on Github external
if r.title.lower() == name.lower():
                        record_uid = uid
                        break

        if record_uid is None:
            logging.warning('Enter name of existing record')
            return

        del_obj = {
            'delete_resolution': 'unlink',
            'object_uid': record_uid,
            'object_type': 'record'
        }
        if folder.type in {BaseFolderNode.RootFolderType, BaseFolderNode.UserFolderType}:
            del_obj['from_type'] = 'user_folder'
            if folder.type == BaseFolderNode.UserFolderType:
                del_obj['from_uid'] = folder.uid
        else:
            del_obj['from_type'] = 'shared_folder_folder'
            del_obj['from_uid'] = folder.uid

        rq = {
            'command': 'pre_delete',
            'objects': [del_obj]
        }

        rs = api.communicate(params, rq)
        if rs['result'] == 'success':
            pdr = rs['pre_delete_response']

            force = kwargs['force'] if 'force' in kwargs else None
            np = 'y'
github Keeper-Security / Commander / keepercommander / importer / imp_exp.py View on Github external
}
                                if dst_folder.type != BaseFolderNode.RootFolderType:
                                    req['to_uid'] = dst_folder.uid
                                mo = {
                                    'type': 'record',
                                    'uid': rec.uid,
                                    'from_type': src_folder.type if src_folder.type != BaseFolderNode.RootFolderType else BaseFolderNode.UserFolderType,
                                    'cascade': True
                                }
                                if src_folder.type != BaseFolderNode.RootFolderType:
                                    mo['from_uid'] = src_folder.uid
                                req['move'].append(mo)

                                transition_key = None
                                record_key = record['record_key_unencrypted']
                                if src_folder.type in {BaseFolderNode.SharedFolderType, BaseFolderNode.SharedFolderFolderType}:
                                    if dst_folder.type in {BaseFolderNode.SharedFolderType, BaseFolderNode.SharedFolderFolderType}:
                                        ssf_uid = src_folder.uid if src_folder.type == BaseFolderNode.SharedFolderType else \
                                            src_folder.shared_folder_uid
                                        dsf_uid = dst_folder.uid if dst_folder.type == BaseFolderNode.SharedFolderType else \
                                            dst_folder.shared_folder_uid
                                        if ssf_uid != dsf_uid:
                                            shf = params.shared_folder_cache[dsf_uid]
                                            transition_key = api.encrypt_aes(record_key, shf['shared_folder_key_unencrypted'])
                                    else:
                                        transition_key = api.encrypt_aes(record_key, params.data_key)
                                else:
                                    if dst_folder.type in {BaseFolderNode.SharedFolderType, BaseFolderNode.SharedFolderFolderType}:
                                        dsf_uid = dst_folder.uid if dst_folder.type == BaseFolderNode.SharedFolderType else \
                                            dst_folder.shared_folder_uid
                                        shf = params.shared_folder_cache[dsf_uid]
                                        transition_key = api.encrypt_aes(record_key, shf['shared_folder_key_unencrypted'])
github Keeper-Security / Commander / keepercommander / importer / imp_exp.py View on Github external
def prepare_record_link(params, records):
    record_links = []
    for rec in records:
        if rec.folders and rec.uid:
            if rec.uid in params.record_cache:
                record = params.record_cache[rec.uid]
                folder_ids = list(find_folders(params, rec.uid))
                for fol in rec.folders:
                    if fol.uid and fol.uid in params.folder_cache:
                        if len(folder_ids) > 0:
                            if fol.uid not in folder_ids:
                                src_folder =  params.folder_cache[folder_ids[0]]
                                dst_folder = params.folder_cache[fol.uid]
                                req = {
                                    'command': 'move',
                                    'to_type': dst_folder.type if dst_folder.type != BaseFolderNode.RootFolderType else BaseFolderNode.UserFolderType,
                                    'link': True,
                                    'move': [],
                                    'transition_keys': []
                                }
                                if dst_folder.type != BaseFolderNode.RootFolderType:
                                    req['to_uid'] = dst_folder.uid
                                mo = {
                                    'type': 'record',
                                    'uid': rec.uid,
                                    'from_type': src_folder.type if src_folder.type != BaseFolderNode.RootFolderType else BaseFolderNode.UserFolderType,
                                    'cascade': True
                                }
                                if src_folder.type != BaseFolderNode.RootFolderType:
                                    mo['from_uid'] = src_folder.uid
                                req['move'].append(mo)
github Keeper-Security / Commander / keepercommander / subfolder.py View on Github external
print('{0:>20s}: {1:<20s}'.format('Folder Type', self.get_folder_type()))
        print('{0:>20s}: {1}'.format('Name', self.name))


class UserFolderNode(BaseFolderNode):
    def __init__(self):
        BaseFolderNode.__init__(self, BaseFolderNode.UserFolderType)


class SharedFolderFolderNode(BaseFolderNode):
    def __init__(self):
        BaseFolderNode.__init__(self, BaseFolderNode.SharedFolderFolderType)
        self.shared_folder_uid = None


class SharedFolderNode(BaseFolderNode):
    def __init__(self):
        BaseFolderNode.__init__(self, BaseFolderNode.SharedFolderType)


class RootFolderNode(BaseFolderNode):
    def __init__(self):
        BaseFolderNode.__init__(self, BaseFolderNode.RootFolderType)
        self.name = 'My Vault'
github Keeper-Security / Commander / keepercommander / commands / folder.py View on Github external
}
                if 'shared_folder_key' not in sf:
                    if 'teams' in sf:
                        for team in sf['teams']:
                            rq['from_team_uid'] = team['team_uid']
                            break

                np = 'y' if force else user_choice('Do you want to proceed with deletion?', 'yn', default='n')
                if np.lower() == 'y':
                    api.communicate(params, rq)
                    params.sync_data = True
        else:
            del_obj = {
                'delete_resolution': 'unlink',
                'object_uid': folder.uid,
                'object_type': 'user_folder' if folder.type == BaseFolderNode.UserFolderType else 'shared_folder_folder'
            }
            if parent is None:
                del_obj['from_type'] = 'user_folder'
            else:
                del_obj['from_uid'] = parent.uid
                del_obj['from_type'] = parent.type
                if parent.type == BaseFolderNode.SharedFolderType:
                    del_obj['from_type'] = 'shared_folder_folder'

            rq = {
                'command': 'pre_delete',
                'objects': [del_obj]
            }

            rs = api.communicate(params, rq)
            if rs['result'] == 'success':
github Keeper-Security / Commander / keepercommander / subfolder.py View on Github external
elif self.type == BaseFolderNode.UserFolderType:
            return 'Regular Folder'
        elif self.type == BaseFolderNode.SharedFolderType:
            return 'Shared Folder'
        elif self.type == BaseFolderNode.SharedFolderFolderType:
            return 'Subfolder in Shared Folder'
        return ''

    def display(self, **kwargs):
        print('')
        print('{0:>20s}: {1:<20s}'.format('Folder UID', self.uid))
        print('{0:>20s}: {1:<20s}'.format('Folder Type', self.get_folder_type()))
        print('{0:>20s}: {1}'.format('Name', self.name))


class UserFolderNode(BaseFolderNode):
    def __init__(self):
        BaseFolderNode.__init__(self, BaseFolderNode.UserFolderType)


class SharedFolderFolderNode(BaseFolderNode):
    def __init__(self):
        BaseFolderNode.__init__(self, BaseFolderNode.SharedFolderFolderType)
        self.shared_folder_uid = None


class SharedFolderNode(BaseFolderNode):
    def __init__(self):
        BaseFolderNode.__init__(self, BaseFolderNode.SharedFolderType)


class RootFolderNode(BaseFolderNode):
github Keeper-Security / Commander / keepercommander / commands / register.py View on Github external
if has_record_share_permissions:
                                            if change_edit:
                                                cmd['editable'] = should_have
                                            if change_share:
                                                cmd['shareable'] = should_have
                                            direct_shares_update.append(cmd)
                                        else:
                                            direct_shares_skip.append(cmd)

        # shared folder record permissions
        shared_folder_update = {}  # dict
        shared_folder_skip = {}

        if share_folder:
            for folder in flat_subfolders:
                if folder.type not in {BaseFolderNode.SharedFolderType, BaseFolderNode.SharedFolderFolderType}:
                    continue
                uids.clear()
                if folder.uid in params.subfolder_record_cache:
                    uids.update(params.subfolder_record_cache[folder.uid])

                shared_folder_uid = folder.uid
                if type(folder) == SharedFolderFolderNode:
                    shared_folder_uid = folder.shared_folder_uid
                if shared_folder_uid in params.shared_folder_cache:
                    shared_folder = params.shared_folder_cache[shared_folder_uid]
                    team_uid = None
                    has_manage_records_permission = False
                    if 'shared_folder_key' in shared_folder:
                        has_manage_records_permission = shared_folder.get('manage_records') or False
                    if not has_manage_records_permission:
                        if 'teams' in shared_folder:
github Keeper-Security / Commander / keepercommander / commands / folder.py View on Github external
name = kwargs['folder'] if 'folder' in kwargs else None
        if name:
            rs = try_resolve_path(params, name)
            if rs is not None:
                base_folder, name = rs
                if len(name) == 0:
                    logging.warning('Folder "%s" already exists', name)
                    return

        shared_folder = kwargs['shared_folder'] if 'shared_folder' in kwargs else None
        user_folder = kwargs['user_folder'] if 'user_folder' in kwargs else None

        request = {"command": "folder_add"}
        if shared_folder:
            if base_folder.type in {BaseFolderNode.RootFolderType, BaseFolderNode.UserFolderType}:
                request['folder_type'] = 'shared_folder'
                grant = kwargs['grant'] if 'grant' in kwargs else None
                for flag in ['manage_users', 'manage_records', 'can_share', 'can_edit']:
                    if grant or (flag in kwargs and kwargs[flag]):
                        request[flag] = True
            else:
                logging.error('Shared folders cannot be nested')
                return

        elif user_folder:
            if base_folder.type in {BaseFolderNode.SharedFolderType, BaseFolderNode.SharedFolderFolderType}:
                request['folder_type'] = 'shared_folder_folder'
            else:
                request['folder_type'] = 'user_folder'

        if request.get('folder_type') is None:
github Keeper-Security / Commander / keepercommander / importer / imp_exp.py View on Github external
record = params.record_cache[rec.uid]
                folder_ids = list(find_folders(params, rec.uid))
                for fol in rec.folders:
                    if fol.uid and fol.uid in params.folder_cache:
                        if len(folder_ids) > 0:
                            if fol.uid not in folder_ids:
                                src_folder =  params.folder_cache[folder_ids[0]]
                                dst_folder = params.folder_cache[fol.uid]
                                req = {
                                    'command': 'move',
                                    'to_type': dst_folder.type if dst_folder.type != BaseFolderNode.RootFolderType else BaseFolderNode.UserFolderType,
                                    'link': True,
                                    'move': [],
                                    'transition_keys': []
                                }
                                if dst_folder.type != BaseFolderNode.RootFolderType:
                                    req['to_uid'] = dst_folder.uid
                                mo = {
                                    'type': 'record',
                                    'uid': rec.uid,
                                    'from_type': src_folder.type if src_folder.type != BaseFolderNode.RootFolderType else BaseFolderNode.UserFolderType,
                                    'cascade': True
                                }
                                if src_folder.type != BaseFolderNode.RootFolderType:
                                    mo['from_uid'] = src_folder.uid
                                req['move'].append(mo)

                                transition_key = None
                                record_key = record['record_key_unencrypted']
                                if src_folder.type in {BaseFolderNode.SharedFolderType, BaseFolderNode.SharedFolderFolderType}:
                                    if dst_folder.type in {BaseFolderNode.SharedFolderType, BaseFolderNode.SharedFolderFolderType}:
                                        ssf_uid = src_folder.uid if src_folder.type == BaseFolderNode.SharedFolderType else \
github Keeper-Security / Commander / keepercommander / importer / imp_exp.py View on Github external
def prepare_shared_folder_add(params, folders):
    folder_hash = {}
    for f_uid in params.folder_cache:
        fol = params.folder_cache[f_uid]
        h = hashlib.md5()
        hs = '{0}|{1}'.format((fol.name or '').lower(), fol.parent_uid or '')
        h.update(hs.encode())
        shared_folder_key = None
        if fol.type in { BaseFolderNode.SharedFolderType, BaseFolderNode.SharedFolderFolderType}:
            sf_uid = fol.shared_folder_uid if fol.type == BaseFolderNode.SharedFolderFolderType else fol.uid
            if sf_uid in params.shared_folder_cache:
                shared_folder_key = params.shared_folder_cache[sf_uid]['shared_folder_key_unencrypted']
        folder_hash[h.hexdigest()] = f_uid, fol.type, shared_folder_key

    # public keys
    emails = {}
    for fol in folders:
        if fol.permissions:
            for perm in fol.permissions:
                if perm.name not in emails:
                    _, email = parseaddr(perm.name)
                    if email:
                        if email != params.user:
                            emails[email.lower()] = None
    if emails: