From 2f43aeee5d9d77850881de7d8a74aaef06112966 Mon Sep 17 00:00:00 2001 From: xinwen Date: Tue, 15 Feb 2022 10:46:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Authbook=20=E4=BF=AE=E6=94=B9=E7=A7=98?= =?UTF-8?q?=E9=92=A5=E4=B8=8D=E7=94=9F=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/serializers/account.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/apps/assets/serializers/account.py b/apps/assets/serializers/account.py index 5de57474b..daa7f38f8 100644 --- a/apps/assets/serializers/account.py +++ b/apps/assets/serializers/account.py @@ -6,6 +6,7 @@ from orgs.mixins.serializers import BulkOrgResourceModelSerializer from .base import AuthSerializerMixin from .utils import validate_password_contains_left_double_curly_bracket +from common.utils.encode import ssh_pubkey_gen class AccountSerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer): @@ -40,6 +41,21 @@ class AccountSerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer): } ref_name = 'AssetAccountSerializer' + def _validate_gen_key(self, attrs): + private_key = attrs.get('private_key') + if not private_key: + return attrs + + password = attrs.get('passphrase') + username = attrs.get('username') + public_key = ssh_pubkey_gen(private_key, password=password, username=username) + attrs['public_key'] = public_key + return attrs + + def validate(self, attrs): + attrs = self._validate_gen_key(attrs) + return attrs + def get_protocols(self, v): return v.protocols.replace(' ', ', ')