From b557e264bcdfbac9c409263b00b3d8816545dead Mon Sep 17 00:00:00 2001 From: jiangweidong Date: Thu, 29 Feb 2024 15:58:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B4=A6=E5=8F=B7=E5=A4=87=E4=BB=BD?= =?UTF-8?q?=E9=80=89=E6=8B=A9SFTP=E6=9C=89=E5=A4=9A=E4=B8=AA=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E9=87=8D=E5=A4=8D=E7=BC=96=E7=A0=81password=E4=BC=9A?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E4=BB=BB=E5=8A=A1=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/accounts/automations/backup_account/handlers.py | 4 +--- apps/accounts/automations/change_secret/manager.py | 3 +-- apps/common/utils/file.py | 2 ++ 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/accounts/automations/backup_account/handlers.py b/apps/accounts/automations/backup_account/handlers.py index c47454685b28..6a00a2436467 100644 --- a/apps/accounts/automations/backup_account/handlers.py +++ b/apps/accounts/automations/backup_account/handlers.py @@ -168,9 +168,8 @@ def send_backup_mail(self, files, recipients): if not user.secret_key: attachment_list = [] else: - password = user.secret_key.encode('utf8') attachment = os.path.join(PATH, f'{plan_name}-{local_now_filename()}-{time.time()}.zip') - encrypt_and_compress_zip_file(attachment, password, files) + encrypt_and_compress_zip_file(attachment, user.secret_key, files) attachment_list = [attachment, ] AccountBackupExecutionTaskMsg(plan_name, user).publish(attachment_list) print('邮件已发送至{}({})'.format(user, user.email)) @@ -191,7 +190,6 @@ def send_backup_obj_storage(self, files, recipients, password): attachment = os.path.join(PATH, f'{plan_name}-{local_now_filename()}-{time.time()}.zip') if password: print('\033[32m>>> 使用加密密码对文件进行加密中\033[0m') - password = password.encode('utf8') encrypt_and_compress_zip_file(attachment, password, files) else: zip_files(attachment, files) diff --git a/apps/accounts/automations/change_secret/manager.py b/apps/accounts/automations/change_secret/manager.py index d85e057b529a..e4d1a0fd5abc 100644 --- a/apps/accounts/automations/change_secret/manager.py +++ b/apps/accounts/automations/change_secret/manager.py @@ -230,9 +230,8 @@ def send_recorder_mail(self, recorders, summary): for user in recipients: attachments = [] if user.secret_key: - password = user.secret_key.encode('utf8') attachment = os.path.join(path, f'{name}-{local_now_filename()}-{time.time()}.zip') - encrypt_and_compress_zip_file(attachment, password, [filename]) + encrypt_and_compress_zip_file(attachment, user.secret_key, [filename]) attachments = [attachment] ChangeSecretExecutionTaskMsg(name, user, summary).publish(attachments) os.remove(filename) diff --git a/apps/common/utils/file.py b/apps/common/utils/file.py index ac3f5868b170..19772d5d7490 100644 --- a/apps/common/utils/file.py +++ b/apps/common/utils/file.py @@ -21,6 +21,8 @@ def encrypt_and_compress_zip_file(filename, secret_password, encrypted_filenames with pyzipper.AESZipFile( filename, 'w', compression=pyzipper.ZIP_LZMA, encryption=pyzipper.WZ_AES ) as zf: + if secret_password and isinstance(secret_password, str): + secret_password = secret_password.encode('utf8') zf.setpassword(secret_password) for encrypted_filename in encrypted_filenames: with open(encrypted_filename, 'rb') as f: