Documentation
¶
Overview ¶
Package scan finds the tool versions a project pins (mise, asdf, aqua, Terraform, Dockerfiles, CI files and more) and maps each raw name to a registry tool.
Index ¶
- Constants
- Variables
- func Detectors() []string
- func ExtractRef(ctx context.Context, r Runner, dir, commit, dst string) error
- func Ignored(rules []Ignore, p *Pin) bool
- func MatchName(pattern, name string) bool
- func RenovateTargetBranch(body string) (string, bool)
- func RenovateTopic(branch string) (string, bool)
- func RenovateTopicMatches(topic string, names ...string) bool
- func ResolveRef(ctx context.Context, r Runner, dir, ref string) (string, error)
- type Change
- type DetectorDoc
- type Ignore
- type Kind
- type Location
- type Match
- type Namer
- type Options
- type Pin
- type Problem
- type Result
- type Runner
- type Scanner
Constants ¶
const ( DetectorMise = "mise" DetectorToolVersions = "tool-versions" DetectorAqua = "aqua" DetectorIdiomatic = "idiomatic" DetectorTerraform = "terraform" DetectorTFLock = "tf-lock" DetectorTerragrunt = "terragrunt" DetectorDockerfile = "dockerfile" DetectorCI = "ci" DetectorHelm = "helm" DetectorGeneric = "generic" DetectorRenovate = "renovate" DetectorRenovateComment = "renovate-comment" DetectorTFCensus = "tfcensus" )
Detector names, as shown in Location.Detector.
const TFCensusSchemaVersion = "1"
TFCensusSchemaVersion is the schema_version of the tfcensus inventory that TFCensusInventory reads (tfcensus schemas/inventory-v1.json).
Variables ¶
var ErrRefNotFound = errors.New("git ref not found")
ErrRefNotFound is returned when a git ref doesn't name a commit in the repository.
var ErrTFCensusInventory = errors.New("not a tfcensus inventory relgap reads")
ErrTFCensusInventory is the error of an input that isn't a tfcensus inventory relgap reads.
Functions ¶
func Detectors ¶
func Detectors() []string
Detectors returns every detector name, sorted. renovate reads --renovate-report and tfcensus reads drift --from-tfcensus instead of repository files.
func ExtractRef ¶ added in v0.3.0
ExtractRef writes the files that commit (a full commit ID) has under dir into dst, as `git archive` lists them: tracked files only, without export-ignore paths. Files larger than the scanner reads and anything but regular files and directories are left out.
func MatchName ¶ added in v0.13.0
MatchName reports whether name matches pattern, ignoring case, where * spans any characters, slashes included, because raw names such as git::git@bitbucket.org:ws/repo.git and tool names such as npm:@scope/pkg hold them.
func RenovateTargetBranch ¶ added in v0.3.0
RenovateTargetBranch returns targetBranch from the renovate-debug comment (base64 JSON) that Renovate appends to its pull request bodies, and reports whether the body has one.
func RenovateTopic ¶ added in v0.3.0
RenovateTopic returns the branch topic of a Renovate branch name, the part after the last slash, and reports whether the name starts with Renovate's default "renovate/" prefix.
func RenovateTopicMatches ¶ added in v0.3.0
RenovateTopicMatches reports whether a Renovate branch topic, such as terraform-1.x or hashicorp-aws-6.x, names a dependency called one of names.
Types ¶
type Change ¶ added in v0.3.0
Change is a pin whose value differs between two scans of the same tree. Base is nil for a pin only the head has, Head is nil for one only the base has.
func Diff ¶ added in v0.3.0
Diff pairs the pins of two scans and returns those that changed, sorted by the head's location. Pins pair when they share repository, file, kind, tool and raw name; a value both sides have counts as unchanged. When several pins of a key change, they pair in line order if both sides have the same number, and otherwise count as removed and added.
func (Change) FloorRaise ¶ added in v0.11.0
FloorRaise returns the lower bounds of a constraint whose bound moved while its operator and every other clause stayed, such as >= 6.62.0 to >= 6.72.0, ~> 1.5 to ~> 1.7, or >= 3.6.0, < 4.0.0 to >= 3.7.0, < 4.0.0, and reports whether c is one. Each side has exactly one clause with >=, ~>, ^ or ~, and both name the same resolved tool.
type DetectorDoc ¶ added in v0.7.0
type DetectorDoc struct {
Name string `json:"name"`
Files string `json:"files"`
Pins string `json:"pins"`
Examples []string `json:"examples,omitempty"` // repository paths the detector reads
}
DetectorDoc says which files a detector reads and which pins it reports.
func DetectorDocs ¶ added in v0.7.0
func DetectorDocs() []DetectorDoc
DetectorDocs returns a DetectorDoc for each name in Detectors, in the same order.
type Ignore ¶
type Ignore struct {
Tool string // a tool name as Pin.Tool holds it
Name string // glob on Pin.RawName, ignoring case; * matches any characters, / included
Path string // glob on repo/file, ** for any directories
}
Ignore drops the pins that match every field it sets. A rule that sets none drops nothing.
type Location ¶
type Location struct {
Repo string `json:"repo"` // repository directory, slash-separated
File string `json:"file"` // relative to Repo, slash-separated
Line int `json:"line"` // 0 when the source has no lines, as in a Renovate report
Detector string `json:"detector"`
}
Location is where a pin was found.
type Namer ¶
type Namer interface {
Identify(input string) (string, bool)
Alias(input string) (string, bool) // the tool a config alias names, which wins over a lookup
}
Namer maps a raw name to a tool name and is safe for concurrent use; registry.Resolver implements it.
type Options ¶
type Options struct {
Exclude []string // globs on repository-relative paths, ** for any directories
ExtraFiles []string // globs the renovate-comment detector reads, and the generic one when Generic is set
Generic bool // run the generic detector on ExtraFiles
Actions bool // report `uses: owner/action@ref` in CI files
Submodules bool // scan checked-out submodules as repositories
Concurrency int // files read at once; 0 means 4 per CPU
Report []Pin // pins from a Renovate report, resolved and merged with the rest
Base string // when set, repositories are named relative to it, as if the scan ran there
GitLabHosts []string // self-managed GitLab hosts whose git sources become gitlab: pins
}
Options configures a Scanner.
type Pin ¶
type Pin struct {
Tool string `json:"tool"` // name `relgap digest` accepts; empty when unresolved
RawName string `json:"raw_name"` // as written: TERRAFORM_VERSION, hashicorp/aws, http:kafka
Kind Kind `json:"kind"`
Registry string `json:"registry_url,omitempty"` // a chart pin's Helm repository URL, or an npm registry other than registry.npmjs.org
Value string `json:"value"` // as written
Version string `json:"version"` // Value without a leading v or go, for comparison
Exact bool `json:"exact"`
Match Match `json:"match"`
Location Location `json:"location"`
// contains filtered or unexported fields
}
Pin is one tool version found in a file.
func RenovateReport ¶
RenovateReport reads the JSON report Renovate writes with --report-type=file. packageFiles may sit at the top level or under repositories.<name>. Unknown fields are ignored. Pins carry no line, because Renovate reports none.
func (*Pin) PrivateRegistry ¶ added in v0.13.0
PrivateRegistry reports whether the pin's package comes from a registry other than the public one, so neither that registry's public counterpart nor OSV hears about it.
type Problem ¶
type Problem struct {
Repo string `json:"repo"`
File string `json:"file"`
Message string `json:"message"`
}
Problem is a file that couldn't be parsed.
type Result ¶
type Result struct {
Repos []string `json:"repos"`
Pins []Pin `json:"pins"`
Problems []Problem `json:"-"`
}
Result is what a scan found, sorted.
func TFCensusInventory ¶ added in v0.4.0
TFCensusInventory reads the JSON of `tfcensus inventory --format json` into a repository per unit and workspace, its state and lock file versions into pins, and its errors into problems.
type Runner ¶
Runner starts git; execx.Runner implements it.