How to use the keepercommander.subfolder.try_resolve_path 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
def execute(self, params, **kwargs):
        name = kwargs['record'] if 'record' in kwargs else None

        if not name:
            self.get_parser().print_help()
            return

        record_uid = None
        if name in params.record_cache:
            record_uid = name
        else:
            rs = try_resolve_path(params, name)
            if rs is not None:
                folder, name = rs
                if folder is not None and name is not None:
                    folder_uid = folder.uid or ''
                    if folder_uid in params.subfolder_record_cache:
                        for uid in params.subfolder_record_cache[folder_uid]:
                            r = api.get_record(params, uid)
                            if r.title.lower() == name.lower():
                                record_uid = uid
                                break

        if record_uid is None:
            logging.warning('Enter name or uid of existing record')
            return
        record = api.get_record(params, record_uid)
github Keeper-Security / Commander / keepercommander / commands / folder.py View on Github external
def execute(self, params, **kwargs):
        folder = None
        name = kwargs['folder'] if 'folder' in kwargs else None
        if name:
            if name in params.folder_cache:
                folder = params.folder_cache[name]
            else:
                rs = try_resolve_path(params, name)
                if rs is not None:
                    folder, name = rs
                    if len(name or '') > 0:
                        folder = None
                    elif folder.type == BaseFolderNode.RootFolderType:
                        folder = None

        if folder is None:
            logging.warning('Enter name of the existing folder')
            return

        force = kwargs['force'] if 'force' in kwargs else None
        parent = params.folder_cache[folder.uid] if folder.uid is not None else None
        if folder.type == BaseFolderNode.SharedFolderType:
            if folder.uid in params.shared_folder_cache:
                sf = params.shared_folder_cache[folder.uid]
github Keeper-Security / Commander / keepercommander / commands / register.py View on Github external
def execute(self, params, **kwargs):
        folder_name = kwargs['folder'] if 'folder' in kwargs else ''
        folder_uid = None
        if folder_name:
            if folder_name in params.folder_cache:
                folder_uid = folder_name
            else:
                rs = try_resolve_path(params, folder_name)
                if rs is not None:
                    folder, pattern = rs
                    if len(pattern) == 0:
                        folder_uid = folder.uid
                    else:
                        logging.warning('Folder %s not found', folder_name)
                        return

        if folder_uid:
            folder = params.folder_cache[folder_uid]  # type: BaseFolderNode or SharedFolderFolderNode
        else:
            folder = params.root_folder

        share_record = kwargs.get('share_record') or False
        share_folder = kwargs.get('share_folder') or False
        if not share_record and not share_folder:
github Keeper-Security / Commander / keepercommander / commands / folder.py View on Github external
if src_folder_uid in params.subfolder_record_cache:
                    for uid in params.subfolder_record_cache[src_folder_uid]:
                        rec = api.get_record(params, uid)
                        if name in {rec.title, rec.record_uid}:
                            src_record_uid = rec.record_uid
                            break

                if src_record_uid is None:
                    logging.warning('Record "%s" not found', name)
                    return

        dst_folder = None
        if dst_path in params.folder_cache:
            dst_folder = params.folder_cache[dst_path]
        else:
            dst = try_resolve_path(params, dst_path)
            if dst is None:
                logging.warning('Destination path should be existing folder')
                return
            dst_folder, name = dst
            if len(name) > 0:
                logging.warning('Destination path should be existing folder')
                return

        rq = {
            'command': 'move',
            'link': not self.is_move(),
            'move': []
        }
        if dst_folder.type == BaseFolderNode.RootFolderType:
            rq['to_type'] = BaseFolderNode.UserFolderType
        else:
github Keeper-Security / Commander / keepercommander / commands / folder.py View on Github external
def execute(self, params, **kwargs):
        folder_name = kwargs['folder'] if 'folder' in kwargs else ''
        if folder_name:
            if folder_name in params.folder_cache:
                params.current_folder = folder_name
            else:
                rs = try_resolve_path(params, folder_name)
                if rs is not None:
                    folder, pattern = rs
                    if len(pattern) == 0:
                        params.current_folder = folder.uid
                    else:
                        logging.warning('cd: Folder %s not found', folder_name)
github Keeper-Security / Commander / keepercommander / commands / folder.py View on Github external
def execute(self, params, **kwargs):
        show_folders = kwargs['folders'] if 'folders' in kwargs else None
        show_records = kwargs['records'] if 'records' in kwargs else None
        show_detail = kwargs['detail'] if 'detail' in kwargs else False
        if not show_folders and not show_records:
            show_folders = True
            show_records = True

        folder = params.folder_cache[params.current_folder] if params.current_folder in params.folder_cache else params.root_folder
        pattern = kwargs['pattern'] if 'pattern' in kwargs else None
        if pattern:
            rs = try_resolve_path(params, kwargs['pattern'])
            if rs is not None:
                folder, pattern = rs

        regex = None
        if pattern:
            regex = re.compile(fnmatch.translate(pattern)).match

        folders = []
        records = []

        if show_folders:
            for uid in folder.subfolders:
                f = params.folder_cache[uid]
                if any(filter(lambda x: regex(x) is not None, FolderListCommand.folder_match_strings(f))) if regex is not None else True:
                    folders.append(f)
