mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 21:04:23 +01:00
feat(ocm-cli): workspace repo sync and manager token targeting (#233)
This commit is contained in:
1 parent
e12f319592
commit
a86e4b1238
69 files changed
+4858
-161
No files matched your search
@@ -0,0 +1,51 @@
|
||||
import { spawnSync } from 'child_process'
|
||||
|
||||
const SERVICE = 'opencode-manager'
|
||||
|
||||
export class KeychainError extends Error {
|
||||
constructor(message: string, public exitCode: number | null) {
|
||||
super(message)
|
||||
this.name = 'KeychainError'
|
||||
}
|
||||
}
|
||||
|
||||
function runSecurity(args: string[], input?: string): { stdout: string; stderr: string; code: number | null } {
|
||||
const res = spawnSync('security', args, {
|
||||
input,
|
||||
encoding: 'utf-8',
|
||||
})
|
||||
return { stdout: res.stdout ?? '', stderr: res.stderr ?? '', code: res.status }
|
||||
}
|
||||
|
||||
export function setToken(account: string, token: string): void {
|
||||
const res = runSecurity([
|
||||
'add-generic-password',
|
||||
'-s', SERVICE,
|
||||
'-a', account,
|
||||
'-w', token,
|
||||
'-U',
|
||||
])
|
||||
if (res.code !== 0) {
|
||||
throw new KeychainError(`Failed to store token in Keychain: ${res.stderr.trim()}`, res.code)
|
||||
}
|
||||
}
|
||||
|
||||
export function getToken(account: string): string | null {
|
||||
const res = runSecurity([
|
||||
'find-generic-password',
|
||||
'-s', SERVICE,
|
||||
'-a', account,
|
||||
'-w',
|
||||
])
|
||||
if (res.code !== 0) return null
|
||||
return res.stdout.trim() || null
|
||||
}
|
||||
|
||||
export function deleteToken(account: string): boolean {
|
||||
const res = runSecurity([
|
||||
'delete-generic-password',
|
||||
'-s', SERVICE,
|
||||
'-a', account,
|
||||
])
|
||||
return res.code === 0
|
||||
}
|
||||
Reference in new issue
Block a user