scan

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 29 Imported by: 0 modules, 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 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

View Source
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"
	DetectorTFCensus     = "tfcensus"
)

Detector names, as shown in Location.Detector.

View Source
const TFCensusSchemaVersion = "1"

TFCensusSchemaVersion is the schema_version of the tfcensus inventory that TFCensusInventory reads (tfcensus schemas/inventory-v1.json).

Variables

View Source
var ErrRefNotFound = errors.New("git ref not found")

ErrRefNotFound is returned when a git ref doesn't name a commit in the repository.

View Source
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

func ExtractRef(ctx context.Context, r Runner, dir, commit, dst string) error

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 Ignored

func Ignored(rules []Ignore, p *Pin) bool

Ignored reports whether any rule drops p.

func RenovateTargetBranch added in v0.3.0

func RenovateTargetBranch(body string) (string, bool)

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

func RenovateTopic(branch string) (string, bool)

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

func RenovateTopicMatches(topic string, names ...string) bool

RenovateTopicMatches reports whether a Renovate branch topic, such as terraform-1.x or hashicorp-aws-6.x, names a dependency called one of names.

func ResolveRef added in v0.3.0

func ResolveRef(ctx context.Context, r Runner, dir, ref string) (string, error)

ResolveRef returns the commit ID that ref names in the repository containing dir.

Types

type Change added in v0.3.0

type Change struct {
	Base *Pin `json:"base"`
	Head *Pin `json:"head"`
}

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

func Diff(base, head []Pin) []Change

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) Upgrade added in v0.3.0

func (c Change) Upgrade() bool

Upgrade reports whether both sides pin one exact version of the same resolved tool and the versions differ. Whether the head is newer is left to the tool's version scheme.

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
	Path string // glob on repo/file, ** for any directories; empty matches every file
}

Ignore drops the pins of one tool, everywhere or only in files under a glob.

type Kind

type Kind string

Kind says what a pin pins.

const (
	KindTool       Kind = "tool"
	KindTFProvider Kind = "tfprovider"
	KindChart      Kind = "chart"
	KindImage      Kind = "image"
	KindAction     Kind = "action"
)

Pin kinds. Every kind but KindTool carries its own name in Pin.Tool as kind:name.

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 Match

type Match string

Match says which versions a pin value allows.

const (
	MatchExact      Match = "exact"      // 1.15.8, v1.2.3-rc.1
	MatchConstraint Match = "constraint" // ~> 1.15, >= 1.5, < 2
	MatchPrefix     Match = "prefix"     // 26, 3.14, prefix:1.2
	MatchChannel    Match = "channel"    // latest, lts, corretto-17, ref:main
)

Match values.

type Namer

type Namer interface {
	Identify(input string) (string, bool)
}

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 generic detector reads
	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
}

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"`
	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

func RenovateReport(data []byte) ([]Pin, error)

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) Resolved

func (p *Pin) Resolved() bool

Resolved reports whether the pin maps to a tool.

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

func TFCensusInventory(data []byte) (*Result, error)

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.

func (*Result) Merge added in v0.4.0

func (r *Result) Merge(o *Result)

Merge adds the repositories, pins and problems of o to r and sorts them again.

type Runner

type Runner interface {
	Run(ctx context.Context, c execx.Cmd) (*execx.Result, error)
}

Runner starts git; execx.Runner implements it.

type Scanner

type Scanner struct {
	// contains filtered or unexported fields
}

Scanner finds pins in repositories.

func New

func New(logger *slog.Logger, r Runner, n Namer, opts Options) *Scanner

New returns a scanner that lists files with git through r and names tools with n.

func (*Scanner) Scan

func (s *Scanner) Scan(ctx context.Context, roots []string) (*Result, error)

Scan finds the repositories under roots and the pins in their files.

Jump to

Keyboard shortcuts

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