Skip to content

Commit aab2ed9

Browse files
Merge pull request #2188 from fishyu-mushroom/main
fix: resolve authentication errors for newly connected assets after org asset ID change
2 parents 3886fb7 + 676303a commit aab2ed9

7 files changed

Lines changed: 39 additions & 10 deletions

File tree

src/main/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2531,8 +2531,9 @@ ipcMain.handle('key-chain-local-update', async (_, data) => {
25312531

25322532
ipcMain.handle('chaterm-connect-asset-info', async (_, data) => {
25332533
try {
2534-
const { uuid } = data
2535-
const result = chatermDbService.connectAssetInfo(uuid)
2534+
const { uuid, organizationUuid, ip } = data
2535+
const fallback = organizationUuid || ip ? { organizationUuid, ip } : undefined
2536+
const result = chatermDbService.connectAssetInfo(uuid, fallback)
25362537
return result
25372538
} catch (error) {
25382539
logger.error('Chaterm get asset info failed', { error: error })

src/main/storage/database.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { setCurrentUserId } from './db/connection'
66
export { ChatermDatabaseService, autoCompleteDatabaseService, setCurrentUserId }
77

88
// Export connection asset information for agent Task connection usage
9-
export async function connectAssetInfo(uuid: string): Promise<any> {
9+
export async function connectAssetInfo(uuid: string, fallback?: { organizationUuid?: string; ip?: string }): Promise<any> {
1010
const service = await ChatermDatabaseService.getInstance()
11-
return service.connectAssetInfo(uuid)
11+
return service.connectAssetInfo(uuid, fallback)
1212
}

src/main/storage/db/chaterm.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ export class ChatermDatabaseService {
240240
getKeyChainList(): any {
241241
return getKeyChainListLogic(this.db)
242242
}
243-
connectAssetInfo(uuid: string): any {
244-
return connectAssetInfoLogic(this.db, uuid)
243+
connectAssetInfo(uuid: string, fallback?: { organizationUuid?: string; ip?: string }): any {
244+
return connectAssetInfoLogic(this.db, uuid, fallback)
245245
}
246246
// @Get user host list (limited)
247247
getUserHosts(search: string, limit: number = 50): any {

src/main/storage/db/chaterm/assets.organization.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function buildBastionParentTitle(label: string | null | undefined, host: string)
5656
return name
5757
}
5858

59-
export function connectAssetInfoLogic(db: Database.Database, uuid: string): any {
59+
export function connectAssetInfoLogic(db: Database.Database, uuid: string, fallback?: { organizationUuid?: string; ip?: string }): any {
6060
try {
6161
const stmt = db.prepare(`
6262
SELECT uuid, asset_ip, asset_type, auth_type, port, username, password, key_chain_id, need_proxy, proxy_name
@@ -89,6 +89,26 @@ export function connectAssetInfoLogic(db: Database.Database, uuid: string): any
8989
;(result as any).host = (result as any).asset_ip
9090
}
9191

92+
// Fallback: uuid stale after asset refresh — look up by organizationUuid + host
93+
if (!result && fallback?.organizationUuid && fallback?.ip) {
94+
const fallbackStmt = db.prepare(`
95+
SELECT oa.hostname, oa.host, oa.bastion_comment as comment, a.asset_ip, oa.organization_uuid, oa.uuid, oa.jump_server_type,
96+
a.asset_type, a.auth_type, a.port, a.username, a.password, a.key_chain_id, a.need_proxy, a.proxy_name
97+
FROM t_organization_assets oa
98+
JOIN t_assets a ON oa.organization_uuid = a.uuid
99+
WHERE oa.organization_uuid = ? AND oa.host = ?
100+
LIMIT 1
101+
`)
102+
result = fallbackStmt.get(fallback.organizationUuid, fallback.ip)
103+
if (result) {
104+
if ((result as any).jump_server_type) {
105+
sshType = (result as any).jump_server_type
106+
} else {
107+
sshType = extractBastionType((result as any).asset_type || 'organization')
108+
}
109+
}
110+
}
111+
92112
if (!result) {
93113
return null
94114
}

src/preload/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ interface ApiType {
398398
deleteKeyChain: (data: { id: number }) => Promise<any>
399399
getKeyChainInfo: (data: { id: number }) => Promise<any>
400400
updateKeyChain: (data: { form: any }) => Promise<any>
401-
connectAssetInfo: (data: { uuid: string }) => Promise<any>
401+
connectAssetInfo: (data: { uuid: string; organizationUuid?: string; ip?: string }) => Promise<any>
402402
openBrowserWindow: (url: string) => Promise<void>
403403
connect: (connectionInfo: any) => Promise<any>
404404
forkSession: (params: { sourceConnectionId: string; newConnectionId: string; host: string; port: number; username: string }) => Promise<any>

src/preload/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ const updateKeyChain = async (data: { form: Record<string, unknown> }) => {
640640
}
641641
}
642642

643-
const connectAssetInfo = async (data: { uuid: string }) => {
643+
const connectAssetInfo = async (data: { uuid: string; organizationUuid?: string; ip?: string }) => {
644644
try {
645645
const result = await ipcRenderer.invoke('chaterm-connect-asset-info', data)
646646
return result

src/renderer/src/views/components/Ssh/sshConnect.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1515,7 +1515,15 @@ const connectSSH = async (_opts?: { isAutoReconnect?: boolean }) => {
15151515
15161516
try {
15171517
const skipAssetLookup = shouldSkipAssetLookup(props.connectData)
1518-
const assetInfo = skipAssetLookup ? null : await api.connectAssetInfo({ uuid: props.connectData.uuid })
1518+
const orgId = props.serverInfo?.organizationId
1519+
const fallbackOrgUuid = orgId && orgId !== 'personal' ? orgId : undefined
1520+
const assetInfo = skipAssetLookup
1521+
? null
1522+
: await api.connectAssetInfo({
1523+
uuid: props.connectData.uuid,
1524+
organizationUuid: fallbackOrgUuid,
1525+
ip: props.connectData.ip || props.connectData.host
1526+
})
15191527
const password = ref('')
15201528
const privateKey = ref('')
15211529
const passphrase = ref('')

0 commit comments

Comments
 (0)