Skip to content

Commit 819f25f

Browse files
authored
Merge pull request #5 from beclab/fix/server-api
refactor(server): remove unused apis
2 parents 3904a2b + 1d3489d commit 819f25f

File tree

7 files changed

+6
-167
lines changed

7 files changed

+6
-167
lines changed

apps/adminConsole/src/utils/constants.js

-5
Original file line numberDiff line numberDiff line change
@@ -962,8 +962,6 @@ export const API_VERSIONS = {
962962
workspaces: 'apis/tenant.kubesphere.io/v1alpha2',
963963
users: 'apis/iam.kubesphere.io/v1alpha2',
964964
globalroles: 'apis/iam.kubesphere.io/v1alpha2',
965-
devops: 'kapis/devops.kubesphere.io/v1alpha3',
966-
pipelines: 'kapis/devops.kubesphere.io/v1alpha3',
967965
workspaceroles: 'apis/iam.kubesphere.io/v1alpha2',
968966
dashboards: 'apis/monitoring.kubesphere.io/v1alpha2',
969967
clusterdashboards: 'apis/monitoring.kubesphere.io/v1alpha2',
@@ -972,9 +970,6 @@ export const API_VERSIONS = {
972970
ippools: 'apis/network.kubesphere.io/v1alpha1',
973971
storageclasscapabilities: 'apis/storage.kubesphere.io/v1alpha1',
974972
meter: 'kapis/metering.kubesphere.io/v1alpha1',
975-
gateways: 'kapis/gateway.kubesphere.io/v1alpha1',
976-
cds: 'kapis/gitops.kubesphere.io/v1alpha1',
977-
codeRepos: 'kapis/devops.kubesphere.io/v1alpha3'
978973
};
979974

980975
export const MONITOR_GRAPH_COLORS = [

apps/common/src/utils/constants.js

-5
Original file line numberDiff line numberDiff line change
@@ -962,8 +962,6 @@ export const API_VERSIONS = {
962962
workspaces: 'apis/tenant.kubesphere.io/v1alpha2',
963963
users: 'apis/iam.kubesphere.io/v1alpha2',
964964
globalroles: 'apis/iam.kubesphere.io/v1alpha2',
965-
devops: 'kapis/devops.kubesphere.io/v1alpha3',
966-
pipelines: 'kapis/devops.kubesphere.io/v1alpha3',
967965
workspaceroles: 'apis/iam.kubesphere.io/v1alpha2',
968966
dashboards: 'apis/monitoring.kubesphere.io/v1alpha2',
969967
clusterdashboards: 'apis/monitoring.kubesphere.io/v1alpha2',
@@ -972,9 +970,6 @@ export const API_VERSIONS = {
972970
ippools: 'apis/network.kubesphere.io/v1alpha1',
973971
storageclasscapabilities: 'apis/storage.kubesphere.io/v1alpha1',
974972
meter: 'kapis/metering.kubesphere.io/v1alpha1',
975-
gateways: 'kapis/gateway.kubesphere.io/v1alpha1',
976-
cds: 'kapis/gitops.kubesphere.io/v1alpha1',
977-
codeRepos: 'kapis/devops.kubesphere.io/v1alpha3'
978973
};
979974

980975
export const MONITOR_GRAPH_COLORS = [

apps/nodes/src/utils/constants.js

-5
Original file line numberDiff line numberDiff line change
@@ -962,8 +962,6 @@ export const API_VERSIONS = {
962962
workspaces: 'apis/tenant.kubesphere.io/v1alpha2',
963963
users: 'apis/iam.kubesphere.io/v1alpha2',
964964
globalroles: 'apis/iam.kubesphere.io/v1alpha2',
965-
devops: 'kapis/devops.kubesphere.io/v1alpha3',
966-
pipelines: 'kapis/devops.kubesphere.io/v1alpha3',
967965
workspaceroles: 'apis/iam.kubesphere.io/v1alpha2',
968966
dashboards: 'apis/monitoring.kubesphere.io/v1alpha2',
969967
clusterdashboards: 'apis/monitoring.kubesphere.io/v1alpha2',
@@ -972,9 +970,6 @@ export const API_VERSIONS = {
972970
ippools: 'apis/network.kubesphere.io/v1alpha1',
973971
storageclasscapabilities: 'apis/storage.kubesphere.io/v1alpha1',
974972
meter: 'kapis/metering.kubesphere.io/v1alpha1',
975-
gateways: 'kapis/gateway.kubesphere.io/v1alpha1',
976-
cds: 'kapis/gitops.kubesphere.io/v1alpha1',
977-
codeRepos: 'kapis/devops.kubesphere.io/v1alpha3'
978973
};
979974

980975
export const MONITOR_GRAPH_COLORS = [

apps/server/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@apps/server",
3-
"version": "0.2.3",
3+
"version": "0.2.4",
44
"description": "server",
55
"productName": "server",
66
"private": true,

apps/server/server/controllers/view.js

+4-15
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@
1818

1919
const {
2020
getCurrentUser,
21-
getKSConfig,
2221
getK8sRuntime,
23-
getOAuthInfo,
2422
getClusterRole,
25-
getSupportGpuList,
2623
getGitOpsEngine,
2724
getMyApps,
2825
getAllMetric,
@@ -52,20 +49,18 @@ const { client: clientConfig } = getServerConfig();
5249

5350
const userDetail = async (ctx) => {
5451
const clusterRole = await getClusterRole(ctx);
55-
const ksConfig = await getKSConfig(ctx);
5652

57-
const [user, runtime, supportGpuType, gitopsEngine] = await Promise.all([
58-
getCurrentUser(ctx, clusterRole, ksConfig.multicluster),
53+
const [user, runtime, gitopsEngine] = await Promise.all([
54+
getCurrentUser(ctx, clusterRole, false),
5955
getK8sRuntime(ctx),
60-
getSupportGpuList(ctx),
6156
getGitOpsEngine(ctx)
57+
6258
]);
6359

6460
const localeManifest = getLocaleManifest();
6561

6662
const data = {
6763
localeManifest,
68-
ksConfig,
6964
user,
7065
runtime,
7166
clusterRole,
@@ -259,16 +254,10 @@ const cacheUser = async (ctx, next) => {
259254
console.log('header', ctx.headers['x-bfl-user']);
260255
if (!user) {
261256
const clusterRole = await getClusterRole(ctx);
262-
const ksConfig = await getKSConfig(ctx);
263257
const [user] = await Promise.all([
264-
getCurrentUser(ctx, clusterRole, ksConfig.multicluster)
258+
getCurrentUser(ctx, clusterRole)
265259
]);
266260

267-
const data = {
268-
ksConfig,
269-
user,
270-
clusterRole
271-
};
272261
setUserInfo(ctx, user);
273262
}
274263
await next();

apps/server/server/proxy.js

-10
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,6 @@ const k8sResourceProxy = {
6161
}
6262
};
6363

64-
const devopsWebhookProxy = {
65-
target: `${serverConfig.apiServer.url}/kapis/devops.kubesphere.io/v1alpha2`,
66-
changeOrigin: true,
67-
ignorePath: true,
68-
optionsHandle(options, req) {
69-
options.target += `/${req.url.slice(8)}`;
70-
}
71-
};
72-
7364
const b2iFileProxy = {
7465
target: serverConfig.apiServer.url,
7566
changeOrigin: true,
@@ -174,6 +165,5 @@ function k8sResourceproxyRes(proxyRes, req, res) {
174165

175166
module.exports = {
176167
k8sResourceProxy,
177-
devopsWebhookProxy,
178168
b2iFileProxy
179169
};

apps/server/server/services/session.js

+1-126
Original file line numberDiff line numberDiff line change
@@ -229,39 +229,6 @@ const getUserDetail = async (token, clusterRole, isMulticluster) => {
229229
return user;
230230
};
231231

232-
const getWorkspaces = async (token, clusterRole) => {
233-
let workspaces = [];
234-
let version = 3.2;
235-
236-
const backendVersion = await send_gateway_request({
237-
method: 'GET',
238-
url: '/kapis/version',
239-
token
240-
});
241-
if (backendVersion) {
242-
const _version = backendVersion.gitVersion.replace(/[^\d.]/g, '');
243-
version = Number(_version.split('.').slice(0, 2).join('.'));
244-
}
245-
const url =
246-
version > 3.2
247-
? clusterRole === 'host'
248-
? '/kapis/tenant.kubesphere.io/v1alpha3/workspacetemplates'
249-
: '/kapis/tenant.kubesphere.io/v1alpha3/workspaces'
250-
: '/kapis/tenant.kubesphere.io/v1alpha2/workspaces';
251-
252-
const resp = await send_gateway_request({
253-
method: 'GET',
254-
url,
255-
params: { limit: 10 },
256-
token
257-
});
258-
259-
if (resp && resp.items) {
260-
workspaces = resp.items.map((item) => item.metadata.name);
261-
}
262-
263-
return workspaces;
264-
};
265232

266233
const getKSConfig = async (ctx) => {
267234
const token = ctx.cookies.get('auth_token');
@@ -381,33 +348,6 @@ const getUserMetric = async (ctx, params) => {
381348
return data;
382349
};
383350

384-
const getSupportGpuList = async (ctx) => {
385-
const token = ctx.cookies.get('auth_token');
386-
let gpuKinds = [];
387-
if (!token) {
388-
return [];
389-
}
390-
try {
391-
const list = await send_gateway_request({
392-
method: 'GET',
393-
url: '/kapis/config.kubesphere.io/v1alpha2/configs/gpu/kinds',
394-
token
395-
});
396-
if (Array.isArray(list)) {
397-
const defaultGpu = list
398-
.filter((item) => item.default)
399-
.map((item) => item.resourceName);
400-
401-
const otherGpus = list
402-
.filter((item) => !item.default)
403-
.map((item) => item.resourceName);
404-
405-
gpuKinds = [...defaultGpu, ...otherGpus];
406-
}
407-
} catch (error) { }
408-
409-
return gpuKinds;
410-
};
411351

412352
// TODO: need to get the data from kubesphere
413353
const getGitOpsEngine = async (ctx) => {
@@ -445,7 +385,7 @@ const getUsers = async (ctx, clusterRole, isMulticluster) => {
445385
return resp;
446386
};
447387

448-
const getCurrentUser = async (ctx, clusterRole, isMulticluster) => {
388+
const getCurrentUser = async (ctx, clusterRole, isMulticluster = false) => {
449389
const token = ctx.cookies.get('auth_token');
450390

451391
if (!token) {
@@ -457,74 +397,11 @@ const getCurrentUser = async (ctx, clusterRole, isMulticluster) => {
457397

458398
const [userDetail, workspaces] = await Promise.all([
459399
getUserDetail(token, clusterRole, isMulticluster),
460-
getWorkspaces(token, clusterRole)
461400
]);
462401

463402
return { ...userDetail, workspaces };
464403
};
465404

466-
const getOAuthInfo = async () => {
467-
let resp = [];
468-
try {
469-
resp = await send_gateway_request({
470-
method: 'GET',
471-
url: '/kapis/config.kubesphere.io/v1alpha2/configs/oauth'
472-
});
473-
} catch (error) {
474-
console.error(error);
475-
}
476-
477-
const servers = [];
478-
if (resp && !isEmpty(resp.identityProviders)) {
479-
resp.identityProviders.forEach((item) => {
480-
if (item && item.provider) {
481-
let url;
482-
let params = {};
483-
let type;
484-
let endSessionURL;
485-
486-
const authURL = get(item, 'provider.endpoint.authURL');
487-
488-
if (authURL) {
489-
url = authURL;
490-
params = {
491-
state: item.name,
492-
client_id: item.provider.clientID,
493-
response_type: 'code'
494-
};
495-
496-
if (item.provider.redirectURL) {
497-
params.redirect_uri = item.provider.redirectURL;
498-
}
499-
500-
if (item.provider.scopes && item.provider.scopes.length > 0) {
501-
params.scope = item.provider.scopes.join(' ');
502-
}
503-
504-
if (item.type) {
505-
endSessionURL = get(item, 'provider.endpoint.endSessionURL');
506-
type = item.type;
507-
}
508-
} else if (item.provider.casServerURL) {
509-
params = { service: item.provider.redirectURL };
510-
url = item.provider.casServerURL;
511-
}
512-
513-
if (url) {
514-
url = `${url}?${Object.keys(params)
515-
.map(
516-
(key) =>
517-
`${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`
518-
)
519-
.join('&')}`;
520-
servers.push({ title: item.name, url, type, endSessionURL });
521-
}
522-
}
523-
});
524-
}
525-
526-
return servers;
527-
};
528405

529406
const createUser = (params, token) => {
530407
return send_gateway_request({
@@ -548,13 +425,11 @@ module.exports = {
548425
login,
549426
oAuthLogin,
550427
getCurrentUser,
551-
getOAuthInfo,
552428
getNewToken,
553429
getKSConfig,
554430
getK8sRuntime,
555431
createUser,
556432
getClusterRole,
557-
getSupportGpuList,
558433
getGitOpsEngine,
559434
getMyApps,
560435
getAllMetric,

0 commit comments

Comments
 (0)