scanoss

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 27 Imported by: 1 module, 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 scanoss is a Go SDK for the SCANOSS component services (cryptography, vulnerabilities, licenses, geoprovenance).

Each decoration is a grouped service on the Client; chunking the request into batches and querying those batches concurrently with a pool of workers is handled internally and is transparent to the caller:

client, err := scanoss.New(scanoss.Config{APIKey: key})
res, err := client.Vulnerabilities.Components(ctx, comps) // batch
res, err := client.Vulnerabilities.Component(ctx, comp)   // single
res, err := client.Licenses.Components(ctx, comps)
res, err := client.Cryptography.Algorithms(ctx, comps)
res, err := client.Geoprovenance.Origins(ctx, comps)

New is the only way to build a Client. Everything client-wide — credentials, endpoint, proxy and TLS, concurrency, retries — is a field of Config, whose zero value is the default configuration.

The client also exposes a batch scan service that uploads WFP fingerprints and returns match results:

res, err := client.Scan.WFP(ctx, wfp) // upload (parallel chunks) + poll

Per-call tuning stays a functional option: WithChunkBytes for the upload block size, WithScanReporter for progress, WithScanIDNotify to capture the scan id for optional recovery via Scan.Wait.

Index

Examples

Constants

View Source
const (
	DefaultAPIURL     = "https://api.scanoss.com"
	DefaultChunkSize  = 10
	DefaultWorkers    = 5
	DefaultMaxRetries = 5
	// DefaultMaxServerRetryWait caps a single Retry-After wait. It is generous because it
	// bounds a wait the server asked for; the SDK's own waits are capped by maxRetryBackoff.
	DefaultMaxServerRetryWait = 5 * time.Minute
	// DefaultRetryBackoffBase is the first backoff wait; it doubles per attempt. With
	// DefaultMaxRetries that totals under 8s of waiting before a call gives up.
	DefaultRetryBackoffBase = 250 * time.Millisecond
	// DefaultTimeout bounds one request attempt, body transfer included. Sized for the
	// largest the SDK sends — a 1 MiB WFP chunk — over a poor link.
	DefaultTimeout = 120 * time.Second
)

Defaults applied when the caller does not override them.

View Source
const DefaultScanChunkBytes = 1 << 20

Scan defaults applied when the corresponding option is not given. DefaultScanChunkBytes is the WFP upload block size (1 MiB).

View Source
const DefaultScanPollInterval = 2 * time.Second

DefaultScanPollInterval is the cadence for polling the scan status endpoint when the caller does not override it with WithPollInterval.

The server reports progress per pass, and polling samples it rather than streaming it: at a slower cadence a whole pass can come and go between two polls, leaving a progress display frozen for stretches that look like a hang.

Variables

View Source
var (
	ServiceCryptographyAlgorithms = Service{Name: "cryptography.algorithms", /* contains filtered or unexported fields */}
)

Cryptography service endpoints: algorithms and library hints, each for an exact version or a version range (plus algorithm versions in a range). Every variant has a batch (POST, many components) and a single (GET, one component) endpoint.

View Source
var (
	ServiceDependencies = Service{Name: "dependencies", /* contains filtered or unexported fields */}
)

Dependency service endpoints (v3): declared dependency + license resolution as a batch (POST, many components) and a single (GET, one component), plus a transitive walk bounded by depth and limit (POST).

View Source
var (
	ServiceGeoprovenanceOrigin = Service{Name: "geoprovenance.origin", /* contains filtered or unexported fields */}
)

Geoprovenance service endpoints: country of origin vs contributor countries, each as a batch (POST, many components) and a single (GET, one component) endpoint.

View Source
var (
	ServiceLicenses = Service{Name: "licenses", /* contains filtered or unexported fields */}
)

