Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions runtime/bk-plugin-runtime/bk_plugin_runtime/config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@
)

# 用户认证
AUTHENTICATION_BACKENDS += (
"apigw_manager.apigw.authentication.UserModelBackend",
AUTHENTICATION_BACKENDS += ( # noqa
"bk_plugin_runtime.packages.apigw.backends.APIGWUserModelBackend",
)

# 所有环境的日志级别可以在这里配置
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -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)