Skip to content

Commit 0b6fb8e

Browse files
bennychendengyh
authored andcommitted
fix: 修复获取用户扩展属性异常的问题
1 parent 07cc5c4 commit 0b6fb8e

4 files changed

Lines changed: 33 additions & 3 deletions

File tree

runtime/bk-plugin-runtime/bk_plugin_runtime/config/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
# This will make sure the app is always imported when
2020
# Django starts so that shared_task will use this app.
21-
import django
2221
from blueapps.core.celery import celery_app
2322
from django.utils.functional import cached_property
2423
from django.db.backends.mysql.features import DatabaseFeatures

runtime/bk-plugin-runtime/bk_plugin_runtime/config/default.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@
7777
)
7878

7979
# 用户认证
80-
AUTHENTICATION_BACKENDS += (
81-
"apigw_manager.apigw.authentication.UserModelBackend",
80+
AUTHENTICATION_BACKENDS += ( # noqa
81+
"bk_plugin_runtime.packages.apigw.backends.APIGWUserModelBackend",
8282
)
8383

8484
# 所有环境的日志级别可以在这里配置

runtime/bk-plugin-runtime/bk_plugin_runtime/packages/apigw/__init__.py

Whitespace-only changes.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Tencent is pleased to support the open source community by making 蓝鲸智云 - PaaS平台 (BlueKing - PaaS System) available.
4+
Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved.
5+
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
http://opensource.org/licenses/MIT
8+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
9+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
10+
specific language governing permissions and limitations under the License.
11+
"""
12+
13+
from apigw_manager.apigw.authentication import UserModelBackend
14+
from django.contrib.auth import get_user_model
15+
16+
USER_MODEL = get_user_model()
17+
18+
19+
class APIGWUserModelBackend(UserModelBackend):
20+
"""
21+
APIGW User Backend
22+
"""
23+
24+
def make_user(self, username: str):
25+
if not username:
26+
return None
27+
user, _ = USER_MODEL.objects.get_or_create(username=username)
28+
return user
29+
30+
def authenticate(self, request, gateway_name, bk_username, verified, **credentials):
31+
return self.make_user(bk_username)

0 commit comments

Comments
 (0)