Skip to content

Commit

Permalink
refactor(server): delete some api
Browse files Browse the repository at this point in the history
remove unused apis
  • Loading branch information
yongheng2016 committed Dec 16, 2024
1 parent 3904a2b commit 1d3489d
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 167 deletions.
5 changes: 0 additions & 5 deletions apps/adminConsole/src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 = [
Expand Down
5 changes: 0 additions & 5 deletions apps/common/src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 = [
Expand Down
5 changes: 0 additions & 5 deletions apps/nodes/src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion apps/server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@apps/server",
"version": "0.2.3",
"version": "0.2.4",
"description": "server",
"productName": "server",
"private": true,
Expand Down
19 changes: 4 additions & 15 deletions apps/server/server/controllers/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@

const {
getCurrentUser,
getKSConfig,
getK8sRuntime,
getOAuthInfo,
getClusterRole,
getSupportGpuList,
getGitOpsEngine,
getMyApps,
getAllMetric,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
10 changes: 0 additions & 10 deletions apps/server/server/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -174,6 +165,5 @@ function k8sResourceproxyRes(proxyRes, req, res) {

module.exports = {
k8sResourceProxy,
devopsWebhookProxy,
b2iFileProxy
};
127 changes: 1 addition & 126 deletions apps/server/server/services/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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) {
Expand All @@ -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({
Expand All @@ -548,13 +425,11 @@ module.exports = {
login,
oAuthLogin,
getCurrentUser,
getOAuthInfo,
getNewToken,
getKSConfig,
getK8sRuntime,
createUser,
getClusterRole,
getSupportGpuList,
getGitOpsEngine,
getMyApps,
getAllMetric,
Expand Down

0 comments on commit 1d3489d

Please sign in to comment.