Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support MAX_API_KEYS #8473

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,6 @@ POSITION_TOOL_EXCLUDES=
POSITION_PROVIDER_PINS=
POSITION_PROVIDER_INCLUDES=
POSITION_PROVIDER_EXCLUDES=

# API keys configuration
MAX_API_KEYS=10
12 changes: 12 additions & 0 deletions api/configs/feature/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -601,6 +612,7 @@ def POSITION_TOOL_EXCLUDES_SET(self) -> set[str]:

class FeatureConfig(
# place the configs in alphabet order
APIConfig,
AppExecutionConfig,
BillingConfig,
CodeExecutionSandboxConfig,
Expand Down
3 changes: 2 additions & 1 deletion api/controllers/console/apikey.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion api/controllers/console/datasets/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
5 changes: 4 additions & 1 deletion docker/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -769,4 +769,7 @@ POSITION_TOOL_EXCLUDES=
# Example: POSITION_PROVIDER_PINS=openai,openllm
POSITION_PROVIDER_PINS=
POSITION_PROVIDER_INCLUDES=
POSITION_PROVIDER_EXCLUDES=
POSITION_PROVIDER_EXCLUDES=

# API keys configuration
MAX_API_KEYS=10
2 changes: 1 addition & 1 deletion docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down