import { useState } from 'react' import type { BaoClient } from '../../api/bao' import { dataPath } from '../../api/secrets' import { accessForPath } from '../../model/graph' import { pathMatches } from '../../model/policy' import { CapabilityChips } from '../shared/CapabilityChips' import { useAccessInputs } from '../shared/useAccessInputs' import { GrantHere } from './GrantHere' interface Props { client: BaoClient mount: string secret: string } export function AccessPanel({ client, mount, secret }: Props) { const data = useAccessInputs(client) const path = dataPath(mount, secret) const [granting, setGranting] = useState(false) const [granted, setGranted] = useState(null) return (

{secret}

{path}
{!granting && ( )}
{granted && (

{granted}

)} {granting && data.data && ( setGranting(false)} onGranted={(message) => { setGranting(false) setGranted(message) }} /> )} {data.isPending &&

Loading access…

} {data.error &&

Could not load access: {data.error.message}

} {data.data && }
) } /** Who can reach `path`, from every identity's effective policies. */ export function Entries({ data, path, label = 'Who can access this secret', empty = 'No identity can reach this secret.', }: { data: NonNullable['data']> path: string label?: string empty?: string }) { const entries = accessForPath(data.identities, data.policies, path, pathMatches) return ( <> {data.notes.map((n) => (

Incomplete: could not read {n}

))} {entries.length === 0 ? (

{empty}

) : ( {entries.map((e) => ( ))}
Identity Via policy Can
{e.identity.name} {e.identity.kind} {e.policy}
)}

Only the most specific matching policy path applies, as in OpenBao. Parameter constraints and templated paths are approximated.

) }