Skip to content

Allow setting OS package driver/provider overrides via ospkg.NewScanner #10817

Description

@DmitriyLewen

Description

Trivy-as-a-library consumers cannot set OS package detection driver/provider overrides at the scanner they actually construct. ospkgDetector.NewDetector accepts WithDriver / WithProvider options (re-exposed in #10740), but that detector is created internally inside (*scanner).Scan. Consumers build ospkg.NewScanner() and pass it to local.NewService, so today there is no way to thread the options down to NewDetector without reaching into the inner constructor.

Expected behavior

ospkg.NewScanner should accept the same ospkgDetector.Option values and forward them to ospkgDetector.NewDetector when it builds the detector, using the standard functional-options pattern (no global mutable state).

Usage:

osScanner := ospkg.NewScanner(ospkgDetector.WithProvider(myProvider))
svc := local.NewService(app, osScanner, langScanner, vulnClient)

This mirrors the grpc.NewServer(opts ...ServerOption) approach, where the top-level constructor collects options and threads them down to the components it builds internally.

Background

The Commercial team consumes the upstream Scan function and needs the driver/provider overrides configurable one level up, at the scanner they construct, rather than only on the inner ospkgDetector.NewDetector.

Related

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions