From 06b9193cb35cf68abe4b8a47f0398bfd05bb4ac3 Mon Sep 17 00:00:00 2001 From: jiayuan929 <252461528@qq.com> Date: Thu, 12 Dec 2024 17:44:29 +0800 Subject: [PATCH] fix: mypy --- sdks/bkpaas-auth/bkpaas_auth/core/encoder.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/sdks/bkpaas-auth/bkpaas_auth/core/encoder.py b/sdks/bkpaas-auth/bkpaas_auth/core/encoder.py index 8b66450..4765014 100644 --- a/sdks/bkpaas-auth/bkpaas_auth/core/encoder.py +++ b/sdks/bkpaas-auth/bkpaas_auth/core/encoder.py @@ -33,20 +33,16 @@ def decode(self, user_id: Union[str, bytes]) -> Tuple[int, str]: :param str user_id: BK user id :returns: (provider_type, username) """ - # Ensure user_id is of type bytes for consistent handling - if isinstance(user_id, str): - user_id = ensure_binary(user_id) - # Check if the user ID is unencrypted - if user_id.startswith(self.unencrypted_user_flag): + if user_id[:2] == self.unencrypted_user_flag: user_info = user_id[2:] - _provider_type, decoded_username = user_info[:2].decode(), user_info[2:].decode() + _provider_type, _decoded_username = user_info[:2], user_info[2:] else: # Handle encrypted user ID _provider_type, encrypted_username = user_id[:2], user_id[2:] - decoded = ARC4(ensure_binary(self.secret_key)).decrypt(binascii.unhexlify(encrypted_username)) - decoded_username = ensure_text(decoded) + _decoded_username = ARC4(ensure_binary(self.secret_key)).decrypt(binascii.unhexlify(encrypted_username)) + decoded_username = ensure_text(_decoded_username) provider_type = int(_provider_type) return provider_type, decoded_username