License service endpoints (v3):

  • attribution / evidence: LICENSE-NOTICE files and per-file license evidence.
  • the License service under /v3/licenses: declared licenses for a component (single GET / batch POST), plus SPDX-registry details and OSADL obligations keyed by license id.
View Source
var (
	ServiceVulnerabilities = Service{Name: "vulnerabilities", /* contains filtered or unexported fields */}
)

Vulnerability service endpoints: known vulnerabilities and CPEs, each as a batch (POST, many components) and a single (GET, one component) endpoint.

Functions

func SetLogger added in v0.8.0

func SetLogger(lg *slog.Logger)

SetLogger routes the SDK's diagnostics to lg — every package it is built from, not just this one. A nil lg restores silence.

The SDK logs nothing until this is called: it will not write to its consumer's stderr uninvited. Pass slog.Default() to fold its records into the application's own stream, or a handler of your own to keep them apart or drop them.

It is process-wide rather than per-client because most of this SDK is local work — filtering, fingerprinting, parsing manifests, rendering SBOMs — with no client to hang a logger off. Call it during initialisation.

Types

type ChunkError

type ChunkError struct {
	// Purls are the components left without data.
	Purls []string
	// Err is the underlying error.
	Err error
}

ChunkError records a batch of components the service never answered for. It names the components rather than the batch: chunking is this SDK's own arithmetic, so a batch number tells a caller nothing it can act on, while the PURLs say exactly which components came back without data.

func (ChunkError) Error

func (e ChunkError) Error() string

Error names the components, not just how many. Most callers only ever see this string — logged, or wrapped with %w — and a bare count is exactly what the batch index already told them.

The list is bounded because a chunk holds ChunkSize components and a caller may raise that: past the first few the full set is on Purls, rather than in every log line.

type Client

type Client struct {

	// Decoration services (grouped public API). Wired in New.
	Vulnerabilities VulnerabilityAPI
	Licenses        LicenseAPI
	Cryptography    CryptographyAPI
	Geoprovenance   GeoprovenanceAPI
	Copyright       CopyrightAPI
	Components      ComponentsAPI
	Dependencies    DependencyAPI

	// Contents service (raw source retrieval by file hash). Wired in New.
	Contents ContentsAPI

	// Scan service (batch WFP scanning). Wired in New.
	Scan ScanAPI
	// contains filtered or unexported fields
}

Client is the SCANOSS SDK entry point. Create one with New and reuse it; it is safe for concurrent use.

func New

func New(cfg Config) (*Client, error)

New creates a Client from cfg. It reports a configuration it cannot apply — an unreadable CA file, a proxy without a scheme — so a bad setting fails here instead of on the first request.

Example

Tuning chunk size and concurrency is done once at construction; the call site is unchanged.

package main

import (
	"context"

	"github.com/scanoss/scanoss.go/pkg/scanoss"
)

func main() {
	client, err := scanoss.New(scanoss.Config{
		APIKey:    "YOUR_API_KEY",
		ChunkSize: 20, // 20 PURLs per request
		Workers:   10, // up to 10 concurrent requests
	})
	if err != nil {
		panic(err)
	}

	comps := scanoss.Components("pkg:npm/lodash", "pkg:pypi/requests")

	// Each service is a single call; effective workers never exceed the chunk count.
	_, _ = client.Licenses.Attribution(context.Background(), comps)
	_, _ = client.Cryptography.Algorithms(context.Background(), comps)
	_, _ = client.Geoprovenance.Origins(context.Background(), comps)
}

func (*Client) DecorationPipeline

func (c *Client) DecorationPipeline(services ...Service) *DecorationPipeline

DecorationPipeline creates a pipeline bound to this client, seeded with the given services (deduped by name, order preserved).

Example

The pipeline runs a configurable set of decoration services in parallel over the same components, reports per-service progress, and returns one object keyed by service.

package main

import (
	"context"
	"fmt"

	"github.com/scanoss/scanoss.go/pkg/scanoss"
)

