diff --git a/api/.env.example b/api/.env.example index a3db406aeabdc..cdc91945ef041 100644 --- a/api/.env.example +++ b/api/.env.example @@ -290,3 +290,6 @@ POSITION_TOOL_EXCLUDES= POSITION_PROVIDER_PINS= POSITION_PROVIDER_INCLUDES= POSITION_PROVIDER_EXCLUDES= + +# API keys configuration +MAX_API_KEYS=10 \ No newline at end of file diff --git a/api/configs/feature/__init__.py b/api/configs/feature/__init__.py index f794552c36d26..fa36e9ebfe791 100644 --- a/api/configs/feature/__init__.py +++ b/api/configs/feature/__init__.py @@ -266,6 +266,17 @@ class InnerAPIConfig(BaseSettings): ) +class APIConfig(BaseSettings): + """ + API configs + """ + + MAX_API_KEYS: PositiveInt = Field( + description="The maximum number of API keys that can be created", + default=10, + ) + + class LoggingConfig(BaseSettings): """ Logging configs @@ -601,6 +612,7 @@ def POSITION_TOOL_EXCLUDES_SET(self) -> set[str]: class FeatureConfig( # place the configs in alphabet order + APIConfig, AppExecutionConfig, BillingConfig, CodeExecutionSandboxConfig, diff --git a/api/controllers/console/apikey.py b/api/controllers/console/apikey.py index 35ac42a14cbfe..41fe97993257e 100644 --- a/api/controllers/console/apikey.py +++ b/api/controllers/console/apikey.py @@ -3,6 +3,7 @@ from flask_restful import Resource, fields, marshal_with from werkzeug.exceptions import Forbidden +from configs import dify_config from extensions.ext_database import db from libs.helper import TimestampField from libs.login import login_required @@ -40,7 +41,7 @@ class BaseApiKeyListResource(Resource): resource_model = None resource_id_field = None token_prefix = None - max_keys = 10 + max_keys = dify_config.MAX_API_KEYS @marshal_with(api_key_list) def get(self, resource_id): diff --git a/api/controllers/console/datasets/datasets.py b/api/controllers/console/datasets/datasets.py index 2c4e5ac60789e..967b303760f65 100644 --- a/api/controllers/console/datasets/datasets.py +++ b/api/controllers/console/datasets/datasets.py @@ -465,7 +465,7 @@ def get(self, dataset_id): class DatasetApiKeyApi(Resource): - max_keys = 10 + max_keys = dify_config.MAX_API_KEYS token_prefix = "dataset-" resource_type = "dataset" diff --git a/docker/.env.example b/docker/.env.example index c892c15636e69..0efce64671a16 100644 --- a/docker/.env.example +++ b/docker/.env.example @@ -769,4 +769,7 @@ POSITION_TOOL_EXCLUDES= # Example: POSITION_PROVIDER_PINS=openai,openllm POSITION_PROVIDER_PINS= POSITION_PROVIDER_INCLUDES= -POSITION_PROVIDER_EXCLUDES= \ No newline at end of file +POSITION_PROVIDER_EXCLUDES= + +# API keys configuration +MAX_API_KEYS=10 \ No newline at end of file diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index 0fbc695177626..69857f88ccb3e 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -204,7 +204,7 @@ x-shared-env: &shared-api-worker-env CODE_MAX_NUMBER_ARRAY_LENGTH: ${CODE_MAX_NUMBER_ARRAY_LENGTH:-1000} SSRF_PROXY_HTTP_URL: ${SSRF_PROXY_HTTP_URL:-http://ssrf_proxy:3128} SSRF_PROXY_HTTPS_URL: ${SSRF_PROXY_HTTPS_URL:-http://ssrf_proxy:3128} - + MAX_API_KEYS: ${MAX_API_KEYS:-10} services: # API service api: