Skip to content

Commit

Permalink
refactor(router): modify v1 prefix to v3 (#1903)
Browse files Browse the repository at this point in the history
  • Loading branch information
nannan00 authored Aug 26, 2024
1 parent f2c2c87 commit 63769e1
Show file tree
Hide file tree
Showing 16 changed files with 123 additions and 122 deletions.
13 changes: 7 additions & 6 deletions src/bk-login/bklogin/component/bk_user/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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.
"""

import logging
from typing import Any, Callable, Dict, List

Expand Down Expand Up @@ -56,7 +57,7 @@ def _call_bk_user_api_20x(http_func, url_path: str, **kwargs):

def get_global_setting() -> GlobalSetting:
"""查询全局配置"""
data = _call_bk_user_api_20x(http_get, "/api/v1/login/global-settings/")
data = _call_bk_user_api_20x(http_get, "/api/v3/login/global-settings/")
return GlobalSetting(**data)


Expand All @@ -66,35 +67,35 @@ def list_tenant(tenant_ids: List[str] | None = None) -> List[TenantInfo]:
if tenant_ids:
params["tenant_ids"] = ",".join(tenant_ids)

data = _call_bk_user_api_20x(http_get, "/api/v1/login/tenants/", params=params)
data = _call_bk_user_api_20x(http_get, "/api/v3/login/tenants/", params=params)
return [TenantInfo(**i) for i in data]


def list_idp(tenant_id: str, idp_owner_tenant_id: str) -> List[IdpInfo]:
"""获取租户关联的认证源"""
data = _call_bk_user_api_20x(
http_get, f"/api/v1/login/tenants/{tenant_id}/idp-owner-tenants/{idp_owner_tenant_id}/idps/"
http_get, f"/api/v3/login/tenants/{tenant_id}/idp-owner-tenants/{idp_owner_tenant_id}/idps/"
)
return [IdpInfo(**i) for i in data]


def get_idp(idp_id: str) -> IdpDetail:
"""获取IDP信息"""
data = _call_bk_user_api_20x(http_get, f"/api/v1/login/idps/{idp_id}/")
data = _call_bk_user_api_20x(http_get, f"/api/v3/login/idps/{idp_id}/")
return IdpDetail(**data)


def list_matched_tencent_user(tenant_id: str, idp_id: str, idp_users: List[Dict[str, Any]]) -> List[TenantUserInfo]:
"""根据IDP用户查询匹配的租户用户"""
data = _call_bk_user_api_20x(
http_post,
f"/api/v1/login/tenants/{tenant_id}/idps/{idp_id}/matched-tenant-users/",
f"/api/v3/login/tenants/{tenant_id}/idps/{idp_id}/matched-tenant-users/",
json={"idp_users": idp_users},
)
return [TenantUserInfo(**i) for i in data]


def get_tenant_user(tenant_user_id: str) -> TenantUserDetailInfo:
"""通过租户用户ID获取租户用户信息"""
data = _call_bk_user_api_20x(http_get, f"/api/v1/login/tenant-users/{tenant_user_id}/")
data = _call_bk_user_api_20x(http_get, f"/api/v3/login/tenant-users/{tenant_user_id}/")
return TenantUserDetailInfo(**data)
12 changes: 6 additions & 6 deletions src/bk-user/bkuser/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@

urlpatterns = [
# 产品功能API
path("api/v1/web/", include("bkuser.apis.web.urls")),
path("api/v3/web/", include("bkuser.apis.web.urls")),
# 提供给登录服务使用的内部 API
path("api/v1/login/", include("bkuser.apis.login.urls")),
# 兼容旧版本(v2)用户管理 OpenAPI
# Q: 这里使用 api/v2 而非 api/v2/open,
path("api/v3/login/", include("bkuser.apis.login.urls")),
# 兼容旧版本用户管理 OpenAPI
# Q: 这里使用 api/v1、api/v2 而非 api/v1/open、api/v2/open
# A: 为了保证 ESB 调用的兼容,只需修改 ESB 配置 bk_user host,不需要依赖 ESB 的版本发布
path("api/v1/", include("bkuser.apis.open_v1.urls")),
path("api/v2/", include("bkuser.apis.open_v2.urls")),
# 用于监控相关的,比如ping/healthz/sentry/metrics/otel等等
path("api/v1/", include("bkuser.apis.open_v1.urls")),
path("", include("bkuser.monitoring.urls")),
]

# 蓝鲸通知中心
if settings.ENABLE_BK_NOTICE:
urlpatterns += [
path("api/v1/web/notices/", include(("bk_notice_sdk.urls", "notice"), namespace="notice")),
path("api/v3/web/notices/", include(("bk_notice_sdk.urls", "notice"), namespace="notice")),
]

# swagger doc
Expand Down
2 changes: 1 addition & 1 deletion src/idp-plugins/idp_plugins/local/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def auth_credentials_of_local_user(
"""
resp_data = self._call(
http_post,
"/api/v1/login/local-user-credentials/authenticate/",
"/api/v3/login/local-user-credentials/authenticate/",
json={"data_source_ids": data_source_ids, "username": username, "password": password},
)

Expand Down
4 changes: 2 additions & 2 deletions src/pages/src/components/import-dialog/import-dialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ const handleUploadRemove = (file) => {
};
// 数据源导出模板
const handleExportTemplate = () => {
const url = `${window.AJAX_BASE_URL}/api/v1/web/data-sources/${props.currentDataSourceId}/operations/download_template/`;
const url = `${window.AJAX_BASE_URL}/api/v3/web/data-sources/${props.currentDataSourceId}/operations/download_template/`;
window.open(url);
};
// 导入用户
Expand All @@ -162,7 +162,7 @@ const confirmImportUsers = async () => {
},
withCredentials: true,
};
const url = `${window.AJAX_BASE_URL}/api/v1/web/data-sources/${props.currentDataSourceId}/operations/import/`;
const url = `${window.AJAX_BASE_URL}/api/v3/web/data-sources/${props.currentDataSourceId}/operations/import/`;
const res = await axios.post(url, formData, config);
if (res.data.data.status === 'success') {
emit('update:isShow', false);
Expand Down
4 changes: 2 additions & 2 deletions src/pages/src/http/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import http from './fetch';

export const currentUser = () => http.get('/api/v1/web/basic/current-user/');
export const currentUser = () => http.get('/api/v3/web/basic/current-user/');

// 版本日志列表
export const getVersionLogs = () => http.get('/api/v1/web/version-logs/');
export const getVersionLogs = () => http.get('/api/v3/web/version-logs/');
20 changes: 10 additions & 10 deletions src/pages/src/http/authSourceFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,49 @@ import type {
/**
* 认证源列表
*/
export const getIdps = (keyword: string) => http.get(`/api/v1/web/idps/?keyword=${keyword}`);
export const getIdps = (keyword: string) => http.get(`/api/v3/web/idps/?keyword=${keyword}`);

/**
* 认证源插件列表
*/
export const getIdpsPlugins = () => http.get('/api/v1/web/idps/plugins/');
export const getIdpsPlugins = () => http.get('/api/v3/web/idps/plugins/');

/**
* 新建认证源
*/
export const postIdps = (params: NewIdpsParams) => http.post('/api/v1/web/idps/', params);
export const postIdps = (params: NewIdpsParams) => http.post('/api/v3/web/idps/', params);

/**
* 认证源详情
*/
export const getIdpsDetails = (id: string) => http.get(`/api/v1/web/idps/${id}/`);
export const getIdpsDetails = (id: string) => http.get(`/api/v3/web/idps/${id}/`);

/**
* 更新认证源部分字段(local)
*/
export const patchIdps = (params: PatchIdpsParams) => http.patch(`/api/v1/web/idps/${params.id}/`, params);
export const patchIdps = (params: PatchIdpsParams) => http.patch(`/api/v3/web/idps/${params.id}/`, params);

/**
* 更新认证源
*/
export const putIdps = (params: PutIdpsParams) => http.put(`/api/v1/web/idps/${params.id}/`, params);
export const putIdps = (params: PutIdpsParams) => http.put(`/api/v3/web/idps/${params.id}/`, params);

/**
* 认证源插件默认配置
*/
export const getIdpsPluginsConfig = (id: string) => http.get(`/api/v1/web/idps/plugins/${id}/config-meta/`);
export const getIdpsPluginsConfig = (id: string) => http.get(`/api/v3/web/idps/plugins/${id}/config-meta/`);

/**
* 新建本地账密认证源
*/
export const postLocalIdps = (params: NewLocalIdpsParams) => http.post('/api/v1/web/idps/local/', params);
export const postLocalIdps = (params: NewLocalIdpsParams) => http.post('/api/v3/web/idps/local/', params);

/**
* 本地认证源详情
*/
export const getLocalIdps = (id: string) => http.get(`/api/v1/web/idps/local/${id}/`);
export const getLocalIdps = (id: string) => http.get(`/api/v3/web/idps/local/${id}/`);

/**
* 更新本地认证源
*/
export const putLocalIdps = (params: NewLocalIdpsParams) => http.put(`/api/v1/web/idps/local/${params.id}/`, params);
export const putLocalIdps = (params: NewLocalIdpsParams) => http.put(`/api/v3/web/idps/local/${params.id}/`, params);
42 changes: 21 additions & 21 deletions src/pages/src/http/dataSourceFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,111 +20,111 @@ import type {
*/
export const getDataSourceUsers = (params: DataSourceUsersParams): Promise<DataSourceUsersResult> => {
const { id, username, page, pageSize } = params;
return http.get(`/api/v1/web/data-sources/${id}/users/?username=${username}&page=${page}&page_size=${pageSize}`);
return http.get(`/api/v3/web/data-sources/${id}/users/?username=${username}&page=${page}&page_size=${pageSize}`);
};

/**
* 新建数据源用户
*/
export const newDataSourceUser = (params: NewDataSourceUserParams) => http.post(`/api/v1/web/data-sources/${params.id}/users/`, params);
export const newDataSourceUser = (params: NewDataSourceUserParams) => http.post(`/api/v3/web/data-sources/${params.id}/users/`, params);

/**
* 数据源创建用户-下拉部门列表
*/
export const getDataSourceDepartments = (params: DepartmentsParams) => {
const { id, name, page, pageSize } = params;
return http.get(`/api/v1/web/data-sources/${id}/departments/?name=${name}&page=${page}&page_size=${pageSize}`);
return http.get(`/api/v3/web/data-sources/${id}/departments/?name=${name}&page=${page}&page_size=${pageSize}`);
};

/**
* 数据源创建用户-下拉上级列表
*/
export const getDataSourceLeaders = (params: LeadersParams) => {
const { id, keyword, page, pageSize } = params;
return http.get(`/api/v1/web/data-sources/${id}/leaders/?keyword=${keyword}&page=${page}&page_size=${pageSize}`);
return http.get(`/api/v3/web/data-sources/${id}/leaders/?keyword=${keyword}&page=${page}&page_size=${pageSize}`);
};

/**
* 数据源用户详情
*/
export const getDataSourceUserDetails = (id: string) => http.get(`/api/v1/web/data-sources/users/${id}/`);
export const getDataSourceUserDetails = (id: string) => http.get(`/api/v3/web/data-sources/users/${id}/`);

/**
* 更新数据源用户
*/
export const putDataSourceUserDetails = (params: PutDataSourceUserParams) => http.put(`/api/v1/web/data-sources/users/${params.id}/`, params);
export const putDataSourceUserDetails = (params: PutDataSourceUserParams) => http.put(`/api/v3/web/data-sources/users/${params.id}/`, params);

/**
* 数据源列表
*/
export const getDataSourceList = (params: { type: string }) => http.get('/api/v1/web/data-sources/', params);
export const getDataSourceList = (params: { type: string }) => http.get('/api/v3/web/data-sources/', params);

/**
* 数据源插件列表
*/
export const getDataSourcePlugins = () => http.get('/api/v1/web/data-sources/plugins/');
export const getDataSourcePlugins = () => http.get('/api/v3/web/data-sources/plugins/');

/**
* 新建数据源
*/
export const newDataSource = (params: NewDataSourceParams) => http.post('/api/v1/web/data-sources/', params);
export const newDataSource = (params: NewDataSourceParams) => http.post('/api/v3/web/data-sources/', params);

/**
* 数据源详情
*/
export const getDataSourceDetails = (id: string) => http.get(`/api/v1/web/data-sources/${id}/`);
export const getDataSourceDetails = (id: string) => http.get(`/api/v3/web/data-sources/${id}/`);

/**
* 新建数据源默认配置
*/
export const getDefaultConfig = (id: string) => http.get(`/api/v1/web/data-sources/plugins/${id}/default-config/`);
export const getDefaultConfig = (id: string) => http.get(`/api/v3/web/data-sources/plugins/${id}/default-config/`);

/**
* 更新数据源
*/
export const putDataSourceDetails = (params: PutDataSourceParams) => http.put(`/api/v1/web/data-sources/${params.id}/`, params);
export const putDataSourceDetails = (params: PutDataSourceParams) => http.put(`/api/v3/web/data-sources/${params.id}/`, params);

/**
* 变更数据源状态
*/
export const changeSwitchStatus = (id: string) => http.patch(`/api/v1/web/data-sources/${id}/operations/switch_status/`);
export const changeSwitchStatus = (id: string) => http.patch(`/api/v3/web/data-sources/${id}/operations/switch_status/`);

/**
* 数据源连通性测试
*/
export const postTestConnection = (params: TestConnectionParams) => http.post('/api/v1/web/data-sources/test-connection/', params);
export const postTestConnection = (params: TestConnectionParams) => http.post('/api/v3/web/data-sources/test-connection/', params);

/**
* 数据源同步
*/
export const postOperationsSync = (id: string) => http.post(`/api/v1/web/data-sources/${id}/operations/sync/`);
export const postOperationsSync = (id: string) => http.post(`/api/v3/web/data-sources/${id}/operations/sync/`);

/**
* 生成数据源用户随机密码
*/
export const randomPasswords = (params: GeneratePasswordParams) => http.post('/api/v1/web/data-sources/random-passwords/', params);
export const randomPasswords = (params: GeneratePasswordParams) => http.post('/api/v3/web/data-sources/random-passwords/', params);

/**
* 数据源更新记录
*/
export const getSyncRecords = (params: SyncRecordsParams) => http.get(`/api/v1/web/data-sources/${params.id}/sync-records/`, params);
export const getSyncRecords = (params: SyncRecordsParams) => http.get(`/api/v3/web/data-sources/${params.id}/sync-records/`, params);

/**
* 数据源更新日志
*/
export const getSyncLogs = (id: string) => http.get(`/api/v1/web/data-sources/sync-records/${id}/`);
export const getSyncLogs = (id: string) => http.get(`/api/v3/web/data-sources/sync-records/${id}/`);

/**
* 重置数据源用户密码
*/
export const putUsersPassword = (params: ResetPasswordParams) => http.put(`/api/v1/web/data-sources/users/${params.id}/password/`, params);
export const putUsersPassword = (params: ResetPasswordParams) => http.put(`/api/v3/web/data-sources/users/${params.id}/password/`, params);

/**
* 重置数据源
*/
export const deleteDataSources = (params: DeleteDataSourcesParams) => http.delete(`/api/v1/web/data-sources/${params.id}/`, params);
export const deleteDataSources = (params: DeleteDataSourcesParams) => http.delete(`/api/v3/web/data-sources/${params.id}/`, params);

/**
* 数据源关联资源信息
*/
export const getRelatedResource = (id: string) => http.get(`/api/v1/web/data-sources/${id}/related-resource-statistics/`);
export const getRelatedResource = (id: string) => http.get(`/api/v3/web/data-sources/${id}/related-resource-statistics/`);
2 changes: 1 addition & 1 deletion src/pages/src/http/fetch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const handleReject = (error: AxiosError, config: Record<string, any>) => {
const { message = '', data = {}, code = '', details = [] } = error.response.data.error;

if (status === 401) {
if (error.config.url === '/api/v1/web/basic/current-user/') {
if (error.config.url === '/api/v3/web/basic/current-user/') {
return window.location.href = getLoginUrl(false);
}
// 登录弹窗
Expand Down
14 changes: 7 additions & 7 deletions src/pages/src/http/organizationFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,46 @@ import type {
UpdateTenantParams,
} from './types/organizationFiles';

const prefix = 'api/v1/web/organization';
const prefix = 'api/v3/web/organization';

/**
* 组织架构-租户列表
*/
export const getTenantOrganizationList = () => http.get('/api/v1/web/tenant-organization/tenants/');
export const getTenantOrganizationList = () => http.get('/api/v3/web/tenant-organization/tenants/');

/**
* 单个租户详情
*/
export const getTenantOrganizationDetails = (id: string) => http.get(`/api/v1/web/tenant-organization/tenants/${id}/`);
export const getTenantOrganizationDetails = (id: string) => http.get(`/api/v3/web/tenant-organization/tenants/${id}/`);

/**
* 更新租户
*/
export const putTenantOrganizationDetails = (id: string, params: UpdateTenantParams) => {
const url = http.put(`/api/v1/web/tenant-organization/tenants/${id}/`, params);
const url = http.put(`/api/v3/web/tenant-organization/tenants/${id}/`, params);
return url;
};

/**
* 租户下的二级子部门列表
*/
export const getTenantDepartments = (id: string) => http.get(`/api/v1/web/tenant-organization/departments/${id}/children/`);
export const getTenantDepartments = (id: string) => http.get(`/api/v3/web/tenant-organization/departments/${id}/children/`);


/**
* 租户下部门下用户列表
*/
export const getTenantDepartmentsList = (params: DepartmentsListParams) => {
const { id, keyword, page, pageSize, recursive } = params;
return http.get(`/api/v1/web/tenant-organization/departments/${id}/users/?keyword=${keyword}&page=${page}&page_size=${pageSize}&recursive=${recursive}`);
return http.get(`/api/v3/web/tenant-organization/departments/${id}/users/?keyword=${keyword}&page=${page}&page_size=${pageSize}&recursive=${recursive}`);
};

/**
* 租户下用户列表
*/
export const getTenantOrganizationUsersList = (params: TenantListParams) => {
const { id, keyword, page, pageSize } = params;
return http.get(`/api/v1/web/tenant-organization/tenants/${id}/users/?keyword=${keyword}&page=${page}&page_size=${pageSize}`);
return http.get(`/api/v3/web/tenant-organization/tenants/${id}/users/?keyword=${keyword}&page=${page}&page_size=${pageSize}`);
};

/**
Expand Down
Loading

0 comments on commit 63769e1

Please sign in to comment.