func main() {
	client, err := scanoss.New(scanoss.Config{APIKey: "YOUR_API_KEY", Workers: 10})
	if err != nil {
		panic(err)
	}

	pipe := client.DecorationPipeline(
		scanoss.ServiceVulnerabilities,
		scanoss.ServiceLicenses,
	)
	pipe.Add(scanoss.ServiceCryptographyAlgorithms, scanoss.ServiceGeoprovenanceOrigin)

	// scanoss.Components turns a list of PURLs into the []Component input.
	// The reporter travels with the call: every update carries the service that produced it, so one
	// receiver renders them all.
	res, err := pipe.Run(context.Background(),
		scanoss.Components("pkg:npm/lodash", "pkg:pypi/requests"),
		scanoss.WithDecorationReporter(serviceRows{}))
	if err != nil {
		panic(err)
	}

	fmt.Println(res.String()) // {"vulnerabilities":{...}, "licenses":{...}, ...}
	for svc, e := range res.Errors {
		fmt.Printf("%s failed: %v\n", svc, e)
	}
}

// serviceRows renders one line per decoration update. Services run concurrently, so a real
// implementation would guard whatever it draws into.
type serviceRows struct{}

func (serviceRows) Decorating(service string, done, total int) {
	fmt.Printf("%-26s %d/%d purls\n", service, done, total)
}

type Component

type Component struct {
	Purl        string `json:"purl"`
	Requirement string `json:"requirement,omitempty"`
}

Component is a single PURL (optionally pinned to a version requirement).

func Components

func Components(purls ...string) []Component

Components builds a []Component from PURL strings, with empty requirements. It accepts a slice via Components(purls...). For per-component version requirements, construct []Component{{Purl, Requirement}} directly. Blank entries are skipped.

type ComponentLimit added in v0.15.0

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

ComponentLimit says how many components the server reports for a scan: a positive number, or all of them. The zero value is unset: the scan request does not mention the limit and the server applies its own default.

func AllComponents added in v0.15.0

func AllComponents() ComponentLimit

AllComponents asks for every component, with no limit.

func ComponentsUpTo added in v0.15.0

func ComponentsUpTo(n int) (ComponentLimit, error)

ComponentsUpTo limits each match to at most n components. n must be at least 1.

func ParseComponentLimit added in v0.15.0

func ParseComponentLimit(s string) (ComponentLimit, error)

ParseComponentLimit reads the text form: exactly "all", or a base-10 positive integer with no sign and no surrounding space.

func (ComponentLimit) IsSet added in v0.15.0

func (l ComponentLimit) IsSet() bool

IsSet reports whether a limit was chosen.

func (ComponentLimit) String added in v0.15.0

func (l ComponentLimit) String() string

String is the value sent to the server, "all" or the number. It is empty when the limit is unset.

type ComponentSearch

type ComponentSearch struct {
	Search    string // free-form term; overrides Vendor/Component when set
	Vendor    string
	Component string
	PurlType  string // purl type (github, npm, pypi, …); defaults to github server-side
	Limit     int    // max results (0 = server default)
	Offset    int    // pagination offset
}

ComponentSearch holds the filters for a component search. At least one of Search, Vendor or Component must be set; Search takes precedence when present.

type ComponentsAPI

type ComponentsAPI interface {
	Search(ctx context.Context, q ComponentSearch) (*scanossapi.ComponentsSearchResponse, error)
	Versions(ctx context.Context, purl string, limit int) (*scanossapi.ComponentVersionsResponse, error)
	Releases(ctx context.Context, purl, requirement string, limit, offset int) (*scanossapi.ReleasesResponse, error)
	Status(ctx context.Context, comps []Component, opts ...DecorateOption) (*scanossapi.ComponentsStatusResponse, error)
	StatusOne(ctx context.Context, comp Component, opts ...DecorateOption) (*scanossapi.ComponentsStatusResponse, error)
}

