From c1e7193c4b3f38290038f2e53d3ba65923461d52 Mon Sep 17 00:00:00 2001 From: Garfield Dai Date: Mon, 6 Nov 2023 23:07:30 +0800 Subject: [PATCH] feat: hidden api key enhancement. (#1468) --- api/fields/api_based_extension_fields.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/api/fields/api_based_extension_fields.py b/api/fields/api_based_extension_fields.py index f6a60ff02e..749e9900de 100644 --- a/api/fields/api_based_extension_fields.py +++ b/api/fields/api_based_extension_fields.py @@ -5,7 +5,13 @@ from libs.helper import TimestampField class HiddenAPIKey(fields.Raw): def output(self, key, obj): - return obj.api_key[:3] + '***' + obj.api_key[-3:] + api_key = obj.api_key + # If the length of the api_key is less than 8 characters, show the first and last characters + if len(api_key) <= 8: + return api_key[0] + '******' + api_key[-1] + # If the api_key is greater than 8 characters, show the first three and the last three characters + else: + return api_key[:3] + '******' + api_key[-3:] api_based_extension_fields = {