mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
The sandbox shim forwards only the plan's pinned names, so turning sandbox Git credentials off withholds tokens. Sandboxed shells resolve repo env once, terminals on linked servers get no local env, mapping keys cannot override git credentials, masks are kept per directory, and directory resolution is cached. A legacy gh-env alias keeps adopted OpenCode processes working for one release.
56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
|
import type { SecretEntry, SecretKind } from '@opencode-manager/shared/schemas'
|
|
import { deleteSecret, listSecrets, setSecret, type SecretScope } from '@/api/secrets'
|
|
|
|
interface SetSecretVariables {
|
|
kind: SecretKind
|
|
name: string
|
|
value: string
|
|
environment?: string
|
|
}
|
|
|
|
interface DeleteSecretVariables {
|
|
kind: SecretKind
|
|
name: string
|
|
environment?: string
|
|
}
|
|
|
|
function scopeKey(scope: SecretScope): string {
|
|
return scope.scope === 'global' ? 'global' : `repo:${scope.repoId}`
|
|
}
|
|
|
|
function secretsQueryKey(scope: SecretScope, kind: SecretKind) {
|
|
return ['secrets', scopeKey(scope), kind] as const
|
|
}
|
|
|
|
export function useSecretEntries(scope: SecretScope, kind: SecretKind) {
|
|
return useQuery({
|
|
queryKey: secretsQueryKey(scope, kind),
|
|
queryFn: async (): Promise<SecretEntry[]> => (await listSecrets(scope, kind)).items,
|
|
})
|
|
}
|
|
|
|
export function useSetSecret(scope: SecretScope) {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation({
|
|
mutationFn: ({ kind, name, value, environment }: SetSecretVariables) =>
|
|
setSecret(scope, kind, name, environment ? { value, environment } : { value }),
|
|
onSuccess: (_result, variables) => {
|
|
queryClient.invalidateQueries({ queryKey: secretsQueryKey(scope, variables.kind) })
|
|
},
|
|
})
|
|
}
|
|
|
|
export function useDeleteSecret(scope: SecretScope) {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation({
|
|
mutationFn: ({ kind, name, environment }: DeleteSecretVariables) =>
|
|
deleteSecret(scope, kind, name, environment),
|
|
onSuccess: (_result, variables) => {
|
|
queryClient.invalidateQueries({ queryKey: secretsQueryKey(scope, variables.kind) })
|
|
},
|
|
})
|
|
}
|