ComponentsAPI is the components service surface. Responses are typed from the OpenAPI v3 contract.

type Config added in v0.6.0

type Config struct {
	// APIKey authenticates the requests. Empty means keyless, which the public
	// endpoint rejects and an on-prem one may allow.
	APIKey string
	// APIURL is the API base URL (default DefaultAPIURL). A trailing slash is trimmed.
	APIURL string

	// Proxy overrides HTTP_PROXY and HTTPS_PROXY for this client. It needs an http://
	// or https:// scheme; NO_PROXY still applies. Empty leaves Go's own environment
	// handling in place.
	Proxy string
	// CACertFile is a PEM file whose certificates are trusted in addition to the system
	// pool. Verification stays on: this adds an authority, it does not stop checking.
	CACertFile string
	// InsecureTLS disables certificate verification entirely. For self-signed or
	// internal endpoints only; prefer CACertFile, which keeps verification on.
	InsecureTLS bool
	// Timeout bounds one request attempt, body transfer included (default
	// DefaultTimeout). A negative value disables it. Retry-After waits happen between
	// attempts, so this does not cut them short.
	Timeout time.Duration

	// ChunkSize is the number of PURLs per decoration request (default
	// DefaultChunkSize), shared by every decoration service.
	ChunkSize int
	// Workers caps the concurrent requests (default DefaultWorkers). The effective
	// number is never larger than the number of chunks.
	Workers int
	// MaxRetries caps the retry count for a transient failure — a network error, a
	// truncated response, or a 429/5xx status (default DefaultMaxRetries). A negative
	// value disables retries; a request that fails once then fails the call.
	MaxRetries int
	// RetryBackoffBase is the first wait the SDK computes for itself, doubled per attempt
	// and capped internally (default DefaultRetryBackoffBase). A Retry-After the server
	// sent takes precedence over it.
	RetryBackoffBase time.Duration
	// MaxServerRetryWait caps a single Retry-After wait (default DefaultMaxServerRetryWait),
	// bounding a pathological server value. It does not bound RetryBackoffBase's waits.
	MaxServerRetryWait time.Duration

	// UserAgent is the caller's product token(s), e.g. "earnie/1.8.2 (deploy=hosted)".
	// The SDK appends its own "scanoss.go/<version>"; empty sends that token alone.
	UserAgent string
	// Headers are sent on every request, e.g. X-Scanoss-Client-Instance. New rejects
	// the headers the SDK sets itself: User-Agent, Content-Type, x-api-key, x-Session,
	// Content-Range and X-Scan-Id.
	Headers http.Header
	// HTTPClient, when set, sends every request instead of a client the SDK builds, so
	// a caller can wrap its transport (tracing, per-request headers). The SDK does not
	// modify it: its own Timeout, proxy and TLS settings apply, and New rejects a Config
	// that also sets Proxy, CACertFile, InsecureTLS or Timeout.
	HTTPClient *http.Client
}

Config is the SDK's configuration. The zero value is the default configuration: every unset field falls back to its Default* constant.

type ContentsAPI added in v0.16.0

type ContentsAPI interface {
	// File returns the raw text of the file with the given hash. start and end are a
	// 1-based inclusive line range; pass 0 for either to leave it at the default (line
	// 1 / the last line), so File(ctx, hash, 0, 0) returns the whole file.
	File(ctx context.Context, hash string, start, end int) ([]byte, error)
}

ContentsAPI is the raw file-content surface. It serves the source of a matched OSS file by the file_hash the scan reported for it, which the snippet classifier needs to score a match. It needs an API key with file-contents access.

type CopyrightAPI

type CopyrightAPI interface {
	Evidence(ctx context.Context, comps []Component, opts ...DecorateOption) (*scanossapi.CopyrightEvidenceResponse, error)
	Holders(ctx context.Context, comps []Component, opts ...DecorateOption) (*scanossapi.CopyrightHoldersResponse, error)
}

