From d308efc63b880cb0c737460ad8788edd1fc3a3d5 Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Wed, 8 Feb 2023 13:36:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E5=90=8E=20=E7=AB=8B=E5=8D=B3=E6=8E=A8=E9=80=81=20(#9462)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: feng <1304903146@qq.com> --- .../automations/change_secret/manager.py | 5 +++++ apps/accounts/serializers/account/account.py | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/apps/accounts/automations/change_secret/manager.py b/apps/accounts/automations/change_secret/manager.py index 41b0a4844..eb2d9d185 100644 --- a/apps/accounts/automations/change_secret/manager.py +++ b/apps/accounts/automations/change_secret/manager.py @@ -153,6 +153,11 @@ class ChangeSecretManager(AccountBasePlaybookManager): logger.error("Change secret error: ", e) def run(self, *args, **kwargs): + if self.secret_strategy == SecretStrategy.custom \ + and not self.execution.snapshot['secret']: + print('Custom secret is empty') + return + super().run(*args, **kwargs) recorders = self.name_recorder_mapper.values() recorders = list(recorders) diff --git a/apps/accounts/serializers/account/account.py b/apps/accounts/serializers/account/account.py index 454708265..97033eda9 100644 --- a/apps/accounts/serializers/account/account.py +++ b/apps/accounts/serializers/account/account.py @@ -39,11 +39,22 @@ class AccountSerializerCreateValidateMixin: attrs = super().validate(attrs) return self.set_secret(attrs) + @staticmethod + def push_account(instance, push_now): + if not push_now: + return + push_accounts_to_assets.delay([instance.id], [instance.asset_id]) + def create(self, validated_data): push_now = validated_data.pop('push_now', None) - instance = super().create(validated_data) - if push_now: - push_accounts_to_assets.delay([instance.id], [instance.asset_id]) + instance = super().create(validated_data, push_now) + self.push_account(instance, push_now) + return instance + + def update(self, instance, validated_data): + push_now = validated_data.pop('push_now', None) + instance = super().update(instance, validated_data) + self.push_account(instance, push_now) return instance