mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-12 10:08:58 +08:00
refactor(*): Update hard-code '[__HIDDEN__]' to the constant. (#7048)
This commit is contained in:
parent
4e8f6b3603
commit
536c43257b
@ -1,2 +1 @@
|
|||||||
# TODO: Update all string in code to use this constant
|
HIDDEN_VALUE = '[__HIDDEN__]'
|
||||||
HIDDEN_VALUE = '[__HIDDEN__]'
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from flask_login import current_user
|
from flask_login import current_user
|
||||||
from flask_restful import Resource, marshal_with, reqparse
|
from flask_restful import Resource, marshal_with, reqparse
|
||||||
|
|
||||||
|
from constants import HIDDEN_VALUE
|
||||||
from controllers.console import api
|
from controllers.console import api
|
||||||
from controllers.console.setup import setup_required
|
from controllers.console.setup import setup_required
|
||||||
from controllers.console.wraps import account_initialization_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.name = args['name']
|
||||||
extension_data_from_db.api_endpoint = args['api_endpoint']
|
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']
|
extension_data_from_db.api_key = args['api_key']
|
||||||
|
|
||||||
return APIBasedExtensionService.save(extension_data_from_db)
|
return APIBasedExtensionService.save(extension_data_from_db)
|
||||||
|
@ -8,6 +8,7 @@ from typing import Optional
|
|||||||
|
|
||||||
from pydantic import BaseModel, ConfigDict
|
from pydantic import BaseModel, ConfigDict
|
||||||
|
|
||||||
|
from constants import HIDDEN_VALUE
|
||||||
from core.entities.model_entities import ModelStatus, ModelWithProviderEntity, SimpleModelProviderEntity
|
from core.entities.model_entities import ModelStatus, ModelWithProviderEntity, SimpleModelProviderEntity
|
||||||
from core.entities.provider_entities import (
|
from core.entities.provider_entities import (
|
||||||
CustomConfiguration,
|
CustomConfiguration,
|
||||||
@ -202,7 +203,7 @@ class ProviderConfiguration(BaseModel):
|
|||||||
for key, value in credentials.items():
|
for key, value in credentials.items():
|
||||||
if key in provider_credential_secret_variables:
|
if key in provider_credential_secret_variables:
|
||||||
# if send [__HIDDEN__] in secret input, it will be same as original value
|
# 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[key] = encrypter.decrypt_token(self.tenant_id, original_credentials[key])
|
||||||
|
|
||||||
credentials = model_provider_factory.provider_credentials_validate(
|
credentials = model_provider_factory.provider_credentials_validate(
|
||||||
@ -345,7 +346,7 @@ class ProviderConfiguration(BaseModel):
|
|||||||
for key, value in credentials.items():
|
for key, value in credentials.items():
|
||||||
if key in provider_credential_secret_variables:
|
if key in provider_credential_secret_variables:
|
||||||
# if send [__HIDDEN__] in secret input, it will be same as original value
|
# 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[key] = encrypter.decrypt_token(self.tenant_id, original_credentials[key])
|
||||||
|
|
||||||
credentials = model_provider_factory.model_credentials_validate(
|
credentials = model_provider_factory.model_credentials_validate(
|
||||||
|
@ -4,6 +4,7 @@ import logging
|
|||||||
from json import JSONDecodeError
|
from json import JSONDecodeError
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
|
from constants import HIDDEN_VALUE
|
||||||
from core.entities.provider_configuration import ProviderConfiguration
|
from core.entities.provider_configuration import ProviderConfiguration
|
||||||
from core.helper import encrypter
|
from core.helper import encrypter
|
||||||
from core.helper.model_provider_cache import ProviderCredentialsCache, ProviderCredentialsCacheType
|
from core.helper.model_provider_cache import ProviderCredentialsCache, ProviderCredentialsCacheType
|
||||||
@ -511,7 +512,7 @@ class ModelLoadBalancingService:
|
|||||||
for key, value in credentials.items():
|
for key, value in credentials.items():
|
||||||
if key in provider_credential_secret_variables:
|
if key in provider_credential_secret_variables:
|
||||||
# if send [__HIDDEN__] in secret input, it will be same as original value
|
# 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])
|
credentials[key] = encrypter.decrypt_token(tenant_id, original_credentials[key])
|
||||||
|
|
||||||
if validate:
|
if validate:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user