diff --git a/archery/settings.py b/archery/settings.py index 7780d26b49..c01e6bb1b6 100644 --- a/archery/settings.py +++ b/archery/settings.py @@ -3,6 +3,7 @@ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os +from datetime import timedelta BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -32,6 +33,9 @@ 'sql', 'sql_api', 'common', + 'rest_framework', + 'django_filters', + 'drf_spectacular', ) MIDDLEWARE = ( @@ -172,6 +176,49 @@ } } +# API Framework +REST_FRAMEWORK = { + 'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema', + 'DEFAULT_RENDERER_CLASSES': ('rest_framework.renderers.JSONRenderer',), + # 鉴权 + 'DEFAULT_AUTHENTICATION_CLASSES': ( + 'rest_framework_simplejwt.authentication.JWTAuthentication', + 'rest_framework.authentication.SessionAuthentication', + ), + # 权限 + 'DEFAULT_PERMISSION_CLASSES': ('sql_api.permissions.IsInUserWhitelist',), + # 限速(anon:未认证用户 user:认证用户) + 'DEFAULT_THROTTLE_CLASSES': ( + 'rest_framework.throttling.AnonRateThrottle', + 'rest_framework.throttling.UserRateThrottle', + ), + 'DEFAULT_THROTTLE_RATES': { + 'anon': '120/min', + 'user': '600/min' + }, + # 过滤 + 'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend',), + # 分页 + 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', + 'PAGE_SIZE': 5, +} + +# Swagger UI +SPECTACULAR_SETTINGS = { + 'TITLE': 'Archery API', + 'DESCRIPTION': 'OpenAPI 3.0', + 'VERSION': '1.0.0', +} + +# API Authentication +SIMPLE_JWT = { + 'ACCESS_TOKEN_LIFETIME': timedelta(hours=4), + 'REFRESH_TOKEN_LIFETIME': timedelta(days=3), + 'ALGORITHM': 'HS256', + 'SIGNING_KEY': SECRET_KEY, + 'AUTH_HEADER_TYPES': ('Bearer',), +} + # LDAP ENABLE_LDAP = False if ENABLE_LDAP: diff --git a/common/middleware/check_login_middleware.py b/common/middleware/check_login_middleware.py index 3cf7bfbc6c..3707169e73 100644 --- a/common/middleware/check_login_middleware.py +++ b/common/middleware/check_login_middleware.py @@ -10,7 +10,7 @@ '/api/info' ] -IGNORE_URL_RE = r'/admin/\w*' +IGNORE_URL_RE = r'(/admin/\w*|/api/(v1|auth)/\w+)' class CheckLoginMiddleware(MiddlewareMixin): diff --git a/common/templates/base.html b/common/templates/base.html index b991602fce..0b37ef1288 100644 --- a/common/templates/base.html +++ b/common/templates/base.html @@ -267,6 +267,11 @@ 相关文档 {% endif %} + {% if perms.sql.menu_openapi %} +
  • + OpenAPI +
  • + {% endif %} diff --git a/common/templates/config.html b/common/templates/config.html index e1d612fe41..2fa27a38c0 100755 --- a/common/templates/config.html +++ b/common/templates/config.html @@ -809,6 +809,19 @@

    其他配置

    +
    + +
    + +
    +
    @@ -903,8 +916,9 @@
    当前审批流程: