fact

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 6 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package fact defines the scan output (schema cernly.scan/v1) and its canonical, deterministic encoding.

Index

Constants

View Source
const (
	KindDependency   = "dependency"
	KindService      = "service"
	KindDatastore    = "datastore"
	KindEnvVar       = "env_var"
	KindOutboundHost = "outbound_host"
	KindDBTable      = "db_table"
	KindDBColumn     = "db_column"
	KindSecretFound  = "secret_found"
	KindImageBuild   = "image_build"
	KindImageRecipe  = "image_recipe"
	KindStack        = "stack"
	KindAgentConfig  = "agent_config"
	KindRoute        = "route"
	// Ownership: who owns the repo, as the repo says it.
	KindOwner         = "owner"
	KindCatalogEntity = "catalog_entity"
	// Tests: test files per module, and the commands
	// that run them.
	KindTestSuite = "test_suite"
	KindTestRun   = "test_run"
	// Size: files and lines per folder, and imports between
	// the repo's own packages.
	KindSourceSize = "source_size"
	KindImport     = "import"
	// The HTTP endpoints the code registers, and the host-level auth policies that cover them.
	KindEndpoint   = "endpoint"
	KindAuthPolicy = "auth_policy"
)

Kinds allowed by scan.v1.schema.json.

View Source
const (
	SourceBuiltin = "builtin"
	SourceWasm    = "wasm"
)

Plugin sources. Built-in plugins are compiled into the binary; wasm plugins are loaded from signed modules and carry their hash and signer.

View Source
const SchemaID = "cernly.scan/v1"

SchemaID names the facts format in every scan.

Variables

This section is empty.

Functions

func Canonical

func Canonical(v any) ([]byte, error)

Canonical encodes v as canonical JSON: object keys sorted, no insignificant whitespace, no HTML escaping. Values in this schema are strings, booleans, integers, arrays and objects only, which keeps this equivalent to RFC 8785.

func SortedSet

func SortedSet(m map[string]bool) []any

SortedSet is the members of a set as an attr list, in sorted order.

func SortedValues

func SortedValues[V any](m map[string]V) []any

SortedValues is the values of a map as an attr list, in key order.

func Strings

func Strings(xs []string) []any

Strings converts a string slice to the []any shape attrs hold.

Types

type Commit

type Commit struct {
	SHA         string `json:"sha"`
	CommittedAt string `json:"committed_at"`
	Dirty       bool   `json:"dirty,omitempty"` // checkout with uncommitted changes; never stored
}

type Declared

type Declared struct {
	OwnDomains []DeclaredDomain `json:"own_domains,omitempty"`
	Stacks     []DeclaredStack  `json:"stacks,omitempty"`
	// Gate levels per rule, from the repo and the operator. Both sides are
	// kept: the gate takes the stricter one.
	Gate []DeclaredGate `json:"gate,omitempty"`
	// Tags on the repo: key:value labels; per key the operator's entry
	// replaces the repo's.
	Tags []DeclaredTag `json:"tags,omitempty"`
}

Declared holds what a person declared about the repo: never a fact, always shown as declared with who said it. The rules read it.

type DeclaredDomain

type DeclaredDomain struct {
	Domain string `json:"domain"`
	By     string `json:"by"`
	Line   int    `json:"line,omitempty"`
}

type DeclaredGate

type DeclaredGate struct {
	Rule  string `json:"rule"`
	Level string `json:"level"` // off, warn or block
	By    string `json:"by"`
	Line  int    `json:"line,omitempty"`
	// Licences is the licence ids licence_not_allowed watches.
	Licences []string `json:"licences,omitempty"`
}

DeclaredGate is one gate rule's level as one side declared it.

type DeclaredStack

type DeclaredStack struct {
	Stack string `json:"stack"`          // the stack's name
	Role  string `json:"role,omitempty"` // production or none
	Name  string `json:"name,omitempty"` // a display name, e.g. UAT
	By    string `json:"by"`
	Line  int    `json:"line,omitempty"`
}

type DeclaredTag

type DeclaredTag struct {
	Key   string `json:"key"`
	Value string `json:"value"`
	By    string `json:"by"`
	Line  int    `json:"line,omitempty"`
}

DeclaredTag is one key:value label on the repo.

type Evidence

type Evidence struct {
	Path    string `json:"path"`
	Line    int    `json:"line"`
	EndLine int    `json:"end_line,omitempty"`
	Unit    string `json:"unit,omitempty"`
}

type Exclusion

type Exclusion struct {
	Pattern    string `json:"pattern"`
	Reason     string `json:"reason,omitempty"`
	By         string `json:"by"`
	Line       int    `json:"line,omitempty"`
	Files      int    `json:"files"`
	Reincluded int    `json:"reincluded,omitempty"`
}

type Extractor

type Extractor struct {
	Version string `json:"version"`
}

type Fact

type Fact struct {
	Kind     string         `json:"kind"`
	Key      string         `json:"key"`
	Attrs    map[string]any `json:"attrs"`
	Plugin   string         `json:"plugin"`
	Evidence []Evidence     `json:"evidence"`
}

func (Fact) Str

func (f Fact) Str(k string) string

Str reads a string attr; any other type reads as "".

func (Fact) Strs

func (f Fact) Strs(k string) []string

Strs reads a list attr; a string attr reads as a one-item list.

type LocationError

type LocationError struct {
	Path    string `json:"path"`
	Line    int    `json:"line,omitempty"`
	Message string `json:"message"`
}

type PluginRun

type PluginRun struct {
	Name    string          `json:"name"`
	Version string          `json:"version"`
	Source  string          `json:"source"`
	SHA256  string          `json:"sha256,omitempty"`
	Signer  string          `json:"signer,omitempty"`
	Status  string          `json:"status"`
	Errors  []LocationError `json:"errors,omitempty"`
}

type Scan

type Scan struct {
	Schema    string      `json:"schema"`
	Repo      string      `json:"repo"`
	Commit    Commit      `json:"commit"`
	Extractor Extractor   `json:"extractor"`
	Config    *ScanConfig `json:"config,omitempty"`
	Plugins   []PluginRun `json:"plugins"`
	Facts     []Fact      `json:"facts"`
}

func (*Scan) Normalise

func (s *Scan) Normalise() []string

Normalise merges facts with the same (kind, key) and sorts everything into the canonical order. Two facts with the same key but different attributes are an extractor bug: the first one (in plugin output order) wins and the clash is reported, so the output never silently depends on map iteration order.

type ScanConfig

type ScanConfig struct {
	File              string          `json:"file,omitempty"`
	IgnoredByOperator bool            `json:"ignored_by_operator,omitempty"`
	Exclusions        []Exclusion     `json:"exclusions,omitempty"`
	Include           []string        `json:"include,omitempty"`
	Declared          *Declared       `json:"declared,omitempty"`
	Errors            []LocationError `json:"errors,omitempty"`
}

ScanConfig records what was excluded from a scan and who decided it: the repo's hint file or the operator. Present only when either said something.

Jump to

Keyboard shortcuts

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