config

package
v0.4.1 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: 8 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 config reads the repo-side hint file and combines it with the operator's settings. The operator always wins, and every exclusion, from either side, is recorded in the scan output so a reader can see what was left out and who decided it.

Index

Constants

View Source
const (
	ByRepo     = "repo"
	ByOperator = "operator"
)
View Source
const (
	GateNewOutsideParty      = "new_outside_party"
	GateNewSensitiveColumn   = "new_sensitive_column"
	GateNewUnpinnedImage     = "new_unpinned_image"
	GateNewProductionStack   = "new_production_stack"
	GateNewDependency        = "new_dependency"
	GateNewTransitive        = "new_transitive_dependency"
	GateLicenceNotAllowed    = "licence_not_allowed"
	GateNewAnonymousEndpoint = "new_anonymous_public_endpoint"
	GateLoosened             = "gate_loosened"

	LevelOff   = "off"
	LevelWarn  = "warn"
	LevelBlock = "block"
)

Gate rules and levels. The rules package applies them; the names live here so the hint file can be checked when it is read.

View Source
const FileName = ".cernly.yml"

FileName is the repo-side hint file, read only when tracked by git.

Variables

GateRules lists every gate rule, in report order.

View Source
var TagKey = regexp.MustCompile(`^[a-z][a-z0-9_.-]{0,62}$`)

TagKey is the form of a tag key: lower case, starting with a letter.

Functions

func GateDefault

func GateDefault(rule string) string

GateDefault is a rule's level when no side names it: warn, except new_transitive_dependency, which is off (one direct dependency can bring dozens of transitive ones).

func HintFile

func HintFile(has func(string) bool, fallbacks []string) (name string, ignored []string)

HintFile picks the hint file a commit uses: FileName when tracked, else the first tracked name in fallbacks (further file names a caller may read, in order, when .cernly.yml is absent; see Operator.HintFallbacks). ignored lists the tracked fallbacks the chosen file overrides.

func LevelRank

func LevelRank(level string) int

LevelRank orders the levels: a higher rank is stricter.

func Matches

func Matches(pattern, file string) bool

Matches reports whether a pattern covers a repo-relative file: the pattern matches the file itself or one of its parent folders, so `examples` covers everything under examples/.

Dynamic programming over (pattern segment, name segment): row i, column j says whether p[:i] matches n[:j]. Linear in each, however many `**`.

func ValidPattern

func ValidPattern(p string) error

ValidPattern accepts repo-relative glob patterns with forward slashes. `**` matches any number of folders; other segments use path.Match syntax.

func ValidTag

func ValidTag(key, value string) error

ValidTag checks a tag; the value is trimmed by the caller.

Types

type Operator

type Operator struct {
	Exclude      []string // extra exclusions
	Include      []string // re-include paths a repo rule excluded
	NoRepoConfig bool     // ignore the repo file entirely (recorded)
	File         []byte   // the operator's configuration file (--config), same keys as the hint file
	FileName     string
	// HintFallbacks are further file names a caller may read, in order, when
	// .cernly.yml is absent. Not a command-line flag.
	HintFallbacks []string
}

Operator holds the scanner-side settings. They override the repo file.

type Plan

type Plan struct {
	Record fact.ScanConfig
	// contains filtered or unexported fields
}

Plan is the combined decision for one scan.

func Build

func Build(repoData []byte, op Operator) (Plan, error)

Build combines repo rules and operator settings. repoData is nil when the hint file is not tracked.

func BuildFrom

func BuildFrom(repoFile string, repoData []byte, op Operator) (Plan, error)

BuildFrom is Build for a hint file under the given name (see HintFile).

func (*Plan) Apply

func (pl *Plan) Apply(files []string) (keep []string)

Apply decides which of the tracked files stay visible and fills the record with, per rule, how many files it removed. The hint file itself always stays visible.

func (*Plan) Empty

func (pl *Plan) Empty() bool

Empty reports whether the plan has nothing to record.

type Repo

type Repo struct {
	Rules   []Rule
	Domains []fact.DeclaredDomain
	Stacks  []fact.DeclaredStack
	Gate    []fact.DeclaredGate
	Tags    []fact.DeclaredTag
	Errors  []fact.LocationError
}

Repo is the parsed hint file (or the operator's file, same shape).

func ParseOperator

func ParseOperator(data []byte, name string) Repo

ParseOperator reads the operator's file, same keys as the hint file.

func ParseRepo

func ParseRepo(data []byte) Repo

ParseRepo reads the hint file. Problems never stop a scan: they are returned as errors and the offending entry is skipped.

version: 1
exclude:
  - path: cmd/tool/testdata
    reason: test fixtures
  - examples/**
domains:
  own: [acme-widgets.be, acme-labs.be]   # and their subdomains
stacks:
  default:
    role: production                      # or none
    name: UAT                             # optional display name
gate:                                     # default warn
  new_outside_party: block                # off, warn or block
  licence_not_allowed:                    # a level and a list
    level: block
    licences: [AGPL-3.0-only, GPL-3.0-only]
tags:                                     # key: value
  team: payments
  product: webshop

func ParseRepoFile

func ParseRepoFile(data []byte, name string) Repo

ParseRepoFile reads the hint file under the name the commit uses.

type Rule

type Rule struct {
	Pattern string
	Reason  string
	By      string
	Line    int // line in the hint file; 0 for operator rules
}

Rule is one exclusion pattern and where it came from.

Jump to

Keyboard shortcuts

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