Documentation
¶
Overview ¶
Package manifests recognizes the files in a tree that declare or pin dependencies, and accounts for the ones a dependency scan did not read.
One list for every reader: a scanner deciding whether resolving nothing was a real answer, a scan reporting what it left unread, and `draugr init` deciding what a tree needs. Kept apart they disagree about what counts as a manifest, and each disagreement is a file one of them is silent about.
Index ¶
- func FormatOf(rel string) string
- func IsLockfile(rel string) bool
- func LicensesNotRead(packages int, command string) string
- func ParseLicensesNotRead(reason string) (packages int, command string, ok bool)
- func PomScopes(data []byte) (map[string]Scope, error)
- func ScannerLimit(reason string) bool
- type File
- type Format
- type Kind
- type Reason
- type Scope
- type Unread
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatOf ¶ added in v0.135.0
FormatOf names the format a path is, as Formats lists it, or "" for a path no rule recognizes. A member of a family named by one entry, requirements-dev.txt or pylock.dev.toml, is that entry. Content is not read, so a file that declares nothing still has a format.
func IsLockfile ¶ added in v0.147.0
IsLockfile reports whether a path is a lockfile, by the format FormatOf names for it.
func LicensesNotRead ¶ added in v0.166.1
LicensesNotRead is the reason for a dependency file whose packages a license scan read with none of their licenses. With no command, the file is all the scanner reads and it records none, as `records no licenses for 3 packages`. With one, the licenses are in a cache the command fills, as `licenses of 3 packages not read, run dotnet restore`.
func ParseLicensesNotRead ¶ added in v0.166.1
ParseLicensesNotRead reads a reason LicensesNotRead wrote back into its packages and command, and reports false for any other reason. A reason for several files is the same sentence over their packages, so a report that folds them into one row reads each one's count here.
func PomScopes ¶ added in v0.167.0
PomScopes reads the scope a pom.xml declares for each of its direct dependencies, keyed by groupId:artifactId.
A dependency with no scope of its own takes the one the same pom's dependencyManagement gives it, and a groupId written as a property is resolved from the pom's own properties and its project and parent coordinates. What this file cannot answer is left out rather than guessed: a scope managed by a parent POM or an imported BOM, a groupId held in a property only a parent defines, and a dependency declared in a profile. A dependency left out is read by the caller as runtime, the answer that keeps its findings counted.
A dependency declared more than once, with a classifier or a type apart, takes the scope that reaches furthest into production: runtime over provided, provided over test. One copy that ships is enough for its flaws to ship.
func ScannerLimit ¶ added in v0.166.1
ScannerLimit reports whether reason describes what a scanner cannot read under any setting, rather than something the reader can change. Where several scanners read one file in part, another scanner's reason is shown in place of such a reason, since it can name the act that clears the row.
Types ¶
type File ¶
type File struct {
// Path is slash-separated and relative to the root that was searched.
Path string
Ecosystem string
Kind Kind
}
File is one dependency file found in a tree.
type Format ¶ added in v0.135.0
type Format struct {
// Name is the file's base name, or `*` and a suffix for a family such as `*.csproj`.
Name string
Ecosystem string
Kind Kind
}
Format is one name of dependency file Draugr recognizes.
type Kind ¶
type Kind int
Kind separates a file that names dependencies from one that pins them.
const ( // Pinned lists exact versions, and a scanner reads packages from it directly: a lockfile, // requirements.txt, go.mod, pom.xml. Pinned Kind = iota // Declared names dependencies without resolving them, so a scanner needs the lockfile beside // it: package.json, pyproject.toml, Cargo.toml, a .csproj. Declared )
type Reason ¶
type Reason string
Reason is why a dependency file contributed no packages to a scan.
const ( // NoLockfile is a declared manifest with no lockfile beside it or above it. NoLockfile Reason = "no lockfile" // Unpinned is a requirements file whose entries name no exact version. Unpinned Reason = "no pinned versions" // NotRead is a file the scan read no packages from: a name its scanner does not read, or a // format it does not support. NotRead Reason = "no packages read" // TransitiveNotReadByGrype is a pom.xml Grype read in part. Grype reads no dependency's own pom // whatever the local Maven repository holds, so no action of the reader's clears it, and it names // none. Another scanner's reason for the same file is shown in its place (see ScannerLimit). TransitiveNotReadByGrype Reason = "transitive dependencies not read by Grype" // NoGoPackages is a go.mod whose module holds no Go package, such as a documentation site built // with Hugo, so an analysis of the module's Go code had nothing to load. NoGoPackages Reason = "no Go packages" )
func PartlyPinned ¶ added in v0.165.5
PartlyPinned is the reason a requirements file a scanner took packages from was read in part: the requirements in it with no exact version, as `1 requirement not pinned: urllib3`, or `29 requirements not pinned` past namedInReason. Trivy and Grype take a package from a requirements file only where its version is pinned with `==`.
Trivy with detectionPriority: comprehensive also takes a range at its minimum version. Where the scanner took more packages than the file pins, which requirements it passed over is not recorded, and the reason counts them, as `2 requirements not read`.
ok is false for a file that is not a requirements file or pins every requirement, for one the scanner took as many packages from as it has requirements, and for one it took none from, which Account reports.
type Scope ¶ added in v0.167.0
type Scope int
Scope is where a pom.xml puts a dependency on the classpath, folded into the three answers a finding needs: it ships with the application, it is supplied by the runtime the application is deployed into, or it is used only to build and test.
const ( // ScopeRuntime is Maven's compile and runtime scopes, a dependency written with no scope, and an // optional one: each is on the application's own runtime classpath. ScopeRuntime Scope = iota // ScopeProvided is Maven's provided and system scopes: the dependency is compiled against and // left out of what is packaged, because the server or platform the application runs in supplies // its own copy. ScopeProvided // ScopeTest is Maven's test scope: a development dependency. ScopeTest )
type Unread ¶
Unread is a dependency file a scan did not read, and why.
func Account ¶
Account returns the dependency files under root that are not in read, each with the reason it contributed nothing.
read holds slash-separated paths relative to root, as a scanner names the files it took packages from. A declared manifest resolved by a lockfile is not unread: the lockfile is what a scanner reads for it, and reporting both would warn about every project that is set up correctly.
A lockfile resolves its manifest when the walk holds it, so that it is reported itself if no scanner reads it, or when the walk left it out as the format with nothing in it. A file merely named like a lockfile does neither, because resolving on the name alone would leave the manifest and the lockfile both unreported with nothing read from either.