Documentation
¶
Overview ¶
Package apilog captures OpenFGA HTTP traffic. It is transport-level and independent of the TUI: the playground buffers entries in a Recorder for its API Logs view, and `ofga --debug` streams them to stderr via a TraceWriter.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Transport ¶
func Transport(base http.RoundTripper, rec Sink, apiURL string, configuredHeaders []string) http.RoundTripper
Transport returns an http.RoundTripper that records each attempt into rec. It sits beneath the SDK's auth/retry chain (installed via WithBaseTransport), so it sees the fully-decorated request and the raw response, and re-wraps both body streams so the SDK's own reads are never disturbed.
apiURL is the resolved OpenFGA API endpoint. The SDK also routes out-of-band OAuth token fetches (client_credentials / private_key_jwt) through this same base transport, and those requests carry secrets (client_secret in the request body, access_token in the response body) that must never be captured. Only requests whose host matches apiURL's host are recorded; everything else passes straight through unrecorded. As defense-in-depth for deployments where the token endpoint shares a host with the API (e.g. behind a gateway), captured bodies also go through redactBody, which masks known secret field names regardless of host.
configuredHeaders names the extra headers the caller sends on API requests (--header / a profile's headers list). Those carry gateway credentials, so their values are masked in captures too.
Types ¶
type Entry ¶
type Entry struct {
Time time.Time
Method string
URL string
ReqHeaders http.Header
ReqBody []byte
Status int
StatusText string
RespHeaders http.Header
RespBody []byte
Elapsed time.Duration
RequestID string
ServerQueryDuration string
Err string
Attempt int
}
Entry is one captured HTTP attempt. Bodies are stored capped (see Transport); Err is set only on a transport-level failure, not on an HTTP error status.
type Recorder ¶
type Recorder struct {
// contains filtered or unexported fields
}
Recorder is a concurrency-safe ring buffer of the most recent entries. Add is called from HTTP goroutines; Snapshot is read from the UI goroutine.
func NewRecorder ¶
NewRecorder returns a Recorder holding at most capacity entries.
func (*Recorder) Len ¶
Len returns how many entries the buffer currently holds (0..capacity), without copying them — cheap enough to call on every render.
type Sink ¶ added in v0.267.0
type Sink interface {
Add(Entry)
}
Sink receives each captured entry as it completes. The playground buffers them in a Recorder to render its API Logs view; the CLI's --debug streams them straight to stderr through a TraceWriter. Transport talks to this interface so neither consumer has to care what the other does.
Add is called from HTTP goroutines and may run concurrently, so implementations must be safe for concurrent use.
type TraceWriter ¶ added in v0.267.0
type TraceWriter struct {
// contains filtered or unexported fields
}
TraceWriter is a Sink that formats each entry to a writer as it completes, for `ofga --debug`. Unlike Recorder it keeps nothing: the point is to show the exchange while the command is still running, so a hung or slow request is visible before the process exits.
Everything it prints has already been through Transport's redaction (Authorization and cookie headers, secret-named JSON/form fields, URL query values), and Transport only ever hands it OpenFGA API traffic — OAuth token-fetch requests, which carry the client secret and the access token, are never captured in the first place.
func NewTraceWriter ¶ added in v0.267.0
func NewTraceWriter(w io.Writer) *TraceWriter
NewTraceWriter returns a Sink that writes a human-readable trace to w.
func (*TraceWriter) Add ¶ added in v0.267.0
func (t *TraceWriter) Add(e Entry)
Add renders one exchange. Concurrent callers (a parallel batch-check, a bulk tuple write) are serialized so two traces never interleave mid-line.