From c8e1660f7ea7ee6e285a2be5b66a5de72ac29c8e Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Tue, 21 Feb 2023 11:36:17 +0800 Subject: [PATCH] perf: windows not ssh automation (#9658) Co-authored-by: feng <1304903146@qq.com> --- apps/accounts/automations/change_secret/manager.py | 6 ++++++ apps/accounts/automations/push_account/manager.py | 5 +++++ apps/accounts/serializers/account/base.py | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/accounts/automations/change_secret/manager.py b/apps/accounts/automations/change_secret/manager.py index 971877c5f..07e10e83c 100644 --- a/apps/accounts/automations/change_secret/manager.py +++ b/apps/accounts/automations/change_secret/manager.py @@ -11,6 +11,7 @@ from accounts.const import AutomationTypes, SecretType, SSHKeyStrategy, SecretSt from accounts.models import ChangeSecretRecord from accounts.notifications import ChangeSecretExecutionTaskMsg from accounts.serializers import ChangeSecretRecordBackUpSerializer +from assets.const import HostTypes 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 @@ -91,6 +92,11 @@ class ChangeSecretManager(AccountBasePlaybookManager): inventory_hosts = [] records = [] host['secret_type'] = self.secret_type + + if asset.type == HostTypes.WINDOWS and self.secret_type == SecretType.SSH_KEY: + print(f'Windows {asset} does not support ssh key push \n') + return inventory_hosts + for account in accounts: h = deepcopy(host) h['name'] += '_' + account.username diff --git a/apps/accounts/automations/push_account/manager.py b/apps/accounts/automations/push_account/manager.py index c974106a6..eb8f1d4ac 100644 --- a/apps/accounts/automations/push_account/manager.py +++ b/apps/accounts/automations/push_account/manager.py @@ -4,6 +4,7 @@ from django.db.models import QuerySet from accounts.const import AutomationTypes, SecretType from accounts.models import Account +from assets.const import HostTypes from common.utils import get_logger from ..base.manager import AccountBasePlaybookManager from ..change_secret.manager import ChangeSecretManager @@ -61,6 +62,10 @@ class PushAccountManager(ChangeSecretManager, AccountBasePlaybookManager): inventory_hosts = [] host['secret_type'] = self.secret_type + if asset.type == HostTypes.WINDOWS and self.secret_type == SecretType.SSH_KEY: + print(f'Windows {asset} does not support ssh key push \n') + return inventory_hosts + for account in accounts: h = deepcopy(host) h['name'] += '_' + account.username diff --git a/apps/accounts/serializers/account/base.py b/apps/accounts/serializers/account/base.py index 811dc0a71..489bd794f 100644 --- a/apps/accounts/serializers/account/base.py +++ b/apps/accounts/serializers/account/base.py @@ -38,7 +38,7 @@ class AuthValidateMixin(serializers.Serializer): return secret def clean_auth_fields(self, validated_data): - secret_type = validated_data.pop('secret_type', None) + secret_type = validated_data.get('secret_type') passphrase = validated_data.get('passphrase') secret = validated_data.pop('secret', None) self.handle_secret(secret, secret_type, passphrase)