Documentation
¶
Overview ¶
Package cli is the open scanner's command line: scan one commit, derive its map, serve both to AI agents over MCP, compare a scan with a base scan the caller passes, write its bill of materials, write its architecture docs. Other commands can wrap it. See https://cernly.dev/how/open-core/.
scan [--repo id] [--out file] [--commit sha] [--committed-at rfc3339] [--exclude glob]... [--include glob]... [--no-repo-config] [--config file] [--plugins dir] [--trust-key key.pub]... <dir> map [--default-branch main] [--out file] [--confirmations file] <facts.json> mcp [--default-branch main] <facts.json | dir> sbom [--default-branch main] [--service key] [--stack key] [--out file] <facts.json> gate --base <earlier.facts.json> [--default-branch main] [--format text|json|sarif] [--out file] <facts.json> docs [--default-branch main] [--out file.md] <facts.json> plugin keygen [--test] --out prefix plugin sign --key key.key --manifest manifest.json [--out dir] <module.wasm> plugin verify [--trust-key key.pub]... <dir> help | -h | --help
Usage prints the same list, built from the flag sets. The plugin commands sign and verify WebAssembly plugins.
Same commit + same binary + same operator flags = byte-identical output. The map is derived from a facts file alone: same facts + same rules version + same settings = byte-identical map.
Index ¶
- Constants
- Variables
- func BuildDocs(path, branch string, o archdoc.Options) ([]byte, error)
- func BuildSBOM(path, branch, service string) ([]byte, error)
- func BuildSBOMScope(path, branch string, sc sbom.Scope) ([]byte, error)
- func Docs(args []string)
- func Gate(args []string)
- func IsHelp(args []string) bool
- func LoadPlugins(dir string, keyFiles []string) ([]plugin.Plugin, error)
- func LoadSource(path, branch string) (*mcp.Source, error)
- func MCP(args []string)
- func Main(args []string) bool
- func Map(args []string)
- func NewFlagSet(name string, args []string) *flag.FlagSet
- func PluginCmd(args []string)
- func ReadConfirmations(path string) ([]rules.Confirmation, error)
- func ReadOperatorFile(op *config.Operator, name string)
- func RenderGate(r *rules.GateResult, format string) ([]byte, error)
- func RunGate(basePath, headPath, branch string) (*rules.GateResult, error)
- func SBOM(args []string)
- func Scan(args []string)
- func Usage(prog string, extra ...string) string
- func Write(out string, data []byte)
- type Multi
- type PluginFlags
Constants ¶
const ( GateOK = 0 GateBlocked = 1 GateError = 2 )
Gate exit codes: 0 nothing or only warnings, 1 a finding at level block, 2 an error (as flag parsing already uses).
const ( EnvPluginDir = "CERNLY_PLUGIN_DIR" // folder of <name>.wasm + <name>.plugin.json EnvPluginKeys = "CERNLY_PLUGIN_KEYS" // PEM public keys to trust, separated by the OS list separator )
Environment defaults for the plugin flags, so a program that embeds this package loads the same WebAssembly plugins as `scan`.
Variables ¶
var MapFacts = pipeline.Map
MapFacts derives a map from a facts file. A wrapping command may replace it to accept more schema ids than the open core does.
Functions ¶
func BuildSBOM ¶
BuildSBOM reads a facts file, derives its map and writes the BOM as canonical JSON.
func BuildSBOMScope ¶
BuildSBOMScope is BuildSBOM for a service or a stack.
func Docs ¶
func Docs(args []string)
Docs writes the architecture documentation of one scan as Markdown: arc42 sections, C4 context and container views in Mermaid, every statement with a footnote naming its facts, file and line.
func Gate ¶
func Gate(args []string)
Gate compares a facts file with a base facts file the caller passes and exits 1 when a finding is at level block.
func LoadPlugins ¶
LoadPlugins returns plugin.All() plus the WebAssembly plugins in dir, signed by Cernly or by one of the key files. A plugin that does not load, or that takes a built-in's name, is an error: the operator asked for it.
func LoadSource ¶
LoadSource reads a facts file, or scans a directory's HEAD, and derives the map. Scan warnings go to stderr: stdout belongs to the protocol.
func MCP ¶
func MCP(args []string)
MCP serves one scan over stdio. Given a directory it scans the commit at HEAD first, with the repo's own hint file; given a facts file it serves that file.
func NewFlagSet ¶
NewFlagSet returns the flag set of a command that exits on a parse error. Asked for help with -h or --help, it prints the flags to stdout and exits 0; a parse error still goes to stderr.
func PluginCmd ¶
func PluginCmd(args []string)
PluginCmd is `cernly plugin keygen | sign | verify`: what a plugin author needs to ship a module the scanner loads.
plugin keygen [--test] --out name writes name.key (private) and name.pub plugin sign --key name.key --manifest manifest.json [--out dir] module.wasm plugin verify --trust-key name.pub [--trust-key ...] dir
func ReadConfirmations ¶
func ReadConfirmations(path string) ([]rules.Confirmation, error)
ReadConfirmations reads a JSON array of confirmations, as a map's settings.confirmations holds them, so a map can be derived again.
func ReadOperatorFile ¶
ReadOperatorFile loads --config into the operator settings.
func RenderGate ¶
func RenderGate(r *rules.GateResult, format string) ([]byte, error)
RenderGate writes a result as text, canonical JSON or SARIF 2.1.0.
func RunGate ¶
func RunGate(basePath, headPath, branch string) (*rules.GateResult, error)
RunGate reads both facts files, derives both maps with the same settings and compares them.
func SBOM ¶
func SBOM(args []string)
SBOM writes a CycloneDX 1.6 bill of materials for one scan: the whole repo, or one service with --service.
func Scan ¶
func Scan(args []string)
Scan runs every plugin on one commit and writes the facts file.
Types ¶
type PluginFlags ¶
PluginFlags adds --plugins and --trust-key to a flag set.
func (*PluginFlags) Plugins ¶
func (pf *PluginFlags) Plugins() ([]plugin.Plugin, error)
Plugins returns the built-in plugins plus the loaded ones, sorted by name.
func (*PluginFlags) Register ¶
func (pf *PluginFlags) Register(fs *flag.FlagSet)