From c318762f82b8833fdbaef0159f4ca06b32803d8f Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 15 Jul 2021 19:11:53 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BF=AE=E6=94=B9account=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/models/authbook.py | 1 - apps/assets/models/user.py | 1 + apps/assets/serializers/account.py | 4 ++++ apps/assets/tasks/account_connectivity.py | 1 + 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/assets/models/authbook.py b/apps/assets/models/authbook.py index b3b8bbbdc..3153608cd 100644 --- a/apps/assets/models/authbook.py +++ b/apps/assets/models/authbook.py @@ -27,7 +27,6 @@ class AuthBook(BaseUser, AbsConnectivity): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.auth_snapshot = {} - self.load_auth() def get_or_systemuser_attr(self, attr): val = getattr(self, attr, None) diff --git a/apps/assets/models/user.py b/apps/assets/models/user.py index 3f8849188..914db0db9 100644 --- a/apps/assets/models/user.py +++ b/apps/assets/models/user.py @@ -141,6 +141,7 @@ class AuthMixin: else: authbooks.sort(key=lambda x: 1 if x.username == username else 0, reverse=True) authbook = authbooks[0] + authbook.load_auth() self.password = authbook.password self.private_key = authbook.private_key self.public_key = authbook.public_key diff --git a/apps/assets/serializers/account.py b/apps/assets/serializers/account.py index 55a7d53ae..8b18e7e33 100644 --- a/apps/assets/serializers/account.py +++ b/apps/assets/serializers/account.py @@ -32,6 +32,10 @@ class AccountSerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer): queryset = queryset.prefetch_related('systemuser', 'asset') return queryset + def to_representation(self, instance): + instance.load_auth() + return super().to_representation(instance) + class AccountSecretSerializer(AccountSerializer): class Meta(AccountSerializer.Meta): diff --git a/apps/assets/tasks/account_connectivity.py b/apps/assets/tasks/account_connectivity.py index 3d8591b06..4327c0ffe 100644 --- a/apps/assets/tasks/account_connectivity.py +++ b/apps/assets/tasks/account_connectivity.py @@ -81,6 +81,7 @@ def test_account_connectivity_util(account, task_name): if not check_asset_can_run_ansible(account.asset): return + account.load_auth() try: raw, summary = test_user_connectivity( task_name=task_name, asset=account.asset,