Secrets: list all mounts and group dynamic engines by type
Adds listMounts and an engine registry (database, aws, ssh, generic fallback). The Secrets page groups mounts by engine; KV v2 keeps the path browser and dynamic mounts get a placeholder EngineView. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
eba7c97de6
commit
6daed8d388
5 files changed
+149
-24
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import type { Mount } from '../secrets'
|
||||
import { isKvV2 } from '../secrets'
|
||||
|
||||
/** Describes a dynamic secrets engine the UI can manage. Grows in later phases (role fields, creds, config). */
|
||||
export interface EngineDef {
|
||||
/** Engine type as reported by sys/mounts. */
|
||||
type: string
|
||||
label: string
|
||||
/** Path, relative to the mount, that roles are listed/written under. */
|
||||
rolesPath: string
|
||||
}
|
||||
|
||||
export const ENGINES: Record<string, EngineDef> = {
|
||||
database: { type: 'database', label: 'Database', rolesPath: 'roles' },
|
||||
aws: { type: 'aws', label: 'AWS', rolesPath: 'roles' },
|
||||
ssh: { type: 'ssh', label: 'SSH', rolesPath: 'roles' },
|
||||
}
|
||||
|
||||
/** Engine types that are managed as plain secret stores or by the system, not as dynamic engines. */
|
||||
const NOT_DYNAMIC = new Set(['kv', 'generic', 'cubbyhole', 'system', 'identity'])
|
||||
|
||||
/** Known engine definition, or a generic fallback (raw JSON roles) for any other dynamic engine type. */
|
||||
export function engineFor(type: string): EngineDef {
|
||||
return ENGINES[type] ?? { type, label: type, rolesPath: 'roles' }
|
||||
}
|
||||
|
||||
export type MountKind = 'kv' | 'dynamic'
|
||||
|
||||
/** KV v2 mounts use the path-tree browser; every other non-system engine is treated as dynamic. */
|
||||
export function mountKind(m: Mount): MountKind | null {
|
||||
if (isKvV2(m)) return 'kv'
|
||||
if (NOT_DYNAMIC.has(m.type)) return null
|
||||
return 'dynamic'
|
||||
}
|
||||
+18
-3
@@ -14,17 +14,32 @@ export interface SecretEntry {
|
||||
isFolder: boolean
|
||||
}
|
||||
|
||||
export async function listKvMounts(c: BaoClient): Promise<KvMount[]> {
|
||||
export interface Mount {
|
||||
/** Mount path with trailing slash, e.g. "database/". */
|
||||
path: string
|
||||
/** Engine type as reported by sys/mounts, e.g. "kv", "database", "aws", "ssh". */
|
||||
type: string
|
||||
/** KV version ("1" | "2") when the engine is KV. */
|
||||
version?: string
|
||||
}
|
||||
|
||||
/** Every secrets engine mount visible to the token, sorted by path. */
|
||||
export async function listMounts(c: BaoClient): Promise<Mount[]> {
|
||||
const res = await c.request<{ data: Record<string, { type: string; options?: { version?: string } | null }> }>(
|
||||
'GET',
|
||||
'sys/mounts',
|
||||
)
|
||||
return Object.entries(res.data)
|
||||
.filter(([, m]) => m.type === 'kv' && m.options?.version === '2')
|
||||
.map(([path]) => ({ path }))
|
||||
.map(([path, m]) => ({ path, type: m.type, version: m.options?.version }))
|
||||
.sort((a, b) => a.path.localeCompare(b.path))
|
||||
}
|
||||
|
||||
export const isKvV2 = (m: Mount) => m.type === 'kv' && m.version === '2'
|
||||
|
||||
export async function listKvMounts(c: BaoClient): Promise<KvMount[]> {
|
||||
return (await listMounts(c)).filter(isKvV2).map(({ path }) => ({ path }))
|
||||
}
|
||||
|
||||
/** Lists metadata only; secret values are never read. `prefix` is "" or ends with "/". */
|
||||
export async function listSecrets(c: BaoClient, mount: string, prefix: string): Promise<SecretEntry[]> {
|
||||
const keys = await c.list(`${mount}metadata/${enc(prefix)}`)
|
||||
|
||||
Reference in new issue
Block a user