MCPcopy Create free account
hub / github.com/Keeper-Security/Commander / FolderMoveCommand

Class FolderMoveCommand

keepercommander/commands/folder.py:759–1012  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

757
758
759class FolderMoveCommand(Command):
760 @staticmethod
761 def get_transition_key(record, encryption_key):
762 # transition key is the key of the object being moved
763 # encrypted with the shared folder key if going to a shared folder,
764 # or encrypted with the user's data key
765 if record.get('version', -1) >= 3:
766 tkey = crypto.encrypt_aes_v2(record['record_key_unencrypted'], encryption_key)
767 else:
768 tkey = crypto.encrypt_aes_v1(record['record_key_unencrypted'], encryption_key)
769 return utils.base64_url_encode(tkey)
770
771 @staticmethod
772 def prepare_transition_keys(params, folder, keys, encryption_key):
773 for f_uid in folder.subfolders:
774 f = params.folder_cache[f_uid]
775 FolderMoveCommand.prepare_transition_keys(params, f, keys, encryption_key)
776
777 sf = params.subfolder_cache[folder.uid]
778 transition_key = utils.base64_url_encode(crypto.encrypt_aes_v1(sf['folder_key_unencrypted'], encryption_key))
779 keys.append({
780 'uid': folder.uid,
781 'key': transition_key
782 })
783 if folder.uid in params.subfolder_record_cache:
784 for r_uid in params.subfolder_record_cache[folder.uid]:
785 rec = params.record_cache[r_uid]
786 transition_key = FolderMoveCommand.get_transition_key(rec, encryption_key)
787 keys.append({
788 'uid': r_uid,
789 'key': transition_key
790 })
791
792 def get_parser(self):
793 return mv_parser
794
795 def is_move(self):
796 return True
797
798 def execute(self, params, **kwargs):
799 src_path = kwargs['src'] if 'src' in kwargs else None
800 dst_path = kwargs['dst'] if 'dst' in kwargs else None
801
802 if not src_path or not dst_path:
803 parser = self.get_parser()
804 parser.print_help()
805 return
806
807 if dst_path in params.folder_cache:
808 dst_folder = params.folder_cache[dst_path]
809 else:
810 dst = try_resolve_path(params, dst_path)
811 if dst is None:
812 raise CommandError('mv', 'Destination path should be existing folder')
813 dst_folder, name = dst
814 if len(name) > 0:
815 raise CommandError('mv', 'Destination path should be existing folder')
816

Callers 7

executeMethod · 0.85
executeMethod · 0.85
executeMethod · 0.85
executeMethod · 0.85
register_commandsFunction · 0.85
executeMethod · 0.85

Calls

no outgoing calls