report

package
v0.67.2 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package report implements `sigcomply report`: the read-only, auditor-facing snapshot tool. It walks a vault's {framework}/{period_id}/run_*/ tree and produces deterministic views of the data — no collection, no evaluation, no cloud calls.

Three views ship in v1-alpha (see docs/architecture/09-implementation- roadmap.md §`sigcomply report`):

  • latest: per-policy roll-up using the latest run that produced a result for each policy. Answers "what was the state at period close?"
  • exceptions: every waiver/NA in effect during the period, pulled from each run manifest's exceptions_applied table.
  • integrity: per-run signature + file-hash verification.

Each view is independently structured and independently formattable (text, json, csv). PDF is deferred to v1.x — the formatter layer returns a clear error rather than emit a half-rendered document.

Determinism is a hard requirement: the same vault state must produce byte-identical output across invocations, modulo any "generated_at" timestamp the CLI command stamps outside the snapshot's content. Snapshot views sort every list by a stable key (policy_id, run path, etc.) before serializing.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnknownView = fmt.Errorf("report: unknown view")

ErrUnknownView is returned by Build when an unknown view string is passed. Sentinel so callers can distinguish "configuration error" from "vault read error".

Functions

func FormatCSV

func FormatCSV(w io.Writer, snap *Snapshot) error

FormatCSV writes a CSV rendering of snap to w. One row per policy for the latest view, one row per exception for the exceptions view, one row per run for the integrity view. Designed to play well with auditor spreadsheets.

The header row is the first record. CSV escaping is the standard encoding/csv behavior (RFC 4180): fields containing commas, quotes, or newlines are quoted.

func FormatJSON

func FormatJSON(w io.Writer, snap *Snapshot) error

FormatJSON writes a structured JSON rendering of snap to w. The output is indented 2-space for readability and is fully deterministic — Snapshot's content is already sorted by Build, and json.Encoder emits map keys in lexicographic order for any embedded maps.

No "generated_at" field is emitted from here; the CLI command stamps run-time metadata outside the snapshot body so tests can assert byte-identical content across invocations.

func FormatText

func FormatText(w io.Writer, snap *Snapshot) error

FormatText writes a human-readable text rendering of snap to w. Output is deterministic: no "generated_at" timestamp is emitted from here. The CLI command can prefix a header if it wants.

Format choices:

  • latest: aligned columns via tabwriter (policy_id control status severity last_evaluated exception)
  • exceptions: aligned columns (policy_id scope state approved_by approved_at expires_at reason)
  • integrity: aligned columns (run_path status files_verified/total details)

Types

type ExceptionEntry

type ExceptionEntry struct {
	PolicyID       string
	State          string
	Scope          string // resource_id, resource_pattern, or "policy"
	ApprovedBy     string
	ApprovedAt     string
	ExpiresAt      string
	Reason         string
	FirstSeenRunID string
	LastSeenRunID  string
}

ExceptionEntry is one row of the exceptions register. Fields mirror core.AppliedException — duplicated here so the report's data model is self-contained and not coupled to the manifest schema.

type ExceptionsView

type ExceptionsView struct {
	Exceptions []ExceptionEntry
}

ExceptionsView is the centralized register of every waiver/NA in effect during the period, deduplicated across runs by policy_id + resource_id + resource_pattern. The order of runs is preserved so readers can trace which run first/last applied a given exception.

type Input

type Input struct {
	Vault     core.Vault
	Framework string
	PeriodID  string
	View      View
}

Input is the parameter bundle for Build. Vault is read-only; Build never writes.

type IntegrityRow

type IntegrityRow struct {
	RunPath           string
	RunID             string
	CompletedAt       time.Time
	SignatureValid    bool
	FilesVerified     int
	FilesTotal        int
	FirstMismatchPath string
	Error             string // populated when SignatureValid is false or a file is missing
}

IntegrityRow records the outcome of integrity verification for one run folder.

func (*IntegrityRow) Status

func (r *IntegrityRow) Status() string

