diff --git a/apps/assets/models/base.py b/apps/assets/models/base.py index 30eafa6b7..3ecfd4deb 100644 --- a/apps/assets/models/base.py +++ b/apps/assets/models/base.py @@ -91,6 +91,8 @@ class BaseAccount(JMSOrgBaseModel): @property def ssh_key_fingerprint(self): + # Todo: 等待修复 + return '等待修复' if self.public_key: public_key = self.public_key elif self.private_key: diff --git a/apps/common/utils/encode.py b/apps/common/utils/encode.py index b06d96a3d..81856b931 100644 --- a/apps/common/utils/encode.py +++ b/apps/common/utils/encode.py @@ -165,8 +165,10 @@ def parse_ssh_public_key_str(text: bytes = "", password=None) -> str: private_key = _parse_ssh_private_key(text, password=password) if private_key is None: return "" - public_key_bytes = private_key.public_key().public_bytes(serialization.Encoding.OpenSSH, - serialization.PublicFormat.OpenSSH) + public_key_bytes = private_key.public_key().public_bytes( + serialization.Encoding.OpenSSH, + serialization.PublicFormat.OpenSSH, + ) return public_key_bytes.decode('utf-8') @@ -185,12 +187,11 @@ def _parse_ssh_private_key(text, password=None): text = text.encode("utf-8") except UnicodeDecodeError: return None - if password is not None: - if isinstance(password, str): - try: - password = password.encode("utf-8") - except UnicodeDecodeError: - return None + if isinstance(password, str): + try: + password = password.encode("utf-8") + except UnicodeDecodeError: + return None try: private_key = serialization.load_ssh_private_key(text, password=password)