mirror of
https://github.com/langgenius/dify.git
synced 2026-06-01 04:00:59 -04:00
Co-authored-by: GareArc <garethcxy@dify.ai> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: L1nSn0w <l1nsn0w@qq.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Co-authored-by: gigglewang <gigglewang@dify.ai> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Co-authored-by: Xiyuan Chen <52963600+GareArc@users.noreply.github.com>
36 lines
1008 B
TypeScript
36 lines
1008 B
TypeScript
import type { TokenStore } from './store.js'
|
|
import { AsyncEntry } from '@napi-rs/keyring'
|
|
|
|
export const KEYRING_SERVICE = 'difyctl'
|
|
|
|
function username(host: string, accountId: string): string {
|
|
return `${host}::${accountId}`
|
|
}
|
|
|
|
export class KeyringBackend implements TokenStore {
|
|
async put(host: string, accountId: string, token: string): Promise<void> {
|
|
await new AsyncEntry(KEYRING_SERVICE, username(host, accountId)).setPassword(token)
|
|
}
|
|
|
|
async get(host: string, accountId: string): Promise<string | undefined> {
|
|
try {
|
|
const v = await new AsyncEntry(KEYRING_SERVICE, username(host, accountId)).getPassword()
|
|
return v ?? undefined
|
|
}
|
|
catch {
|
|
return undefined
|
|
}
|
|
}
|
|
|
|
async delete(host: string, accountId: string): Promise<void> {
|
|
try {
|
|
await new AsyncEntry(KEYRING_SERVICE, username(host, accountId)).deletePassword()
|
|
}
|
|
catch { /* missing entry is fine */ }
|
|
}
|
|
|
|
async list(_host: string): Promise<readonly string[]> {
|
|
return []
|
|
}
|
|
}
|