auditexport

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package auditexport serialises the tamper-evident audit trail into the formats a compliance pipeline consumes (Task 20167).

Three writers, one interface:

jsonl  one JSON object per line — lossless, the format to keep
csv    a flat table — the format a human opens in a spreadsheet
cef    ArcSight Common Event Format — the format a SIEM ingests

The package deliberately holds no database handle and no file handle: it writes events from a slice to an io.Writer. That keeps the format rules (which are fiddly, especially CEF's two-level escaping) testable against golden fixtures without a SQLite dependency, and lets the same code serve both the CLI's `--output file` and a future HTTP download.

Hashes are carried through every format. An export that dropped prev_hash and row_hash would be a list of claims about the past with no way to check them; carrying them means a recipient can re-run the chain verification against the export itself.

Index

Constants

This section is empty.

Variables

AllFormats lists the supported formats in the order help text shows them.

Functions

func Write

func Write(w io.Writer, events []Event, opts Options) error

Write serialises events to w in the requested format.

Types

type Event

type Event = statedb.AuditEvent

Event is the row shape being exported, re-exported so callers need not import pkg/statedb just to name the type.

type Format

type Format string

Format selects the serialisation.

const (
	// FormatJSONL writes one JSON object per line. Lossless.
	FormatJSONL Format = "jsonl"

	// FormatCSV writes a header row followed by one row per event.
	FormatCSV Format = "csv"

	// FormatCEF writes ArcSight Common Event Format records.
	FormatCEF Format = "cef"
)

func ParseFormat

func ParseFormat(s string) (Format, error)

ParseFormat resolves a user-supplied format name, case-insensitively. "json" is accepted as an alias for jsonl: it is the name people reach for, and refusing it teaches nothing.

type Options

type Options struct {
	// Format selects the serialisation. Zero value is FormatJSONL.
	Format Format

	// ProductVersion is stamped into the CEF header so a SIEM can attribute
	// a record to the binary that produced it. Ignored by the other formats.
	// Defaults to "dev" when empty.
	ProductVersion string

	// MaxPayloadBytes truncates the payload field in CEF output. CEF has no
	// formal size cap but collectors routinely drop records past a few
	// kilobytes, and a step payload can be large. 0 selects the default;
	// negative disables truncation.
	MaxPayloadBytes int
}

Options tunes an export run.

type Summary

type Summary struct {
	Format     Format
	Events     int
	FirstID    int64
	LastID     int64
	Actors     []string
	EventTypes []string
}

Summary describes an export run, for the CLI to report on stderr without polluting the exported stream on stdout.

func Summarize

func Summarize(events []Event, format Format) Summary

Summarize describes a set of events without serialising them.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL