From fc2d7aafce93546fa277c29ae26cb3dbce3bf648 Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Thu, 16 Feb 2023 18:49:42 +0800 Subject: [PATCH] perf: push account (#9594) Co-authored-by: feng <1304903146@qq.com> --- apps/accounts/automations/base/manager.py | 4 ++-- apps/accounts/automations/change_secret/manager.py | 12 ++++++------ apps/accounts/automations/push_account/manager.py | 13 +++++++------ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/apps/accounts/automations/base/manager.py b/apps/accounts/automations/base/manager.py index 2dd91d794..4e06217b3 100644 --- a/apps/accounts/automations/base/manager.py +++ b/apps/accounts/automations/base/manager.py @@ -1,9 +1,9 @@ from copy import deepcopy -from common.utils import get_logger +from accounts.automations.methods import platform_automation_methods from accounts.const import SecretType from assets.automations.base.manager import BasePlaybookManager -from accounts.automations.methods import platform_automation_methods +from common.utils import get_logger logger = get_logger(__name__) diff --git a/apps/accounts/automations/change_secret/manager.py b/apps/accounts/automations/change_secret/manager.py index ea5641a18..971877c5f 100644 --- a/apps/accounts/automations/change_secret/manager.py +++ b/apps/accounts/automations/change_secret/manager.py @@ -1,22 +1,22 @@ import os import time -from copy import deepcopy -from openpyxl import Workbook from collections import defaultdict +from copy import deepcopy from django.conf import settings from django.utils import timezone +from openpyxl import Workbook -from users.models import User +from accounts.const import AutomationTypes, SecretType, SSHKeyStrategy, SecretStrategy from accounts.models import ChangeSecretRecord from accounts.notifications import ChangeSecretExecutionTaskMsg from accounts.serializers import ChangeSecretRecordBackUpSerializer -from accounts.const import AutomationTypes, SecretType, SSHKeyStrategy, SecretStrategy from common.utils import get_logger, lazyproperty from common.utils.file import encrypt_and_compress_zip_file from common.utils.timezone import local_now_display -from ...utils import SecretGenerator +from users.models import User from ..base.manager import AccountBasePlaybookManager +from ...utils import SecretGenerator logger = get_logger(__name__) @@ -131,7 +131,7 @@ class ChangeSecretManager(AccountBasePlaybookManager): recorder.status = 'success' recorder.date_finished = timezone.now() recorder.save() - + print('recorder.new_secret', recorder.new_secret) account = recorder.account account.secret = recorder.new_secret account.save(update_fields=['secret']) diff --git a/apps/accounts/automations/push_account/manager.py b/apps/accounts/automations/push_account/manager.py index edcb2856b..844649cc4 100644 --- a/apps/accounts/automations/push_account/manager.py +++ b/apps/accounts/automations/push_account/manager.py @@ -2,9 +2,9 @@ from copy import deepcopy from django.db.models import QuerySet -from common.utils import get_logger -from accounts.models import Account from accounts.const import AutomationTypes, SecretType +from accounts.models import Account +from common.utils import get_logger from ..base.manager import AccountBasePlaybookManager from ..change_secret.manager import ChangeSecretManager @@ -66,15 +66,15 @@ class PushAccountManager(ChangeSecretManager, AccountBasePlaybookManager): h['name'] += '_' + account.username new_secret = self.get_secret() + self.name_recorder_mapper[h['name']] = { + 'account': account, 'new_secret': new_secret, + } + private_key_path = None if self.secret_type == SecretType.SSH_KEY: private_key_path = self.generate_private_key_path(new_secret, path_dir) new_secret = self.generate_public_key(new_secret) - self.name_recorder_mapper[h['name']] = { - 'account': account, 'new_secret': new_secret, - } - h['kwargs'] = self.get_kwargs(account, new_secret) h['account'] = { 'name': account.name, @@ -92,6 +92,7 @@ class PushAccountManager(ChangeSecretManager, AccountBasePlaybookManager): account_info = self.name_recorder_mapper.get(host) if not account_info: return + print('account_info', account_info) account = account_info['account'] new_secret = account_info['new_secret'] if not account: