2026-07-15 10:52:41 +08:00
|
|
|
import type { ApiResponse } from '@/types/api'
|
2026-07-15 14:47:42 +08:00
|
|
|
import { getToken, removeToken } from '@/utils/auth'
|
|
|
|
|
import { redirectToSSO } from '@/utils/sso'
|
2026-07-14 15:39:44 +08:00
|
|
|
|
|
|
|
|
export interface Subsystem {
|
|
|
|
|
id: number
|
|
|
|
|
name: string
|
2026-07-17 11:20:17 +08:00
|
|
|
label: string
|
2026-07-14 15:39:44 +08:00
|
|
|
description: string
|
|
|
|
|
icon: string
|
|
|
|
|
url: string
|
2026-07-17 11:20:17 +08:00
|
|
|
domain: string
|
|
|
|
|
category: string
|
2026-07-14 15:39:44 +08:00
|
|
|
status: 'integrated' | 'integrating'
|
|
|
|
|
sso_enabled: boolean
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-15 10:52:41 +08:00
|
|
|
export interface SSOResponse {
|
|
|
|
|
sso_url: string
|
|
|
|
|
expires_in: number
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-14 15:39:44 +08:00
|
|
|
const mockSubsystems: Subsystem[] = [
|
|
|
|
|
{
|
|
|
|
|
id: 1,
|
|
|
|
|
name: 'Wayne',
|
2026-07-17 11:20:17 +08:00
|
|
|
label: '多集群发布平台',
|
|
|
|
|
description: '业务容器发布、命名空间与配额管理,复用 Wayne 原生多租户能力。',
|
2026-07-14 15:39:44 +08:00
|
|
|
icon: 'W',
|
|
|
|
|
url: 'https://wayne.qiniu.com',
|
2026-07-17 11:20:17 +08:00
|
|
|
domain: 'wayne.xinfra.internal',
|
|
|
|
|
category: '容器管理',
|
2026-07-14 15:39:44 +08:00
|
|
|
status: 'integrated',
|
|
|
|
|
sso_enabled: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 2,
|
|
|
|
|
name: 'CloudDM',
|
2026-07-17 11:20:17 +08:00
|
|
|
label: 'SQL 审核平台',
|
|
|
|
|
description: '数据库 SQL 上线统一审核,支持 LDAP 用户组到角色的自动映射。',
|
2026-07-14 15:39:44 +08:00
|
|
|
icon: 'DM',
|
|
|
|
|
url: 'https://clouddm.qiniu.com',
|
2026-07-17 11:20:17 +08:00
|
|
|
domain: 'clouddm.xinfra.internal',
|
|
|
|
|
category: '数据库',
|
2026-07-14 15:39:44 +08:00
|
|
|
status: 'integrated',
|
|
|
|
|
sso_enabled: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 3,
|
|
|
|
|
name: 'CacheCloud',
|
2026-07-17 11:20:17 +08:00
|
|
|
label: 'Redis 管理平台',
|
|
|
|
|
description: 'Redis 实例全生命周期管理,登录与监控运维统一入口。',
|
2026-07-14 15:39:44 +08:00
|
|
|
icon: 'CC',
|
|
|
|
|
url: 'https://cachecloud.qiniu.com',
|
2026-07-17 11:20:17 +08:00
|
|
|
domain: 'cachecloud.xinfra.internal',
|
|
|
|
|
category: '缓存',
|
|
|
|
|
status: 'integrating',
|
2026-07-14 15:39:44 +08:00
|
|
|
sso_enabled: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 4,
|
|
|
|
|
name: 'Apollo',
|
2026-07-17 11:20:17 +08:00
|
|
|
label: '配置中心',
|
|
|
|
|
description: '统一配置管理,按机房 Cluster 隔离,支持灰度发布、版本回滚与变更审计。',
|
2026-07-14 15:39:44 +08:00
|
|
|
icon: 'AP',
|
|
|
|
|
url: 'https://apollo.xinfra.internal',
|
2026-07-17 11:20:17 +08:00
|
|
|
domain: 'apollo.xinfra.internal',
|
|
|
|
|
category: '配置中心',
|
|
|
|
|
status: 'integrating',
|
2026-07-14 15:39:44 +08:00
|
|
|
sso_enabled: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 5,
|
|
|
|
|
name: 'qpass',
|
2026-07-17 11:20:17 +08:00
|
|
|
label: '七牛统一运维平台',
|
2026-07-17 11:36:20 +08:00
|
|
|
description: '七牛云内部系统。',
|
2026-07-14 15:39:44 +08:00
|
|
|
icon: 'QP',
|
|
|
|
|
url: 'https://qpass.xinfra.internal',
|
2026-07-17 11:20:17 +08:00
|
|
|
domain: 'qpass.xinfra.internal',
|
2026-07-17 11:36:20 +08:00
|
|
|
category: '内部系统',
|
2026-07-14 15:39:44 +08:00
|
|
|
status: 'integrated',
|
|
|
|
|
sso_enabled: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 6,
|
|
|
|
|
name: 'Grafana',
|
2026-07-17 11:20:17 +08:00
|
|
|
label: '指标可视化平台',
|
|
|
|
|
description: '对接 VictoriaMetrics 数据源,K8s / 容器 / 业务指标统一仪表盘展示。',
|
2026-07-14 15:39:44 +08:00
|
|
|
icon: 'GF',
|
|
|
|
|
url: 'https://grafana.xinfra.internal',
|
2026-07-17 11:20:17 +08:00
|
|
|
domain: 'grafana.xinfra.internal',
|
|
|
|
|
category: '可观测性',
|
2026-07-14 15:39:44 +08:00
|
|
|
status: 'integrated',
|
|
|
|
|
sso_enabled: true,
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
export const subsystemApi = {
|
2026-07-15 10:52:41 +08:00
|
|
|
getSubsystems(): Promise<ApiResponse<Subsystem[]>> {
|
2026-07-15 14:47:42 +08:00
|
|
|
return Promise.resolve({
|
|
|
|
|
code: 0,
|
|
|
|
|
message: 'success',
|
|
|
|
|
data: mockSubsystems,
|
2026-07-14 15:39:44 +08:00
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
2026-07-17 11:20:17 +08:00
|
|
|
getSubsystemByName(name: string): Subsystem | undefined {
|
|
|
|
|
return mockSubsystems.find((s) => s.name.toLowerCase() === name.toLowerCase())
|
|
|
|
|
},
|
|
|
|
|
|
2026-07-15 14:47:42 +08:00
|
|
|
async getSSOUrl(id: number): Promise<ApiResponse<SSOResponse>> {
|
|
|
|
|
const subsystem = mockSubsystems.find((s) => s.id === id)
|
|
|
|
|
if (!subsystem) {
|
|
|
|
|
throw new Error('subsystem not found')
|
|
|
|
|
}
|
|
|
|
|
if (subsystem.name !== 'Wayne' && subsystem.name !== 'CloudDM') {
|
|
|
|
|
return {
|
|
|
|
|
code: 0,
|
|
|
|
|
message: 'success',
|
|
|
|
|
data: {
|
|
|
|
|
sso_url: subsystem.url,
|
|
|
|
|
expires_in: 300,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const token = getToken()
|
|
|
|
|
const openApp = subsystem.name === 'CloudDM' ? 'clouddm' : 'wayne'
|
|
|
|
|
const path = subsystem.name === 'CloudDM' ? '/auth/api/v1/clouddm/login' : '/auth/api/v1/wayen/login'
|
|
|
|
|
const response = await fetch(path, {
|
|
|
|
|
headers: {
|
|
|
|
|
Accept: 'application/json',
|
|
|
|
|
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
|
|
|
},
|
|
|
|
|
credentials: 'include',
|
2026-07-14 15:39:44 +08:00
|
|
|
})
|
2026-07-15 14:47:42 +08:00
|
|
|
const data = await response.json().catch(() => ({}))
|
|
|
|
|
if (response.status === 401) {
|
|
|
|
|
removeToken()
|
2026-07-16 16:43:01 +08:00
|
|
|
const configResponse = await fetch('/auth/api/v1/config', {
|
|
|
|
|
headers: { Accept: 'application/json' },
|
|
|
|
|
}).catch(() => null)
|
|
|
|
|
const config = await configResponse?.json().catch(() => ({}))
|
|
|
|
|
if (config?.sso_enabled === false) {
|
|
|
|
|
window.location.assign(`/login?redirect=${encodeURIComponent(`/subsystem?open_app=${openApp}`)}`)
|
|
|
|
|
} else {
|
|
|
|
|
redirectToSSO(openApp)
|
|
|
|
|
}
|
2026-07-15 14:47:42 +08:00
|
|
|
throw new Error('unauthorized')
|
|
|
|
|
}
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
throw new Error(data.error || `HTTP ${response.status}`)
|
|
|
|
|
}
|
|
|
|
|
if (!data.target_url) {
|
|
|
|
|
throw new Error(`${subsystem.name} 跳转地址为空`)
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
code: 0,
|
|
|
|
|
message: 'success',
|
|
|
|
|
data: {
|
|
|
|
|
sso_url: data.target_url,
|
|
|
|
|
expires_in: 300,
|
|
|
|
|
},
|
|
|
|
|
}
|
2026-07-14 15:39:44 +08:00
|
|
|
},
|
|
|
|
|
}
|