| QUEUE_MONITOR_ALERT_EMAILS= | QUEUE_MONITOR_ALERT_EMAILS= | ||||
| # Monitor interval in minutes, default is 30 minutes | # Monitor interval in minutes, default is 30 minutes | ||||
| QUEUE_MONITOR_INTERVAL=30 | QUEUE_MONITOR_INTERVAL=30 | ||||
| # Swagger UI configuration | |||||
| SWAGGER_UI_ENABLED=true | |||||
| SWAGGER_UI_PATH=/swagger-ui.html |
| from typing import Annotated, Literal, Optional | |||||
| from typing import Literal, Optional | |||||
| from pydantic import ( | from pydantic import ( | ||||
| AliasChoices, | AliasChoices, | ||||
| ) | ) | ||||
| class SwaggerUIConfig(BaseSettings): | |||||
| SWAGGER_UI_ENABLED: bool = Field( | |||||
| description="Whether to enable Swagger UI in api module", | |||||
| default=True, | |||||
| ) | |||||
| SWAGGER_UI_PATH: str = Field( | |||||
| description="Swagger UI page path in api module", | |||||
| default="/swagger-ui.html", | |||||
| ) | |||||
| class FeatureConfig( | class FeatureConfig( | ||||
| # place the configs in alphabet order | # place the configs in alphabet order | ||||
| AppExecutionConfig, | AppExecutionConfig, | ||||
| WorkspaceConfig, | WorkspaceConfig, | ||||
| LoginConfig, | LoginConfig, | ||||
| AccountConfig, | AccountConfig, | ||||
| SwaggerUIConfig, | |||||
| # hosted services config | # hosted services config | ||||
| HostedServiceConfig, | HostedServiceConfig, | ||||
| CeleryBeatConfig, | CeleryBeatConfig, |
| def load_user_from_request(request_from_flask_login): | def load_user_from_request(request_from_flask_login): | ||||
| """Load user based on the request.""" | """Load user based on the request.""" | ||||
| # Skip authentication for documentation endpoints | # Skip authentication for documentation endpoints | ||||
| if request.path.endswith("/docs") or request.path.endswith("/swagger.json"): | |||||
| if dify_config.SWAGGER_UI_ENABLED and request.path.endswith((dify_config.SWAGGER_UI_PATH, "/swagger.json")): | |||||
| return None | return None | ||||
| auth_header = request.headers.get("Authorization", "") | auth_header = request.headers.get("Authorization", "") |
| from collections.abc import Mapping | from collections.abc import Mapping | ||||
| from typing import Any | from typing import Any | ||||
| from flask import current_app, got_request_exception | |||||
| from flask import Blueprint, Flask, current_app, got_request_exception | |||||
| from flask_restx import Api | from flask_restx import Api | ||||
| from werkzeug.exceptions import HTTPException | from werkzeug.exceptions import HTTPException | ||||
| from werkzeug.http import HTTP_STATUS_CODES | from werkzeug.http import HTTP_STATUS_CODES | ||||
| from configs import dify_config | |||||
| from core.errors.error import AppInvokeQuotaExceededError | from core.errors.error import AppInvokeQuotaExceededError | ||||
| } | } | ||||
| } | } | ||||
| def __init__(self, *args, **kwargs): | |||||
| def __init__(self, app: Blueprint | Flask, *args, **kwargs): | |||||
| kwargs.setdefault("authorizations", self._authorizations) | kwargs.setdefault("authorizations", self._authorizations) | ||||
| kwargs.setdefault("security", "Bearer") | kwargs.setdefault("security", "Bearer") | ||||
| super().__init__(*args, **kwargs) | |||||
| kwargs["add_specs"] = dify_config.SWAGGER_UI_ENABLED | |||||
| kwargs["doc"] = dify_config.SWAGGER_UI_PATH if dify_config.SWAGGER_UI_ENABLED else False | |||||
| # manual separate call on construction and init_app to ensure configs in kwargs effective | |||||
| super().__init__(app=None, *args, **kwargs) # type: ignore | |||||
| self.init_app(app, **kwargs) | |||||
| register_external_error_handlers(self) | register_external_error_handlers(self) |
| # Monitor interval in minutes, default is 30 minutes | # Monitor interval in minutes, default is 30 minutes | ||||
| QUEUE_MONITOR_INTERVAL=30 | QUEUE_MONITOR_INTERVAL=30 | ||||
| # Swagger UI configuration | |||||
| SWAGGER_UI_ENABLED=true | |||||
| SWAGGER_UI_PATH=/swagger-ui.html | |||||
| # Celery schedule tasks configuration | # Celery schedule tasks configuration | ||||
| ENABLE_CLEAN_EMBEDDING_CACHE_TASK=false | ENABLE_CLEAN_EMBEDDING_CACHE_TASK=false | ||||
| ENABLE_CLEAN_UNUSED_DATASETS_TASK=false | ENABLE_CLEAN_UNUSED_DATASETS_TASK=false |
| QUEUE_MONITOR_THRESHOLD: ${QUEUE_MONITOR_THRESHOLD:-200} | QUEUE_MONITOR_THRESHOLD: ${QUEUE_MONITOR_THRESHOLD:-200} | ||||
| QUEUE_MONITOR_ALERT_EMAILS: ${QUEUE_MONITOR_ALERT_EMAILS:-} | QUEUE_MONITOR_ALERT_EMAILS: ${QUEUE_MONITOR_ALERT_EMAILS:-} | ||||
| QUEUE_MONITOR_INTERVAL: ${QUEUE_MONITOR_INTERVAL:-30} | QUEUE_MONITOR_INTERVAL: ${QUEUE_MONITOR_INTERVAL:-30} | ||||
| SWAGGER_UI_ENABLED: ${SWAGGER_UI_ENABLED:-true} | |||||
| SWAGGER_UI_PATH: ${SWAGGER_UI_PATH:-/swagger-ui.html} | |||||
| ENABLE_CLEAN_EMBEDDING_CACHE_TASK: ${ENABLE_CLEAN_EMBEDDING_CACHE_TASK:-false} | ENABLE_CLEAN_EMBEDDING_CACHE_TASK: ${ENABLE_CLEAN_EMBEDDING_CACHE_TASK:-false} | ||||
| ENABLE_CLEAN_UNUSED_DATASETS_TASK: ${ENABLE_CLEAN_UNUSED_DATASETS_TASK:-false} | ENABLE_CLEAN_UNUSED_DATASETS_TASK: ${ENABLE_CLEAN_UNUSED_DATASETS_TASK:-false} | ||||
| ENABLE_CREATE_TIDB_SERVERLESS_TASK: ${ENABLE_CREATE_TIDB_SERVERLESS_TASK:-false} | ENABLE_CREATE_TIDB_SERVERLESS_TASK: ${ENABLE_CREATE_TIDB_SERVERLESS_TASK:-false} |