Преглед изворни кода

refactor(*): Update hard-code '[__HIDDEN__]' to the constant. (#7048)

-LAN- пре 8 месеци
родитељ
комит
536c43257b

+ 1 - 2
api/constants/__init__.py

@@ -1,2 +1 @@
-# TODO: Update all string in code to use this constant
-HIDDEN_VALUE = '[__HIDDEN__]'
+HIDDEN_VALUE = '[__HIDDEN__]'

+ 2 - 1
api/controllers/console/extension.py

@@ -1,6 +1,7 @@
 from flask_login import current_user
 from flask_restful import Resource, marshal_with, reqparse
 
+from constants import HIDDEN_VALUE
 from controllers.console import api
 from controllers.console.setup import setup_required
 from controllers.console.wraps import account_initialization_required
@@ -89,7 +90,7 @@ class APIBasedExtensionDetailAPI(Resource):
         extension_data_from_db.name = args['name']
         extension_data_from_db.api_endpoint = args['api_endpoint']
 
-        if args['api_key'] != '[__HIDDEN__]':
+        if args['api_key'] != HIDDEN_VALUE:
             extension_data_from_db.api_key = args['api_key']
 
         return APIBasedExtensionService.save(extension_data_from_db)

+ 3 - 2
api/core/entities/provider_configuration.py

@@ -8,6 +8,7 @@ from typing import Optional
 
 from pydantic import BaseModel, ConfigDict
 
+from constants import HIDDEN_VALUE
 from core.entities.model_entities import ModelStatus, ModelWithProviderEntity, SimpleModelProviderEntity
 from core.entities.provider_entities import (
     CustomConfiguration,
@@ -202,7 +203,7 @@ class ProviderConfiguration(BaseModel):
             for key, value in credentials.items():
                 if key in provider_credential_secret_variables:
                     # if send [__HIDDEN__] in secret input, it will be same as original value
-                    if value == '[__HIDDEN__]' and key in original_credentials:
+                    if value == HIDDEN_VALUE and key in original_credentials:
                         credentials[key] = encrypter.decrypt_token(self.tenant_id, original_credentials[key])
 
         credentials = model_provider_factory.provider_credentials_validate(
@@ -345,7 +346,7 @@ class ProviderConfiguration(BaseModel):
             for key, value in credentials.items():
                 if key in provider_credential_secret_variables:
                     # if send [__HIDDEN__] in secret input, it will be same as original value
-                    if value == '[__HIDDEN__]' and key in original_credentials:
+                    if value == HIDDEN_VALUE and key in original_credentials:
                         credentials[key] = encrypter.decrypt_token(self.tenant_id, original_credentials[key])
 
         credentials = model_provider_factory.model_credentials_validate(

+ 2 - 1
api/services/model_load_balancing_service.py

@@ -4,6 +4,7 @@ import logging
 from json import JSONDecodeError
 from typing import Optional
 
+from constants import HIDDEN_VALUE
 from core.entities.provider_configuration import ProviderConfiguration
 from core.helper import encrypter
 from core.helper.model_provider_cache import ProviderCredentialsCache, ProviderCredentialsCacheType
@@ -511,7 +512,7 @@ class ModelLoadBalancingService:
             for key, value in credentials.items():
                 if key in provider_credential_secret_variables:
                     # if send [__HIDDEN__] in secret input, it will be same as original value
-                    if value == '[__HIDDEN__]' and key in original_credentials:
+                    if value == HIDDEN_VALUE and key in original_credentials:
                         credentials[key] = encrypter.decrypt_token(tenant_id, original_credentials[key])
 
         if validate: