scan

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 26 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"
)

Detector names, as shown in Location.Detector.

Variables

This section is empty.

Functions

func Detectors

func Detectors() []string

Detectors returns every detector name, sorted. renovate reads --renovate-report instead of repository files.

func Ignored

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

Ignored reports whether any rule drops p.

Types

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.

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