From 7d80be4c9d603f4f63130a9070fcba434816107c Mon Sep 17 00:00:00 2001 From: bennychen Date: Thu, 30 Oct 2025 22:08:05 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=89=A9=E5=B1=95=E5=B1=9E=E6=80=A7=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bk_plugin_runtime/config/__init__.py | 1 - .../bk_plugin_runtime/config/default.py | 4 +-- .../packages/apigw/__init__.py | 0 .../packages/apigw/backends.py | 31 +++++++++++++++++++ 4 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 runtime/bk-plugin-runtime/bk_plugin_runtime/packages/apigw/__init__.py create mode 100644 runtime/bk-plugin-runtime/bk_plugin_runtime/packages/apigw/backends.py diff --git a/runtime/bk-plugin-runtime/bk_plugin_runtime/config/__init__.py b/runtime/bk-plugin-runtime/bk_plugin_runtime/config/__init__.py index a074304..88070b6 100644 --- a/runtime/bk-plugin-runtime/bk_plugin_runtime/config/__init__.py +++ b/runtime/bk-plugin-runtime/bk_plugin_runtime/config/__init__.py @@ -18,7 +18,6 @@ # This will make sure the app is always imported when # Django starts so that shared_task will use this app. -import django from blueapps.core.celery import celery_app from django.utils.functional import cached_property from django.db.backends.mysql.features import DatabaseFeatures diff --git a/runtime/bk-plugin-runtime/bk_plugin_runtime/config/default.py b/runtime/bk-plugin-runtime/bk_plugin_runtime/config/default.py index 22a8f4c..ed03fe5 100644 --- a/runtime/bk-plugin-runtime/bk_plugin_runtime/config/default.py +++ b/runtime/bk-plugin-runtime/bk_plugin_runtime/config/default.py @@ -77,8 +77,8 @@ ) # 用户认证 -AUTHENTICATION_BACKENDS += ( - "apigw_manager.apigw.authentication.UserModelBackend", +AUTHENTICATION_BACKENDS += ( # noqa + "bk_plugin_runtime.packages.apigw.backends.APIGWUserModelBackend", ) # 所有环境的日志级别可以在这里配置 diff --git a/runtime/bk-plugin-runtime/bk_plugin_runtime/packages/apigw/__init__.py b/runtime/bk-plugin-runtime/bk_plugin_runtime/packages/apigw/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/runtime/bk-plugin-runtime/bk_plugin_runtime/packages/apigw/backends.py b/runtime/bk-plugin-runtime/bk_plugin_runtime/packages/apigw/backends.py new file mode 100644 index 0000000..98769b9 --- /dev/null +++ b/runtime/bk-plugin-runtime/bk_plugin_runtime/packages/apigw/backends.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +""" +Tencent is pleased to support the open source community by making 蓝鲸智云 - PaaS平台 (BlueKing - PaaS System) available. +Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. +Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. +You may obtain a copy of the License at +http://opensource.org/licenses/MIT +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on +an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. +""" + +from apigw_manager.apigw.authentication import UserModelBackend +from django.contrib.auth import get_user_model + +USER_MODEL = get_user_model() + + +class APIGWUserModelBackend(UserModelBackend): + """ + APIGW User Backend + """ + + def make_user(self, username: str): + if not username: + return None + user, _ = USER_MODEL.objects.get_or_create(username=username) + return user + + def authenticate(self, request, gateway_name, bk_username, verified, **credentials): + return self.make_user(bk_username)