From 8506ae9edd8faad3e3dc2872563588ea4c140928 Mon Sep 17 00:00:00 2001 From: feng <1304903146@qq.com> Date: Tue, 30 Jul 2024 18:30:49 +0800 Subject: [PATCH] perf: When account push change secret windows only modify the type equal to password --- apps/accounts/automations/change_secret/manager.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/accounts/automations/change_secret/manager.py b/apps/accounts/automations/change_secret/manager.py index b5a978b79..024282d82 100644 --- a/apps/accounts/automations/change_secret/manager.py +++ b/apps/accounts/automations/change_secret/manager.py @@ -8,7 +8,7 @@ from django.utils.translation import gettext_lazy as _ from xlsxwriter import Workbook from accounts.const import AutomationTypes, SecretType, SSHKeyStrategy, SecretStrategy, ChangeSecretRecordStatusChoice -from accounts.models import ChangeSecretRecord +from accounts.models import ChangeSecretRecord, BaseAccountQuerySet from accounts.notifications import ChangeSecretExecutionTaskMsg, ChangeSecretFailedMsg from accounts.serializers import ChangeSecretRecordBackUpSerializer from assets.const import HostTypes @@ -68,10 +68,10 @@ class ChangeSecretManager(AccountBasePlaybookManager): else: return self.secret_generator(secret_type).get_secret() - def get_accounts(self, privilege_account): + def get_accounts(self, privilege_account) -> BaseAccountQuerySet | None: if not privilege_account: - print(f'not privilege account') - return [] + print('Not privilege account') + return asset = privilege_account.asset accounts = asset.accounts.all() @@ -108,6 +108,9 @@ class ChangeSecretManager(AccountBasePlaybookManager): print(f'Windows {asset} does not support ssh key push') return inventory_hosts + if asset.type == HostTypes.WINDOWS: + accounts = accounts.filter(secret_type=SecretType.PASSWORD) + host['ssh_params'] = {} for account in accounts: h = deepcopy(host)