perf: push account (#9594)

Co-authored-by: feng <1304903146@qq.com>
pull/9595/head
fit2bot 2 years ago committed by GitHub
parent 1298cc0a91
commit fc2d7aafce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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__)

@ -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'])

@ -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:

Loading…
Cancel
Save