settings

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package settings loads a project's scanoss.json (or settings.json): the BOM rules (include/identify/ignore/remove/replace) and the skip rules (patterns and size bounds per operation). Detect finds the file and Load parses it; pkg/filter reads the skip rules straight out of it, one operation per profile.

Index

Constants

View Source
const (
	OperationScanning       = "scanning"
	OperationFingerprinting = "fingerprinting"
	OperationDependencies   = "dependencies"
)

Operation identifies which set of skip rules applies. Mirrors the operations enumerated in the scanoss.json settings schema.

View Source
const MaxRankingThreshold = 10

MaxRankingThreshold is the largest ranking threshold the settings schema accepts. Ranks observed in practice run 1..9, so a higher cap would filter nothing that 10 does not.

View Source
const MinRankingThreshold = -1

MinRankingThreshold is the smallest accepted value: -1 means "defer", which for a client-side filter is the same as off.

Variables

This section is empty.

Functions

func Detect

func Detect(dir string) string

Detect looks for a settings file in the given directory, checking "scanoss.json" then "settings.json". It returns the path of the first one found, or "" if there is none — a project without settings is the normal case, not a failure.

A file path is accepted too, and its directory is searched: a scan target can be a single file, and the settings that apply to it live alongside it.

Types

type BOM

type BOM struct {
	// Include specifies components declared to be present. Schema spelling of Identify.
	Include []BOMEntry `json:"include,omitempty"`
	// Identify specifies components that should be identified as declared dependencies
	Identify []BOMEntry `json:"identify,omitempty"`
	// Ignore specifies components that should be ignored/whitelisted in scan results
	Ignore []BOMEntry `json:"ignore,omitempty"`
	// Exclude specifies components to drop from matches. Schema spelling of Ignore.
	Exclude []BOMEntry `json:"exclude,omitempty"`
	// Remove specifies components that should be removed/blacklisted from scan results
	Remove []BOMEntry `json:"remove,omitempty"`
	// Replace specifies components that should be replaced with alternatives
	Replace []BOMEntry `json:"replace,omitempty"`
}

BOM represents the Bill of Materials section in the settings file. It contains lists of components to identify, ignore, or remove from scan results.

Two of the rules are spelled two ways, because the published scanoss.json schema and this client's own settings grew apart: the schema calls them "include" and "exclude", while this client declared "identify" and "ignore". Both spellings are read, and are folded together by IdentifyRules and IgnoreRules — which is what consumers should use rather than the fields.

func (BOM) IdentifyRules added in v0.8.1

func (b BOM) IdentifyRules() []BOMEntry

IdentifyRules returns the components the user declares are present: bom.identify and bom.include together, since the two spell one rule.

The order the two lists are joined in is not a precedence mechanism. Where several rules cover one file, the most specific one wins (see the rule scoring in the postprocess package), so a caller must not read "earlier in this slice" as "stronger".

func (BOM) IgnoreRules added in v0.8.1

func (b BOM) IgnoreRules() []BOMEntry

IgnoreRules returns the components to drop from a file's matches: bom.ignore and bom.exclude together, since the two spell one rule. The ordering caveat on IdentifyRules applies here too.

type BOMEntry

type BOMEntry struct {
	// PURL (Package URL) identifying the component. Supports glob patterns (e.g., pkg:npm/lodash@*)
	Purl string `json:"purl"`
	// Path optional file path pattern to scope this entry
	Path string `json:"path,omitempty"`
	// ReplaceWith specifies the PURL to replace with (only for Replace entries)
	ReplaceWith string `json:"replace_with,omitempty"`
}

BOMEntry represents a single BOM (Bill of Materials) entry that specifies how the scanner should handle a particular component.

type FileSnippet added in v0.8.1

type FileSnippet struct {
	// SkipHeaders skips license headers, comments and imports at the start of each file
	// when fingerprinting.
	SkipHeaders *bool `json:"skip_headers,omitempty"`
	// SkipHeadersLimit caps how many leading lines SkipHeaders may drop (0 = no cap).
	SkipHeadersLimit *int `json:"skip_headers_limit,omitempty"`
	// RankingThreshold drops matches whose component ranks worse than this. Rank is the
	// scanner's own ordering, lowest is strongest. Valid range -1..MaxRankingThreshold;
	// anything at or below 0 disables the filter.
	RankingThreshold *int `json:"ranking_threshold,omitempty"`
}

