| # TODO: Update all string in code to use this constant | |||||
| HIDDEN_VALUE = '[__HIDDEN__]' | |||||
| HIDDEN_VALUE = '[__HIDDEN__]' |
| 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 | ||||
| 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) |
| 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, | ||||
| 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( | ||||
| 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( |
| 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 | ||||
| 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: |