github Keeper-Security / Commander / keepercommander / commands / register.py View on Github external
def execute(self, params, **kwargs):
        folder = None
        name = kwargs.get('folder')
        if name:
            if name in params.folder_cache:
                folder = params.folder_cache[name]
            else:
                rs = try_resolve_path(params, name)
                if rs is not None:
                    folder, name = rs
                    if len(name or '') > 0:
                        folder = None
                    elif folder.type == BaseFolderNode.RootFolderType:
                        folder = None

        if folder is None:
            logging.error('Enter name of the existing folder')
            return

        if folder.type not in {BaseFolderNode.SharedFolderType, BaseFolderNode.SharedFolderFolderType}:
            logging.error('You can change permission of shared folders only')
            return

        shared_folder_uid = folder.shared_folder_uid if folder.type == BaseFolderNode.SharedFolderFolderType else folder.uid
github Keeper-Security / Commander / keepercommander / commands / record.py View on Github external
def execute(self, params, **kwargs):
        record_name = kwargs['record'] if 'record' in kwargs else None

        if not record_name:
            self.get_parser().print_help()
            return

        user_pattern = None
        if kwargs['username']:
            user_pattern = re.compile(kwargs['username'].lower())

        record_uid = None
        if record_name in params.record_cache:
            record_uid = record_name
        else:
            rs = try_resolve_path(params, record_name)
            if rs is not None:
                folder, record_name = rs
                if folder is not None and record_name is not None:
                    folder_uid = folder.uid or ''
                    if folder_uid in params.subfolder_record_cache:
                        for uid in params.subfolder_record_cache[folder_uid]:
                            r = api.get_record(params, uid)
                            if r.title.lower() == record_name.lower():
                                if user_pattern:
                                    if not user_pattern.match(r.login):
                                        continue
                                record_uid = uid
                                break

        if record_uid is None:
            records = api.search_records(params, kwargs['record'])
github Keeper-Security / Commander / keepercommander / commands / folder.py View on Github external
if src_path in params.record_cache:
            src_record_uid = src_path
            if '' in params.subfolder_record_cache:
                if src_record_uid in params.subfolder_record_cache['']:
                    src_folder = params.root_folder
            if src_folder is None:
                for folder_uid in find_folders(params, src_record_uid):
                    src_folder = params.folder_cache[folder_uid]
                    break
            if src_folder is None:
                src_folder = params.root_folder
        elif src_path in params.folder_cache:
            src_folder = params.folder_cache[src_path]
        else:
            src = try_resolve_path(params, src_path)
            if src is None:
                logging.warning('Source path should be existing record or folder')
                return

            src_folder, name = src
            if len(name) > 0:
                src_folder_uid = src_folder.uid or ''
                if src_folder_uid in params.subfolder_record_cache:
                    for uid in params.subfolder_record_cache[src_folder_uid]:
                        rec = api.get_record(params, uid)
                        if name in {rec.title, rec.record_uid}:
                            src_record_uid = rec.record_uid
                            break

                if src_record_uid is None:
                    logging.warning('Record "%s" not found', name)
github Keeper-Security / Commander / keepercommander / commands / register.py View on Github external
team_keys[team_uid] = api.decrypt_rsa(tk['key'], params.rsa_key)
                                elif tk['type'] == 3:
                                    team_keys[team_uid] = base64.urlsafe_b64decode(tk['key'] + '==')

            record_uids = []
            default_record = False
            if 'record' in kwargs:
                records = kwargs.get('record') or []
                for r in records:
                    if r == '*':
                        default_record = True
                    elif r in params.record_cache:
                        record_uids.append(r)
                    else:
                        r_uid = None
                        rs = try_resolve_path(params, r)
                        if rs is not None:
                            sf, name = rs
                            if name:
                                shared_folder_uid = sf.uid or ''
                                if shared_folder_uid in params.subfolder_record_cache:
                                    for uid in params.subfolder_record_cache[shared_folder_uid]:
                                        rec = api.get_record(params, uid)
                                        if name in {rec.title, rec.record_uid}:
                                            r_uid = rec.record_uid
                                            break
                        if r_uid:
                            record_uids.append(r_uid)
                        else:
                            logging.error('\'%s\' is not an existing record title or UID', r)

            request = {