CopyrightAPI is the copyright service surface. Responses are typed from the OpenAPI v3 contract.

type CryptographyAPI

CryptographyAPI is the cryptography service surface: algorithms and library hints, each exact-version and version-range, plus algorithm versions in range. Responses are typed from the OpenAPI v3 contract.

type DecorateOption added in v0.5.0

type DecorateOption func(*decorateOptions)

DecorateOption configures a single decoration call. It is the decoration counterpart of ScanOption.

func WithDecorationReporter added in v0.5.0

func WithDecorationReporter(r DecorationReporter) DecorateOption

WithDecorationReporter reports this call's advance to r, service by service. Optional; by default the SDK reports nothing. Services run concurrently, so r must be safe for concurrent use.

type DecorationPipeline

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

DecorationPipeline runs a configurable set of decoration services over the same components, in parallel, and returns one result keyed by service. Create one with Client.DecorationPipeline and reuse it; configure the service set with Add/Remove.

func (*DecorationPipeline) Add

func (p *DecorationPipeline) Add(services ...Service) *DecorationPipeline

Add appends services that are not already present (dedupe by name). Chainable, so it does not validate: a service with no field on PipelineResult is skipped by Run, with a warning.

func (*DecorationPipeline) Remove

func (p *DecorationPipeline) Remove(services ...Service) *DecorationPipeline

Remove drops the named services if present. Chainable.

func (*DecorationPipeline) Run

func (p *DecorationPipeline) Run(ctx context.Context, components []Component, opts ...DecorateOption) (*PipelineResult, error)

Run queries every configured service concurrently over the same components and returns the combined result once all services have finished (success or failure). It is a barrier: Run returns only after the last service completes.

Run returns an error only if every service failed; otherwise it returns the PipelineResult with any per-service failures recorded in PipelineResult.Errors.

func (*DecorationPipeline) Services

func (p *DecorationPipeline) Services() []Service

Services returns a copy of the configured service set, in order.

type DecorationReporter added in v0.5.0

type DecorationReporter interface {
	// Decorating reports one service's advance over the components, counted in PURLs. Services run
	// concurrently, so updates from several arrive interleaved, each tagged with its own name
	// (Service.Name, e.g. "licenses" or "cryptography.algorithms").
	Decorating(service string, done, total int)
}

DecorationReporter receives enrichment progress: the components being gathered over, by service.

It is separate from ScanReporter because decoration needs no scan — an inventory parsed from a file is enriched the same way — and because there are consumers of each half alone: a command that only queries PURLs implements this and nothing else.

type DependencyAPI

type DependencyAPI interface {
	// Dependencies resolves declared dependencies + licenses for the given
	// components (batch POST).
	Dependencies(ctx context.Context, comps []Component, opts ...DecorateOption) (*scanossapi.DependenciesResolveResponse, error)
	// Dependency resolves declared dependencies for a single component (GET).
	Dependency(ctx context.Context, comp Component, opts ...DecorateOption) (*scanossapi.DependenciesResolveResponse, error)
	// Transitive walks declared dependencies bounded by depth and limit (POST).
	// depth/limit <= 0 are omitted so the server defaults apply.
	Transitive(ctx context.Context, comps []Component, depth, limit int) (*scanossapi.TransitiveResponse, error)
}

DependencyAPI is the dependencies service surface. Responses are typed from the OpenAPI v3 contract; the compiler enforces that dependencyService implements every method (see the var _ below).

type GeoprovenanceAPI

type GeoprovenanceAPI interface {
	Origins(ctx context.Context, comps []Component, opts ...DecorateOption) (*scanossapi.GeoOriginResponse, error)
	Origin(ctx context.Context, comp Component, opts ...DecorateOption) (*scanossapi.GeoOriginResponse, error)
	Countries(ctx context.Context, comps []Component, opts ...DecorateOption) (*scanossapi.GeoContributorsResponse, error)
	Country(ctx context.Context, comp Component, opts ...DecorateOption) (*scanossapi.GeoContributorsResponse, error)
}

