Browse Source

fix: 账号备份密码如 t08\x08fIE 备份失败

pull/12447/head
feng 11 months ago committed by Bryan
parent
commit
219fad9b62
  1. 11
      apps/accounts/automations/backup_account/handlers.py
  2. 9
      apps/accounts/automations/change_secret/manager.py
  3. 18
      poetry.lock
  4. 1
      pyproject.toml

11
apps/accounts/automations/backup_account/handlers.py

@ -3,13 +3,13 @@ import time
from collections import defaultdict, OrderedDict
from django.conf import settings
from openpyxl import Workbook
from rest_framework import serializers
from xlsxwriter import Workbook
from accounts.const.automation import AccountBackupType
from accounts.models.automations.backup_account import AccountBackupAutomation
from accounts.notifications import AccountBackupExecutionTaskMsg, AccountBackupByObjStorageExecutionTaskMsg
from accounts.serializers import AccountSecretSerializer
from accounts.models.automations.backup_account import AccountBackupAutomation
from assets.const import AllTypes
from common.utils.file import encrypt_and_compress_zip_file, zip_files
from common.utils.timezone import local_now_filename, local_now_display
@ -144,10 +144,11 @@ class AccountBackupHandler:
wb = Workbook(filename)
for sheet, data in data_map.items():
ws = wb.create_sheet(str(sheet))
ws = wb.add_worksheet(str(sheet))
for row in data:
ws.append(row)
wb.save(filename)
for col, _data in enumerate(row):
ws.write_string(0, col, _data)
wb.close()
files.append(filename)
timedelta = round((time.time() - time_start), 2)
print('创建备份文件完成: 用时 {}s'.format(timedelta))

9
apps/accounts/automations/change_secret/manager.py

@ -4,7 +4,7 @@ from copy import deepcopy
from django.conf import settings
from django.utils import timezone
from openpyxl import Workbook
from xlsxwriter import Workbook
from accounts.const import AutomationTypes, SecretType, SSHKeyStrategy, SecretStrategy
from accounts.models import ChangeSecretRecord
@ -227,8 +227,9 @@ class ChangeSecretManager(AccountBasePlaybookManager):
rows.insert(0, header)
wb = Workbook(filename)
ws = wb.create_sheet('Sheet1')
ws = wb.add_worksheet('Sheet1')
for row in rows:
ws.append(row)
wb.save(filename)
for col, data in enumerate(row):
ws.write_string(0, col, data)
wb.close()
return True

18
poetry.lock

@ -7540,6 +7540,22 @@ type = "legacy"
url = "https://pypi.tuna.tsinghua.edu.cn/simple"
reference = "tsinghua"
[[package]]
name = "xlsxwriter"
version = "3.1.9"
description = "A Python module for creating Excel XLSX files."
optional = false
python-versions = ">=3.6"
files = [
{file = "XlsxWriter-3.1.9-py3-none-any.whl", hash = "sha256:b61c1a0c786f82644936c0936ec96ee96cd3afb9440094232f7faef9b38689f0"},
{file = "XlsxWriter-3.1.9.tar.gz", hash = "sha256:de810bf328c6a4550f4ffd6b0b34972aeb7ffcf40f3d285a0413734f9b63a929"},
]
[package.source]
type = "legacy"
url = "https://pypi.tuna.tsinghua.edu.cn/simple"
reference = "tsinghua"
[[package]]
name = "xmlsec"
version = "1.3.13"
@ -7755,4 +7771,4 @@ reference = "tsinghua"
[metadata]
lock-version = "2.0"
python-versions = "^3.11"
content-hash = "397cb294c81da3ce74f1a1c3044bd778669284c0c280177162ed9d51e623a7c8"
content-hash = "19950a5300f8a4425e3e3c9a096fc3782cb544e02152e92ac1bc09d1d9b5274a"

1
pyproject.toml

@ -145,6 +145,7 @@ user-agents = "^2.2.0"
django-cors-headers = "^4.3.0"
mistune = "0.8.4"
openai = "^1.3.7"
xlsxwriter = "^3.1.9"
[tool.poetry.group.xpack.dependencies]

Loading…
Cancel
Save