FileSnippet mirrors settings.file_snippet: the knobs that tune how files are fingerprinted and matched.

Only the ones this client acts on are declared. The rest of the section (min_snippet_hits, min_snippet_lines, ranking_enabled, honour_file_exts) tunes the matching engine, not the client, and this client does not forward scan settings to the server — so declaring them here would promise something nothing honors.

ranking_threshold is the exception that proves the rule: scanoss.py sends it to the server, which filters before reporting. Here it is applied to the result the batch scanner returns, which reports every candidate match with its rank — so the same setting reaches the same outcome without the server needing to know about it.

The fields are pointers because the schema's "unset" is a value, not an absence: skip_headers defaults to false, skip_headers_limit to 0 and ranking_threshold to 0, so a plain bool/int cannot say whether the settings file asked for that or said nothing at all. That difference is what decides whether the file overrides the command line.

type Settings

type Settings struct {
	BOM BOM `json:"bom"`
	// Settings holds the input-filtering rules (the scanoss.json "settings"
	// section). Optional.
	Settings Tuning `json:"settings,omitempty"`
}

Settings represents the scanoss settings file structure.

func Load

func Load(path string) (*Settings, error)

Load reads and parses a settings file from the given path.

func (*Settings) HasBOM

func (s *Settings) HasBOM() bool

HasBOM returns true if the settings contain any BOM entries

type SizeRule

type SizeRule struct {
	Patterns []string `json:"patterns"`
	Min      int64    `json:"min"`
	Max      int64    `json:"max"`
}

SizeRule is one entry under settings.skip.sizes.<operation>: files matching any of Patterns are skipped when smaller than Min or larger than Max (0 disables a bound).

type Skip

type Skip struct {
	Patterns SkipPatternsByOp `json:"patterns,omitempty"`
	Sizes    SkipSizesByOp    `json:"sizes,omitempty"`
}

Skip mirrors the settings.skip section of scanoss.json.

type SkipPatternsByOp

type SkipPatternsByOp struct {
	Scanning       []string `json:"scanning,omitempty"`
	Fingerprinting []string `json:"fingerprinting,omitempty"`
	Dependencies   []string `json:"dependencies,omitempty"`
}

SkipPatternsByOp mirrors settings.skip.patterns: glob patterns per operation.

type SkipSizesByOp

type SkipSizesByOp struct {
	Scanning       []SizeRule `json:"scanning,omitempty"`
	Fingerprinting []SizeRule `json:"fingerprinting,omitempty"`
	Dependencies   []SizeRule `json:"dependencies,omitempty"`
}

SkipSizesByOp mirrors settings.skip.sizes: size rules per operation.

type Tuning

type Tuning struct {
	Skip        Skip        `json:"skip,omitempty"`
	FileSnippet FileSnippet `json:"file_snippet,omitempty"`
}

Tuning mirrors the top-level settings section of scanoss.json: the input-filtering skip rules applied during file collection, and the file_snippet fingerprinting knobs.

func (Tuning) RankingThreshold added in v0.8.1

func (t Tuning) RankingThreshold() (value int, ok bool)

RankingThreshold reports the configured ranking_threshold, and whether the settings file set it at all. The value is returned as written, out-of-range included: clamping it is a decision that owes the user a warning, which belongs where there is somewhere to print one.

func (Tuning) SkipHeaders added in v0.8.1

func (t Tuning) SkipHeaders() (value, ok bool)

SkipHeaders reports the configured skip_headers value, and whether the settings file set it at all. An unset value is not "false": see the FileSnippet doc.

func (Tuning) SkipHeadersLimit added in v0.8.1

func (t Tuning) SkipHeadersLimit() (value int, ok bool)

SkipHeadersLimit reports the configured skip_headers_limit, and whether the settings file set it at all. A negative cap is meaningless — it would ask to drop fewer than zero lines — so it is reported as unset rather than passed on.

func (Tuning) SkipPatterns

func (t Tuning) SkipPatterns(operation string) []string

SkipPatterns returns the skip patterns for the given operation, or nil.

func (Tuning) SkipSizes

func (t Tuning) SkipSizes(operation string) []SizeRule

SkipSizes returns the size rules for the given operation, or nil.

Jump to

Keyboard shortcuts

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