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)