Documentation
¶
Overview ¶
Package audit provides audit logging types and storage.
Index ¶
- type Entry
- type Publisher
- type Store
- type StreamStore
- func (s *StreamStore) Get(ctx context.Context, id string) (*Entry, error)
- func (s *StreamStore) List(ctx context.Context, limit int, offset int) ([]Entry, int, error)
- func (s *StreamStore) ListAll(ctx context.Context) ([]Entry, error)
- func (s *StreamStore) Write(ctx context.Context, entry Entry) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Entry ¶
type Entry struct {
// ID is the unique identifier for this audit entry.
ID string `json:"id"`
// Timestamp is when the request was processed.
Timestamp time.Time `json:"timestamp"`
// User is the authenticated subject (from JWT sub claim).
User string `json:"user"`
// Roles are the roles from the JWT token.
Roles []string `json:"roles"`
// Method is the HTTP method (GET, POST, PUT, DELETE).
Method string `json:"method"`
// Path is the request URL path.
Path string `json:"path"`
// OperationID is the OpenAPI operation ID (if available).
OperationID string `json:"operation_id,omitempty"`
// SourceIP is the client's IP address.
SourceIP string `json:"source_ip"`
// ResponseCode is the HTTP response status code.
ResponseCode int `json:"response_code"`
// DurationMs is the request processing time in milliseconds.
DurationMs int64 `json:"duration_ms"`
// TraceID is the OpenTelemetry trace ID for correlation.
TraceID string `json:"trace_id,omitempty"`
}
Entry represents a single audit log record.
type Store ¶
type Store interface {
// Write persists an audit entry.
Write(
ctx context.Context,
entry Entry,
) error
// Get retrieves a single audit entry by ID.
Get(
ctx context.Context,
id string,
) (*Entry, error)
// List retrieves audit entries with pagination.
// Returns the entries, total count, and any error.
List(
ctx context.Context,
limit int,
offset int,
) ([]Entry, int, error)
// ListAll retrieves all audit entries without pagination.
ListAll(
ctx context.Context,
) ([]Entry, error)
}
Store defines the interface for audit log persistence.
type StreamStore ¶
type StreamStore struct {
// contains filtered or unexported fields
}
StreamStore implements Store backed by a NATS JetStream stream.
func NewStreamStore ¶
func NewStreamStore( logger *slog.Logger, stream jetstream.Stream, publisher Publisher, subject string, ) *StreamStore
NewStreamStore creates a new StreamStore.
func (*StreamStore) List ¶
List retrieves audit entries with pagination, newest-first. Returns the entries, total count, and any error.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package export provides pluggable audit log export with pagination.
|
Package export provides pluggable audit log export with pagination. |
|
mocks
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
|
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
Click to show internal directories.
Click to hide internal directories.