Status returns "pass" if the run's signature verifies and every file_hashes entry matched its recomputed SHA-256; "fail" otherwise. Centralizing the boolean → label mapping lets every formatter render the same word.

type IntegrityView

type IntegrityView struct {
	Runs []IntegrityRow
}

IntegrityView is the per-run signature + file-hash verification table. Rows are sorted by run path (which sorts by timestamp in ISO 8601 basic form) so the output is reproducible.

type LatestPolicy

type LatestPolicy struct {
	PolicyID      string
	ControlID     string
	Status        string
	Severity      string
	Category      string
	LastEvaluated time.Time
	RunID         string
	// ExceptionID, when non-empty, points at the policy_id of the
	// exception that suppressed this result (waived/na). The free-CLI
	// design uses the policy_id as the exception's primary key — the
	// exceptions view is the place to look up details.
	ExceptionID string
}

LatestPolicy is one row of the latest-wins view.

type LatestView

type LatestView struct {
	Policies []LatestPolicy
}

LatestView is the latest-wins per-policy roll-up for the period. One row per policy that appears in any run in the period folder; for policies that appear in multiple runs, the row reflects the latest run (by manifest.completed_at) that produced a result for that policy.

type ScopeSource added in v0.67.0

type ScopeSource struct {
	SourceID string
	State    string
}

ScopeSource is one declared source and how it fared.

type ScopeView added in v0.67.0

type ScopeView struct {
	// Declared reports whether the run carried an estate declaration.
	// False for runs written before scope existed, and for projects that
	// have not opted in.
	Declared bool
	// Status is the run-level verdict: complete, incomplete, or empty
	// when nothing was declared.
	Status string
	// DeclaredBy/DeclaredAt are the operator's audit trail.
	DeclaredBy string
	DeclaredAt string
	// RunID is the run this verdict came from — the latest in the period.
	RunID string

	// Sources is one row per declared source, sorted by ID.
	Sources []ScopeSource
	// Skipped is one row per unevaluated control, sorted by policy ID.
	Skipped []SkippedPolicy
}

ScopeView answers "what was this run supposed to cover, and did it?"

Two independent things live here because they answer the same auditor question from opposite ends. Sources is the estate the operator declared and how each declared entry actually fared — present only for projects that opted in by declaring one. Skipped is every control the run did not evaluate, with the reason, which is available for every project whether or not an estate was declared.

The second matters on its own: a skipped control leaves the compliance-score denominator entirely, so a run can go green while quietly evaluating nothing.

type SkippedPolicy added in v0.67.0

type SkippedPolicy struct {
	PolicyID string
	Status   string
	Reason   string
}

SkippedPolicy is one control the run did not evaluate.

type Snapshot

type Snapshot struct {
	View      View
	Framework string
	PeriodID  string

	Latest     *LatestView     `json:",omitempty"`
	Exceptions *ExceptionsView `json:",omitempty"`
	Integrity  *IntegrityView  `json:",omitempty"`
	Scope      *ScopeView      `json:",omitempty"`
}

Snapshot is the top-level result of Build. Exactly one of the per-view sub-structs is populated based on the requested view; the other fields are zero-valued.

GeneratedAt is excluded from the formatted body — it lives on the header that the CLI command stamps separately so tests can assert byte-identical content across invocations.

func Build

func Build(ctx context.Context, in *Input) (*Snapshot, error)

Build walks the vault for the requested {framework}/{period_id} subtree and returns a Snapshot for the chosen view.

Build is strictly read-only: it lists run folders, parses each manifest, and (for the latest view) reads per-policy result.json files. It never writes, never opens network connections, and never requires OIDC.

type View

type View string

View names the requested snapshot kind. Surfaced as the --view flag on the CLI.

const (
	ViewLatest     View = "latest"
	ViewExceptions View = "exceptions"
	ViewIntegrity  View = "integrity"
	ViewScope      View = "scope"
)

Supported views. See package doc for the auditor question each answers.

Jump to

Keyboard shortcuts

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