From 1d3489db69734b652514e211a2e8a31ce26a027d Mon Sep 17 00:00:00 2001 From: yyh <24493052+yongheng2016@users.noreply.github.com> Date: Mon, 16 Dec 2024 16:26:43 +0800 Subject: [PATCH] refactor(server): delete some api remove unused apis --- apps/adminConsole/src/utils/constants.js | 5 - apps/common/src/utils/constants.js | 5 - apps/nodes/src/utils/constants.js | 5 - apps/server/package.json | 2 +- apps/server/server/controllers/view.js | 19 +--- apps/server/server/proxy.js | 10 -- apps/server/server/services/session.js | 127 +---------------------- 7 files changed, 6 insertions(+), 167 deletions(-) diff --git a/apps/adminConsole/src/utils/constants.js b/apps/adminConsole/src/utils/constants.js index da13de6..a5e38a2 100644 --- a/apps/adminConsole/src/utils/constants.js +++ b/apps/adminConsole/src/utils/constants.js @@ -962,8 +962,6 @@ export const API_VERSIONS = { workspaces: 'apis/tenant.kubesphere.io/v1alpha2', users: 'apis/iam.kubesphere.io/v1alpha2', globalroles: 'apis/iam.kubesphere.io/v1alpha2', - devops: 'kapis/devops.kubesphere.io/v1alpha3', - pipelines: 'kapis/devops.kubesphere.io/v1alpha3', workspaceroles: 'apis/iam.kubesphere.io/v1alpha2', dashboards: 'apis/monitoring.kubesphere.io/v1alpha2', clusterdashboards: 'apis/monitoring.kubesphere.io/v1alpha2', @@ -972,9 +970,6 @@ export const API_VERSIONS = { ippools: 'apis/network.kubesphere.io/v1alpha1', storageclasscapabilities: 'apis/storage.kubesphere.io/v1alpha1', meter: 'kapis/metering.kubesphere.io/v1alpha1', - gateways: 'kapis/gateway.kubesphere.io/v1alpha1', - cds: 'kapis/gitops.kubesphere.io/v1alpha1', - codeRepos: 'kapis/devops.kubesphere.io/v1alpha3' }; export const MONITOR_GRAPH_COLORS = [ diff --git a/apps/common/src/utils/constants.js b/apps/common/src/utils/constants.js index da13de6..a5e38a2 100644 --- a/apps/common/src/utils/constants.js +++ b/apps/common/src/utils/constants.js @@ -962,8 +962,6 @@ export const API_VERSIONS = { workspaces: 'apis/tenant.kubesphere.io/v1alpha2', users: 'apis/iam.kubesphere.io/v1alpha2', globalroles: 'apis/iam.kubesphere.io/v1alpha2', - devops: 'kapis/devops.kubesphere.io/v1alpha3', - pipelines: 'kapis/devops.kubesphere.io/v1alpha3', workspaceroles: 'apis/iam.kubesphere.io/v1alpha2', dashboards: 'apis/monitoring.kubesphere.io/v1alpha2', clusterdashboards: 'apis/monitoring.kubesphere.io/v1alpha2', @@ -972,9 +970,6 @@ export const API_VERSIONS = { ippools: 'apis/network.kubesphere.io/v1alpha1', storageclasscapabilities: 'apis/storage.kubesphere.io/v1alpha1', meter: 'kapis/metering.kubesphere.io/v1alpha1', - gateways: 'kapis/gateway.kubesphere.io/v1alpha1', - cds: 'kapis/gitops.kubesphere.io/v1alpha1', - codeRepos: 'kapis/devops.kubesphere.io/v1alpha3' }; export const MONITOR_GRAPH_COLORS = [ diff --git a/apps/nodes/src/utils/constants.js b/apps/nodes/src/utils/constants.js index da13de6..a5e38a2 100644 --- a/apps/nodes/src/utils/constants.js +++ b/apps/nodes/src/utils/constants.js @@ -962,8 +962,6 @@ export const API_VERSIONS = { workspaces: 'apis/tenant.kubesphere.io/v1alpha2', users: 'apis/iam.kubesphere.io/v1alpha2', globalroles: 'apis/iam.kubesphere.io/v1alpha2', - devops: 'kapis/devops.kubesphere.io/v1alpha3', - pipelines: 'kapis/devops.kubesphere.io/v1alpha3', workspaceroles: 'apis/iam.kubesphere.io/v1alpha2', dashboards: 'apis/monitoring.kubesphere.io/v1alpha2', clusterdashboards: 'apis/monitoring.kubesphere.io/v1alpha2', @@ -972,9 +970,6 @@ export const API_VERSIONS = { ippools: 'apis/network.kubesphere.io/v1alpha1', storageclasscapabilities: 'apis/storage.kubesphere.io/v1alpha1', meter: 'kapis/metering.kubesphere.io/v1alpha1', - gateways: 'kapis/gateway.kubesphere.io/v1alpha1', - cds: 'kapis/gitops.kubesphere.io/v1alpha1', - codeRepos: 'kapis/devops.kubesphere.io/v1alpha3' }; export const MONITOR_GRAPH_COLORS = [ diff --git a/apps/server/package.json b/apps/server/package.json index 5a66dbc..5b7ea69 100644 --- a/apps/server/package.json +++ b/apps/server/package.json @@ -1,6 +1,6 @@ { "name": "@apps/server", - "version": "0.2.3", + "version": "0.2.4", "description": "server", "productName": "server", "private": true, diff --git a/apps/server/server/controllers/view.js b/apps/server/server/controllers/view.js index b20b651..43e620d 100644 --- a/apps/server/server/controllers/view.js +++ b/apps/server/server/controllers/view.js @@ -18,11 +18,8 @@ const { getCurrentUser, - getKSConfig, getK8sRuntime, - getOAuthInfo, getClusterRole, - getSupportGpuList, getGitOpsEngine, getMyApps, getAllMetric, @@ -52,20 +49,18 @@ const { client: clientConfig } = getServerConfig(); const userDetail = async (ctx) => { const clusterRole = await getClusterRole(ctx); - const ksConfig = await getKSConfig(ctx); - const [user, runtime, supportGpuType, gitopsEngine] = await Promise.all([ - getCurrentUser(ctx, clusterRole, ksConfig.multicluster), + const [user, runtime, gitopsEngine] = await Promise.all([ + getCurrentUser(ctx, clusterRole, false), getK8sRuntime(ctx), - getSupportGpuList(ctx), getGitOpsEngine(ctx) + ]); const localeManifest = getLocaleManifest(); const data = { localeManifest, - ksConfig, user, runtime, clusterRole, @@ -259,16 +254,10 @@ const cacheUser = async (ctx, next) => { console.log('header', ctx.headers['x-bfl-user']); if (!user) { const clusterRole = await getClusterRole(ctx); - const ksConfig = await getKSConfig(ctx); const [user] = await Promise.all([ - getCurrentUser(ctx, clusterRole, ksConfig.multicluster) + getCurrentUser(ctx, clusterRole) ]); - const data = { - ksConfig, - user, - clusterRole - }; setUserInfo(ctx, user); } await next(); diff --git a/apps/server/server/proxy.js b/apps/server/server/proxy.js index 921fa9d..39d29aa 100644 --- a/apps/server/server/proxy.js +++ b/apps/server/server/proxy.js @@ -61,15 +61,6 @@ const k8sResourceProxy = { } }; -const devopsWebhookProxy = { - target: `${serverConfig.apiServer.url}/kapis/devops.kubesphere.io/v1alpha2`, - changeOrigin: true, - ignorePath: true, - optionsHandle(options, req) { - options.target += `/${req.url.slice(8)}`; - } -}; - const b2iFileProxy = { target: serverConfig.apiServer.url, changeOrigin: true, @@ -174,6 +165,5 @@ function k8sResourceproxyRes(proxyRes, req, res) { module.exports = { k8sResourceProxy, - devopsWebhookProxy, b2iFileProxy }; diff --git a/apps/server/server/services/session.js b/apps/server/server/services/session.js index f046470..88a3c12 100644 --- a/apps/server/server/services/session.js +++ b/apps/server/server/services/session.js @@ -229,39 +229,6 @@ const getUserDetail = async (token, clusterRole, isMulticluster) => { return user; }; -const getWorkspaces = async (token, clusterRole) => { - let workspaces = []; - let version = 3.2; - - const backendVersion = await send_gateway_request({ - method: 'GET', - url: '/kapis/version', - token - }); - if (backendVersion) { - const _version = backendVersion.gitVersion.replace(/[^\d.]/g, ''); - version = Number(_version.split('.').slice(0, 2).join('.')); - } - const url = - version > 3.2 - ? clusterRole === 'host' - ? '/kapis/tenant.kubesphere.io/v1alpha3/workspacetemplates' - : '/kapis/tenant.kubesphere.io/v1alpha3/workspaces' - : '/kapis/tenant.kubesphere.io/v1alpha2/workspaces'; - - const resp = await send_gateway_request({ - method: 'GET', - url, - params: { limit: 10 }, - token - }); - - if (resp && resp.items) { - workspaces = resp.items.map((item) => item.metadata.name); - } - - return workspaces; -}; const getKSConfig = async (ctx) => { const token = ctx.cookies.get('auth_token'); @@ -381,33 +348,6 @@ const getUserMetric = async (ctx, params) => { return data; }; -const getSupportGpuList = async (ctx) => { - const token = ctx.cookies.get('auth_token'); - let gpuKinds = []; - if (!token) { - return []; - } - try { - const list = await send_gateway_request({ - method: 'GET', - url: '/kapis/config.kubesphere.io/v1alpha2/configs/gpu/kinds', - token - }); - if (Array.isArray(list)) { - const defaultGpu = list - .filter((item) => item.default) - .map((item) => item.resourceName); - - const otherGpus = list - .filter((item) => !item.default) - .map((item) => item.resourceName); - - gpuKinds = [...defaultGpu, ...otherGpus]; - } - } catch (error) { } - - return gpuKinds; -}; // TODO: need to get the data from kubesphere const getGitOpsEngine = async (ctx) => { @@ -445,7 +385,7 @@ const getUsers = async (ctx, clusterRole, isMulticluster) => { return resp; }; -const getCurrentUser = async (ctx, clusterRole, isMulticluster) => { +const getCurrentUser = async (ctx, clusterRole, isMulticluster = false) => { const token = ctx.cookies.get('auth_token'); if (!token) { @@ -457,74 +397,11 @@ const getCurrentUser = async (ctx, clusterRole, isMulticluster) => { const [userDetail, workspaces] = await Promise.all([ getUserDetail(token, clusterRole, isMulticluster), - getWorkspaces(token, clusterRole) ]); return { ...userDetail, workspaces }; }; -const getOAuthInfo = async () => { - let resp = []; - try { - resp = await send_gateway_request({ - method: 'GET', - url: '/kapis/config.kubesphere.io/v1alpha2/configs/oauth' - }); - } catch (error) { - console.error(error); - } - - const servers = []; - if (resp && !isEmpty(resp.identityProviders)) { - resp.identityProviders.forEach((item) => { - if (item && item.provider) { - let url; - let params = {}; - let type; - let endSessionURL; - - const authURL = get(item, 'provider.endpoint.authURL'); - - if (authURL) { - url = authURL; - params = { - state: item.name, - client_id: item.provider.clientID, - response_type: 'code' - }; - - if (item.provider.redirectURL) { - params.redirect_uri = item.provider.redirectURL; - } - - if (item.provider.scopes && item.provider.scopes.length > 0) { - params.scope = item.provider.scopes.join(' '); - } - - if (item.type) { - endSessionURL = get(item, 'provider.endpoint.endSessionURL'); - type = item.type; - } - } else if (item.provider.casServerURL) { - params = { service: item.provider.redirectURL }; - url = item.provider.casServerURL; - } - - if (url) { - url = `${url}?${Object.keys(params) - .map( - (key) => - `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}` - ) - .join('&')}`; - servers.push({ title: item.name, url, type, endSessionURL }); - } - } - }); - } - - return servers; -}; const createUser = (params, token) => { return send_gateway_request({ @@ -548,13 +425,11 @@ module.exports = { login, oAuthLogin, getCurrentUser, - getOAuthInfo, getNewToken, getKSConfig, getK8sRuntime, createUser, getClusterRole, - getSupportGpuList, getGitOpsEngine, getMyApps, getAllMetric,