GeoprovenanceAPI is the geoprovenance service surface: country of origin and contributor countries, each batch and single. Responses are typed from the OpenAPI v3 contract.

type Layer added in v0.7.0

type Layer[T any] struct {
	Response *T
	Failed   []ChunkError
}

Layer is an answer that arrived. Failed lists the chunks lost from it: a decoration is split into chunks, and a partial answer covers fewer components than asked for — those components read exactly like components the service had nothing to say about.

type LicenseAPI

type LicenseAPI interface {
	Attribution(ctx context.Context, comps []Component, opts ...DecorateOption) (*scanossapi.AttributionResponse, error)
	Evidence(ctx context.Context, comps []Component, opts ...DecorateOption) (*scanossapi.LicenseEvidenceResponse, error)
	Components(ctx context.Context, comps []Component, opts ...DecorateOption) (*scanossapi.ComponentsLicenseResponse, error)
	Component(ctx context.Context, comp Component, opts ...DecorateOption) (*scanossapi.ComponentLicenseResponse, error)
	Details(ctx context.Context, license string) (*scanossapi.LicenseDetailsResponse, error)
	Obligations(ctx context.Context, license string) (*scanossapi.ObligationsResponse, error)
}

LicenseAPI is the licenses service surface. Responses are typed from the OpenAPI v3 contract.

type PipelineResult

type PipelineResult struct {
	Licenses        *Layer[scanossapi.ComponentsLicenseResponse]
	Cryptography    *Layer[scanossapi.CryptoAlgorithmsResponse]
	Geoprovenance   *Layer[scanossapi.GeoOriginResponse]
	Vulnerabilities *Layer[scanossapi.VulnerabilitiesResponse]

	Errors map[string]error // service name → it failed outright, or answered unreadably
}

PipelineResult holds one layer per decoration service. A non-nil layer always carries a response; a nil one was either not requested or did not arrive — see Errors. Go cannot give a map a different value type per key, so the layers are fields rather than entries.

func (*PipelineResult) MarshalJSON

func (pr *PipelineResult) MarshalJSON() ([]byte, error)

MarshalJSON renders the result as {"<service>": <response>, …}, where each value is that service's full response object — the shape callers persisting this document already read.

func (*PipelineResult) String

func (pr *PipelineResult) String() string

String returns the pretty-printed keyed JSON.

type ScanAPI

type ScanAPI interface {
	// Folder collects, fingerprints and scans a directory tree (or single file).
	Folder(ctx context.Context, path string, opts ...ScanOption) (scanossapi.ScanEnvelope, error)

	// Files fingerprints and scans an explicit list of files.
	Files(ctx context.Context, files []string, opts ...ScanOption) (scanossapi.ScanEnvelope, error)

	// WFP scans an already-assembled WFP byte stream.
	WFP(ctx context.Context, wfp []byte, opts ...ScanOption) (scanossapi.ScanEnvelope, error)

	// WFPReader scans an already-assembled WFP read from r — WFP without the
	// in-memory requirement, for a caller whose WFP lives in a file.
	WFPReader(ctx context.Context, r io.ReaderAt, size int64, opts ...ScanOption) (scanossapi.ScanEnvelope, error)

	// Status performs a single status poll for a known scan id.
	Status(ctx context.Context, scanID string) (scanossapi.ScanEnvelope, error)

	// Wait resumes polling a known scan id until a terminal state. Used to recover
	// an interrupted scan (e.g. `scanoss-cli results <id>`). The poll cadence can be
	// tuned with WithPollInterval.
	Wait(ctx context.Context, scanID string, opts ...ScanOption) (scanossapi.ScanEnvelope, error)
}

