Skip to content

Commit

Permalink
fix: 账号备份选择SFTP有多个时,重复编码password会导致任务异常
Browse files Browse the repository at this point in the history
  • Loading branch information
O-Jiangweidong authored and BaiJiangJie committed Feb 29, 2024
1 parent 457d2b2 commit b557e26
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
4 changes: 1 addition & 3 deletions apps/accounts/automations/backup_account/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions apps/accounts/automations/change_secret/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions apps/common/utils/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b557e26

Please sign in to comment.