scanrun

package
v0.18.1 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package scanrun wraps the orchestration core of `disco scan` so the engine is reusable outside the CLI front end (cmd/scan.go). It owns:

  • resolving Scanner instances from the provider registry by name;
  • applying per-request scope (regions, services, profile, skip-globals);
  • creating the scan row and fanning out the Scan() calls in parallel;
  • finalising the scan row (Complete or Partial) based on captured errors.

CLI-only concerns (--if-older-than, --resume, --dry-run, progress rendering, --quiet) stay in cmd/scan.go. The Store's OnError / OnServiceComplete / OnResolveStart / OnResolveComplete callbacks still fire if the caller wires them — RunScanners's own OnError is only a last-resort fallback so an error returned from Scan() is captured, not dropped.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute(ctx context.Context, st *store.Store, a *Allocation) error

Execute runs the scanners attached to a, finalises the scan row, and returns a non-nil error only for store-level failures. Per-scanner errors are persisted as PartialScan; the call returns nil so the caller can exit cleanly.

func Run

func Run(ctx context.Context, st *store.Store, req Request) (string, error)

Run is the synchronous shorthand for Allocate + Execute. CLI uses this; API handler splits to surface scanID at 202 time.

func RunScanners

func RunScanners(
	ctx context.Context,
	st *store.Store,
	scanID string,
	scanners []providers.Scanner,
) (warnings []store.ScanWarning, scanErrors []store.ScanError, totalSeen, totalNew, totalChanged int)

RunScanners is the parallel fan-out core: invokes Scan() on each scanner concurrently, capturing warnings + errors and accumulating the rows-visited (totalSeen) / newly-inserted (totalNew) totals via the Store's callbacks. The caller owns the scan row lifecycle (CreateScan + Finalize) — RunScanners only writes resources via the scanners themselves.

Captured warnings/errors are returned for the caller to render (cmd/scan.go renders to stderr; the scan row's `error` column also carries the summary for later inspection); the totals feed Finalize so every entry point records the same scans.resource_count. Existing OnWarn / OnError / OnServiceComplete callbacks set by the caller still fire — RunScanners chains onto them so wiring stays additive for the CLI, and restores them before returning.

Types

type Allocation

type Allocation struct {
	ScanID string
	// contains filtered or unexported fields
}

Allocation is the handle returned by Allocate; pass it to Execute to run the scanners and finalise the scan row.

func Allocate

func Allocate(st *store.Store, req Request) (*Allocation, error)

Allocate creates a "pending" scan row and returns its ID without running any scanners. Used by the API handler to surface a scan_id at 202 time before the fan-out begins. The handler then calls Execute(scanID, req) in a background goroutine.

The returned scanners + scope are cached in the *Allocation so Execute does not re-resolve providers (which would double-apply overrides).

type FinalizeResult added in v0.10.0

type FinalizeResult struct {
	Partial      bool
	Interrupted  bool
	AppendErrors []error
}

FinalizeResult reports the outcome of finalising a scan row. AppendErrors holds non-fatal failures persisting structured per-failure entries — the CLI renders them to stderr; library callers may ignore them. Interrupted is set when the scan was finalised partial because it was signal/deadline-cancelled rather than because a service failed — the CLI uses it to print a distinct "interrupted" summary.

func Finalize added in v0.10.0

func Finalize(st *store.Store, scanID string, count int, scanErrors []store.ScanError, interrupted bool) (FinalizeResult, error)

Finalize marks the scan row complete (no errors and not interrupted) or partial (one or more scan errors, or the scan was interrupted), and on the partial path persists one structured ScanErrorEntry per failure alongside the concatenated legacy `error` blob. Single source of truth shared by Execute and cmd/scan.go so a scan is finalised identically regardless of entry point. count is the canonical rows-visited total. interrupted reflects ctx.Err() at the call site — a cancelled scan is always partial, regardless of whether any provider reported a context-canceled error (the silent semaphore-gate path reports none), so the status can't depend on timing.

type Request

type Request struct {
	// Provider names ("aws", "azure", "gcp"). Empty = all registered.
	Providers []string
	// AWS-specific override.
	Regions []string
	// AWS-specific override.
	Accounts []string
	// Azure-specific override.
	Subscriptions []string
	// GCP-specific override.
	Projects []string
	// Limit scanners to this set of services (e.g. "aws:ec2", "aws:s3").
	// Applied per provider via providers.ServiceFilterer.
	ResourceTypes []string
	// AWS named credentials profile.
	Profile string
	// Skip globally-scoped scanners (IAM, Route53, etc.) where supported.
	SkipGlobals bool
}

Request describes a scan to launch. The CLI builds one from cobra flags; the shape is deliberately serialisable so other drivers can construct it too. Empty slices mean "use the provider's default scope" — e.g. all regions for AWS.

Jump to

Keyboard shortcuts

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