ScanAPI is the batch scan service surface. Folder, Files, WFP and WFPReader each run the full flow — upload (parallel byte-range chunks) + poll to completion — and return the envelope with its Result populated. They differ only in the input: a directory tree, an explicit file list, or an already-assembled WFP (in memory, or read from a file). The caller never manages the scan id; stages are reported via WithScanReporter and the client-generated id is surfaced via WithScanIDNotify for optional recovery.

type ScanOption

type ScanOption func(*scanOptions)

ScanOption configures a single scan (Folder / Files / WFP).

func WithBOM

func WithBOM(bom *settings.BOM) ScanOption

WithBOM applies the scan's bill-of-materials rules to the result, post-scan and in order: bom.remove (with bom.include as precedence) neutralizes matching file matches, then bom.replace re-points the survivors it covers at their replace_with component; unreferenced components are pruned. The whole BOM is passed so the rules still to come (pre-scan include/identify context, ignore) extend this same option. A nil BOM is a no-op.

func WithBOMReport added in v0.8.1

func WithBOMReport(fn func(postprocess.Report)) ScanOption

WithBOMReport registers a callback invoked once with what the BOM selection rules concluded — today, which components a bom.identify rule claimed. It fires after the rules are applied and only when there was a result to apply them to.

It is a callback rather than a field on the returned envelope because the envelope is an API SDK type: it carries what the server said, and has nowhere to put a verdict the client reached on its own. Optional; a caller that only needs the rewritten result can ignore it.

func WithChunkBytes

func WithChunkBytes(n int) ScanOption

WithChunkBytes sets the WFP upload block size in bytes (default DefaultScanChunkBytes). Values <= 0 are ignored.

func WithFilters

func WithFilters(f filter.Options) ScanOption

WithFilters sets the file-collection filters used by Folder: default skip lists, .gitignore and size bounds. The default is filter.Scanning(nil), which leaves Settings nil — pass scanoss.json rules here to have them applied.

func WithFingerprintOptions added in v0.8.1

func WithFingerprintOptions(opts ...wfp.Option) ScanOption

WithFingerprintOptions tunes how each file is fingerprinted by Folder and Files — today, whether the leading licence header, comments and imports are dropped. They are dropped by default; wfp.WithoutSkipHeaders fingerprints files whole, and wfp.WithSkipHeaders caps how many lines go. It has no effect on WFP or WFPReader, which are handed a stream that is already assembled.

func WithMaxComponents added in v0.15.0

func WithMaxComponents(l ComponentLimit) ScanOption

WithMaxComponents asks the server to report up to l components, or all of them. For a full-file match that is the best N components of the project ranking plus up to three context picks (folder, file alone, origin), each labelled in the match's context; a snippet block gets up to N candidates, and the allowed set widens to at least N. It is sent with every WFP block of the scan, because the server refuses a session whose blocks disagree. An unset limit sends nothing and leaves the server's defaults in force.

The server must support the max_components parameter. Unlike WithRankingThreshold this is not applied client-side.

func WithPollInterval

func WithPollInterval(d time.Duration) ScanOption

WithPollInterval sets how often the scan status endpoint is polled while waiting for a scan to finish (default DefaultScanPollInterval). Values <= 0 are ignored. Very small intervals increase load on the server. Applies to the full scan flow (Folder/Files/WFP) and to Wait when resuming a known scan id.

func WithRankingThreshold added in v0.8.1

func WithRankingThreshold(threshold int) ScanOption

WithRankingThreshold drops matches whose component ranks worse than threshold, post-scan. Rank is the scanner's own ordering of how well a component explains a match, lowest is strongest; ranks seen in practice run 1..9. A threshold at or below 0 disables the filter.

It applies client-side, over the candidate matches the batch scanner reports with their ranks — nothing is asked of the server. Matches a bom.identify rule claims are never dropped by it.

func WithScanIDNotify

