From 516dae578eef0174c019996cb59832166ee5fa31 Mon Sep 17 00:00:00 2001 From: jamesgetx Date: Fri, 20 Dec 2024 15:32:25 +0800 Subject: [PATCH] refactor: minor N --- sdks/bkpaas-auth/CHANGES.md | 2 +- sdks/bkpaas-auth/README.md | 4 ++-- sdks/bkpaas-auth/bkpaas_auth/__init__.py | 2 +- sdks/bkpaas-auth/bkpaas_auth/core/http.py | 4 ++-- sdks/bkpaas-auth/bkpaas_auth/core/token.py | 1 + sdks/bkpaas-auth/pyproject.toml | 2 +- sdks/bkpaas-auth/setup.py | 2 +- 7 files changed, 9 insertions(+), 8 deletions(-) diff --git a/sdks/bkpaas-auth/CHANGES.md b/sdks/bkpaas-auth/CHANGES.md index 7b3b8cb..6ca74b6 100644 --- a/sdks/bkpaas-auth/CHANGES.md +++ b/sdks/bkpaas-auth/CHANGES.md @@ -1,6 +1,6 @@ # 版本历史 -## 3.0.1 +## 3.1.0 - feat: UniversalAuthBackend 支持获取用户租户身份信息 ## 3.0.0 diff --git a/sdks/bkpaas-auth/README.md b/sdks/bkpaas-auth/README.md index 46ff928..7e76b97 100644 --- a/sdks/bkpaas-auth/README.md +++ b/sdks/bkpaas-auth/README.md @@ -69,7 +69,7 @@ BKAUTH_ENABLE_MULTI_TENANT_MODE = True BKAUTH_BACKEND_TYPE = "bk_token" # 只能选择:bk_token # 验证用户信息的网关 API(租户版本) -# 如 https://{网关域名}/api/bk-login/prod/login/api/v3/open/bk-tokens/userinfo/ +# 如 BK_API_URL_TMPL.format(api_name="bk-login") + "/prod/login/api/v3/open/bk-tokens/userinfo/" BKAUTH_USER_INFO_APIGW_URL = "" # [可选]`BKAUTH_DEFAULT_PROVIDER_TYPE` 的值用于 JWT 校验时获取默认的用户认证类型。 @@ -147,7 +147,7 @@ class YourDjangoAuthUserCompatibleBackend(DjangoAuthUserCompatibleBackend): return db_user ``` -> 说明: 启用多租户模式后, user 会增加 tenant_id 字段,可以通过 `request.user.tenant_id` 获取租户 ID +> 说明: 启用多租户模式后, user 会增加 tenant_id 和 display_name 两个字段,可以通过 `request.user.tenant_id` 获取租户 ID, 通过 `request.user.display_name` 获取用户展示名。 #### 和 [apigw-manager](../apigw-manager) 集成 该 SDK 可以和 apigw-manager 集成,完成网关 JWT 的校验,在 settings 中配置: diff --git a/sdks/bkpaas-auth/bkpaas_auth/__init__.py b/sdks/bkpaas-auth/bkpaas_auth/__init__.py index 123d5e5..ac7af52 100644 --- a/sdks/bkpaas-auth/bkpaas_auth/__init__.py +++ b/sdks/bkpaas-auth/bkpaas_auth/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -__version__ = "3.0.1" +__version__ = "3.1.0" def get_user_by_user_id(user_id: str, username_only: bool = True): diff --git a/sdks/bkpaas-auth/bkpaas_auth/core/http.py b/sdks/bkpaas-auth/bkpaas_auth/core/http.py index 290f3d4..07037d9 100644 --- a/sdks/bkpaas-auth/bkpaas_auth/core/http.py +++ b/sdks/bkpaas-auth/bkpaas_auth/core/http.py @@ -14,7 +14,7 @@ import requests from bkpaas_auth.conf import bkauth_settings -from bkpaas_auth.core.exceptions import HttpRequestError, ResponseError +from bkpaas_auth.core.exceptions import HttpRequestError, ServiceError from bkpaas_auth.utils import scrub_data logger = logging.getLogger(__name__) @@ -69,7 +69,7 @@ def resp_to_json(resp: requests.Response) -> Union[dict, list]: resp.status_code, resp.text, ) - raise ResponseError("parse response error") + raise ServiceError("parse json response error") def http_get(url: str, **kwargs) -> requests.Response: diff --git a/sdks/bkpaas-auth/bkpaas_auth/core/token.py b/sdks/bkpaas-auth/bkpaas_auth/core/token.py index e0e2f74..5ad8adf 100644 --- a/sdks/bkpaas-auth/bkpaas_auth/core/token.py +++ b/sdks/bkpaas-auth/bkpaas_auth/core/token.py @@ -80,6 +80,7 @@ def _request_apigw(**credentials) -> UserAccount: headers={ 'blueking-language': get_language(), "X-Bkapi-Authorization": json.dumps(get_app_credentials()), + "X-Bk-Tenant-Id": "default", }, params=credentials, ) diff --git a/sdks/bkpaas-auth/pyproject.toml b/sdks/bkpaas-auth/pyproject.toml index ea94dfd..cd3e773 100644 --- a/sdks/bkpaas-auth/pyproject.toml +++ b/sdks/bkpaas-auth/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "bkpaas-auth" -version = "3.0.1" +version = "3.1.0" description = "User authentication django app for blueking internal projects" readme = "README.md" authors = ["blueking "] diff --git a/sdks/bkpaas-auth/setup.py b/sdks/bkpaas-auth/setup.py index d200e71..9fd5b9e 100644 --- a/sdks/bkpaas-auth/setup.py +++ b/sdks/bkpaas-auth/setup.py @@ -23,7 +23,7 @@ setup( long_description=readme, name='bkpaas-auth', - version='3.0.1', + version='3.1.0', description='User authentication django app for blueking internal projects', python_requires='<4.0,>=3.8', author='blueking',