From 9e41ad076418ee012285c4bf0873bf8795ef13a4 Mon Sep 17 00:00:00 2001 From: jiangweidong Date: Thu, 24 Nov 2022 15:25:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=95=8C=E9=9D=A2=E6=B8=85=E7=A9=BA=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E7=9A=84=E7=A7=98=E9=92=A5=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/models/base.py | 2 +- apps/assets/serializers/account/account.py | 4 +++- apps/assets/serializers/base.py | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/assets/models/base.py b/apps/assets/models/base.py index 90fb384e6..3609ca270 100644 --- a/apps/assets/models/base.py +++ b/apps/assets/models/base.py @@ -83,7 +83,7 @@ class BaseAccount(JMSOrgBaseModel): @lazyproperty def public_key(self): - if self.secret_type == SecretType.SSH_KEY: + if self.secret_type == SecretType.SSH_KEY and self.private_key: return ssh_pubkey_gen(private_key=self.private_key) return None diff --git a/apps/assets/serializers/account/account.py b/apps/assets/serializers/account/account.py index cfd9a52f4..c7dad4f5b 100644 --- a/apps/assets/serializers/account/account.py +++ b/apps/assets/serializers/account/account.py @@ -72,7 +72,9 @@ class AccountSerializer(AccountSerializerCreateMixin, BaseAccountSerializer): def __init__(self, *args, data=None, **kwargs): super().__init__(*args, data=data, **kwargs) if data and 'name' not in data: - data['name'] = data.get('username') + username = data.get('username') + if username is not None: + data['name'] = username if hasattr(self, 'initial_data') and \ not getattr(self, 'initial_data', None): delattr(self, 'initial_data') diff --git a/apps/assets/serializers/base.py b/apps/assets/serializers/base.py index 18432a7e5..9641ce786 100644 --- a/apps/assets/serializers/base.py +++ b/apps/assets/serializers/base.py @@ -28,7 +28,7 @@ class AuthValidateMixin(serializers.Serializer): def validate_secret(self, secret): if not secret: - return + return '' secret_type = self.initial_secret_type if secret_type == SecretType.PASSWORD: validate_password_for_ansible(secret) @@ -44,7 +44,7 @@ class AuthValidateMixin(serializers.Serializer): def clean_auth_fields(validated_data): for field in ('secret',): value = validated_data.get(field) - if not value: + if value is None: validated_data.pop(field, None) validated_data.pop('passphrase', None)