func WithScanIDNotify(fn func(scanID string)) ScanOption

WithScanIDNotify registers a callback invoked once with this scan's id, after the full WFP is uploaded and before polling begins — the point from which Scan.Wait can resume it. Optional; a normal scan needs no recovery.

func WithScanReporter added in v0.5.0

func WithScanReporter(r ScanReporter) ScanOption

WithScanReporter reports this scan's stages to r. Optional; by default the SDK reports nothing.

It belongs to the call rather than to the Client on purpose: a Client is long-lived and shared — a caller may hand the same one to several operations, or to a library — while an observer belongs to the one operation it is watching.

type ScanReporter added in v0.5.0

type ScanReporter interface {
	// Fingerprinting reports local hashing as files are hashed. done only ever grows.
	Fingerprinting(done, total int)

	// Uploading reports WFP blocks handed to the server. done only ever grows: it counts 1..total,
	// one call per block, and the last call carries total.
	Uploading(done, total int)

	// Scanning reports one status poll of a running scan, handing over the server's envelope
	// verbatim: the SDK does not choose which of its fields matter.
	//
	// The server scans in passes ("Pass 1: scan files", "Pass 2: scan snippets", ...) that each
	// restart PhaseDone/PhaseTotal and count something different from the last, so those counters
	// are comparable only within one Phase. A caller rendering them as a single bar must segment it
	// by Phase; feeding them straight to one bar makes it run backwards.
	//
	// Polling samples the scan rather than streaming it, so a pass shorter than the poll interval
	// is never reported at all. Whether the scan succeeded is Status, never these counters.
	Scanning(env scanossapi.ScanEnvelope)
}

ScanReporter receives the stages of scanning a source tree, one method per stage. Each reports exactly what that stage has — the local ones a count, the server one its envelope — so no update's meaning depends on which other field happens to be set.

Which stages run depends on the entry point: Scan.WFP is handed its fingerprints already made and never reports Fingerprinting, and Scan.Wait resumes an uploaded scan, so it only reports Scanning. A stage that does not run simply never calls.

Register an implementation with WithScanReporter. Methods are called from whichever goroutine reached that stage — Uploading from the upload workers, so from several — but never two at once: the SDK serialises them, and each call happens before the next. An implementation therefore needs no lock of its own. It must not block, since a slow reporter holds up the stage reporting it.

type Service

type Service struct {
	Name string // stable id, used for logging/progress tagging
	// contains filtered or unexported fields
}

Service is a pure endpoint descriptor: a stable name and a REST path. It carries no request logic, so the same value serves the batch engine (decorate), the single path (decorateOne), and any future non-component endpoint (via do). Each value is declared in its own service file (e.g. ServiceVulnerabilities). Callers use the per-service methods on Client; the engine is internal.

type StatusError

type StatusError struct {
	StatusCode int
	Body       string
}

StatusError is returned by the transport when the API responds with a non-success status (anything outside the 2xx range). It exposes the status code so callers can branch on it (e.g. distinguish 401 Unauthorized) via errors.As.

func (*StatusError) Error

func (e *StatusError) Error() string

type VulnerabilityAPI

type VulnerabilityAPI interface {
	Components(ctx context.Context, comps []Component, opts ...DecorateOption) (*scanossapi.VulnerabilitiesResponse, error)
	Component(ctx context.Context, comp Component, opts ...DecorateOption) (*scanossapi.VulnerabilitiesResponse, error)
	Cpes(ctx context.Context, comps []Component, opts ...DecorateOption) (*scanossapi.CpesResponse, error)
	Cpe(ctx context.Context, comp Component, opts ...DecorateOption) (*scanossapi.CpesResponse, error)
}

VulnerabilityAPI is the vulnerabilities service surface. Responses are typed from the OpenAPI v3 contract; the compiler enforces that vulnerabilityService implements every method (see the var _ below).

Jump to

Keyboard shortcuts

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