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
- Variables
- func GateDefault(rule string) string
- func HintFile(has func(string) bool, fallbacks []string) (name string, ignored []string)
- func LevelRank(level string) int
- func Matches(pattern, file string) bool
- func ValidPattern(p string) error
- func ValidTag(key, value string) error
- type Operator
- type Plan
- type Repo
- type Rule
Constants ¶
const ( ByRepo = "repo" ByOperator = "operator" )
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.
const FileName = ".cernly.yml"
FileName is the repo-side hint file, read only when tracked by git.
Variables ¶
var GateRules = []string{GateNewOutsideParty, GateNewSensitiveColumn, GateNewUnpinnedImage, GateNewProductionStack, GateNewDependency, GateNewTransitive, GateLicenceNotAllowed, GateNewAnonymousEndpoint, GateLoosened}
GateRules lists every gate rule, in report order.
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 ¶
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 ¶
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 Matches ¶
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 ¶
ValidPattern accepts repo-relative glob patterns with forward slashes. `**` matches any number of folders; other segments use path.Match syntax.
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 ¶
Build combines repo rules and operator settings. repoData is nil when the hint file is not tracked.
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 ¶
ParseOperator reads the operator's file, same keys as the hint file.
func ParseRepo ¶
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 ¶
ParseRepoFile reads the hint file under the name the commit uses.