mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
feat(ocm-cli): add file and keychain credential backends with auth commands (#327)
* feat(ocm-cli): add file and keychain credential backends with auth commands * feat(ocm-cli): refactor credentials into async TokenStore architecture Replace the credential-backend module with a TokenStore interface and file/keychain implementations behind an internal facade. Convert token get/set/delete to async, add env-token precedence warnings on login and logout, and surface store availability in status. Add token-store tests and helpers; remove the old credential modules and tests. Bump to 0.2.6. * fix(ocm-cli): keep tokens out of security argv and stop masking config read errors Route every macOS Keychain call through `security -i`, sending the quoted command on stdin so the token is never visible in process arguments. Reject arguments containing line breaks, which would otherwise inject additional security commands. Let unexpected state file read failures propagate so a broken config dir is reported instead of being reduced to "no manager configured", and stop consuming the install notice when reading it fails unexpectedly. --------- Co-authored-by: CS <chris@chriswritescode.dev>
This commit is contained in:
1 parent
29f154a9c3
commit
6cc50a02ed
19 files changed
+1560
-117
No files matched your search
+15
-22
@@ -1,6 +1,7 @@
|
||||
import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from 'fs'
|
||||
import { existsSync, unlinkSync } from 'fs'
|
||||
import { homedir } from 'os'
|
||||
import { dirname, join } from 'path'
|
||||
import { join } from 'path'
|
||||
import { readJsonFile, writeJsonFileAtomic } from './json-store.js'
|
||||
|
||||
export interface OcmState {
|
||||
managerUrl: string
|
||||
@@ -21,46 +22,38 @@ const STATE_DIR = join(homedir(), '.config', 'opencode-manager')
|
||||
const STATE_FILE = join(STATE_DIR, 'state.json')
|
||||
const INSTALL_NOTICE_FILE = join(STATE_DIR, 'install-notice.json')
|
||||
|
||||
export function getConfigDir(): string {
|
||||
return STATE_DIR
|
||||
}
|
||||
|
||||
export function getStatePath(): string {
|
||||
return STATE_FILE
|
||||
}
|
||||
|
||||
export function readState(): OcmState | null {
|
||||
if (!existsSync(STATE_FILE)) return null
|
||||
try {
|
||||
const raw = readFileSync(STATE_FILE, 'utf-8')
|
||||
const parsed = JSON.parse(raw) as OcmState
|
||||
if (!parsed.managerUrl) return null
|
||||
return parsed
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
const parsed = readJsonFile<OcmState>(STATE_FILE)
|
||||
return parsed?.managerUrl ? parsed : null
|
||||
}
|
||||
|
||||
export function writeState(state: OcmState): void {
|
||||
mkdirSync(dirname(STATE_FILE), { recursive: true })
|
||||
const next: OcmState = { ...state, updatedAt: Date.now() }
|
||||
writeFileSync(STATE_FILE, JSON.stringify(next, null, 2), { mode: 0o600 })
|
||||
writeJsonFileAtomic(STATE_FILE, { ...state, updatedAt: Date.now() })
|
||||
}
|
||||
|
||||
export function clearState(): void {
|
||||
if (existsSync(STATE_FILE)) {
|
||||
writeFileSync(STATE_FILE, '{}', { mode: 0o600 })
|
||||
writeJsonFileAtomic(STATE_FILE, {})
|
||||
}
|
||||
}
|
||||
|
||||
export function readInstallNotice(): InstallNotice | null {
|
||||
if (!existsSync(INSTALL_NOTICE_FILE)) return null
|
||||
let parsed: InstallNotice | null
|
||||
try {
|
||||
const raw = readFileSync(INSTALL_NOTICE_FILE, 'utf-8')
|
||||
const parsed = JSON.parse(raw) as InstallNotice
|
||||
if (!parsed.link || !parsed.binDir) return null
|
||||
return parsed
|
||||
parsed = readJsonFile<InstallNotice>(INSTALL_NOTICE_FILE)
|
||||
} catch {
|
||||
return null
|
||||
} finally {
|
||||
deleteInstallNotice()
|
||||
}
|
||||
deleteInstallNotice()
|
||||
return parsed?.link && parsed.binDir ? parsed : null
|
||||
}
|
||||
|
||||
function deleteInstallNotice(): void {
|
||||
|
||||
Reference in new issue
Block a user