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

Class FolderMoveCommand

keepercommander/commands/folder.py:862–1124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

860
861
862class FolderMoveCommand(Command):
863 @staticmethod
864 def get_transition_key(record, encryption_key):
865 # transition key is the key of the object being moved
866 # encrypted with the shared folder key if going to a shared folder,
867 # or encrypted with the user's data key
868 if record.get('version', -1) >= 3:
869 tkey = crypto.encrypt_aes_v2(record['record_key_unencrypted'], encryption_key)
870 else:
871 tkey = crypto.encrypt_aes_v1(record['record_key_unencrypted'], encryption_key)
872 return utils.base64_url_encode(tkey)
873
874 @staticmethod
875 def prepare_transition_keys(params, folder, keys, encryption_key):
876 for f_uid in folder.subfolders:
877 f = params.folder_cache[f_uid]
878 FolderMoveCommand.prepare_transition_keys(params, f, keys, encryption_key)
879
880 sf = params.subfolder_cache[folder.uid]
881 transition_key = utils.base64_url_encode(crypto.encrypt_aes_v1(sf['folder_key_unencrypted'], encryption_key))
882 keys.append({
883 'uid': folder.uid,
884 'key': transition_key
885 })
886 if folder.uid in params.subfolder_record_cache:
887 for r_uid in params.subfolder_record_cache[folder.uid]:
888 rec = params.record_cache[r_uid]
889 transition_key = FolderMoveCommand.get_transition_key(rec, encryption_key)
890 keys.append({
891 'uid': r_uid,
892 'key': transition_key
893 })
894
895 def get_parser(self):
896 return mv_parser
897
898 def is_move(self):
899 return True
900
901 def execute(self, params, **kwargs):
902 src_path = kwargs['src'] if 'src' in kwargs else None
903 dst_path = kwargs['dst'] if 'dst' in kwargs else None
904 error_command = 'mv' if self.is_move() else 'ln'
905
906 if not src_path or not dst_path:
907 parser = self.get_parser()
908 parser.print_help()
909 return
910
911 if dst_path in params.folder_cache:
912 dst_folder = params.folder_cache[dst_path]
913 else:
914 try:
915 dst = try_resolve_path(
916 params, dst_path, raise_on_ambiguous=True)
917 except FolderPathAmbiguousError as e:
918 raise CommandError(error_command, str(e))
919 if dst is None:

Callers 6

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

Calls

no outgoing calls