diff --git a/apps/assets/models/base.py b/apps/assets/models/base.py index 70c6b54e6..59c135847 100644 --- a/apps/assets/models/base.py +++ b/apps/assets/models/base.py @@ -86,8 +86,8 @@ class BaseAccount(JMSOrgBaseModel): @lazyproperty def public_key(self): - if self.secret_type == SecretType.SSH_KEY: - return parse_ssh_public_key_str(self.private_key) + if self.secret_type == SecretType.SSH_KEY and self.private_key: + return parse_ssh_public_key_str(private_key=self.private_key) return None @property 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)