scansession

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: GPL-3.0 Imports: 5 Imported by: ? 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

type Filter struct {
	TenantID    *shared.ID
	AgentID     *shared.ID
	AssetID     *shared.ID
	ScannerName string
	AssetType   string
	AssetValue  string
	Branch      string
	Status      *Status
	Since       *time.Time
	Until       *time.Time
}

Filter defines the filter options for listing scan sessions.

type Repository

type Repository interface {
	// Create creates a new scan session.
	Create(ctx context.Context, session *ScanSession) error

	// GetByID retrieves a scan session by ID.
	GetByID(ctx context.Context, id shared.ID) (*ScanSession, error)

	// GetByTenantAndID retrieves a scan session by tenant and ID.
	GetByTenantAndID(ctx context.Context, tenantID, id shared.ID) (*ScanSession, error)

	// Update updates a scan session.
	Update(ctx context.Context, session *ScanSession) error

	// List lists scan sessions with filtering and pagination.
	List(ctx context.Context, filter Filter, page pagination.Pagination) (pagination.Result[*ScanSession], error)

	// Delete deletes a scan session by ID.
	Delete(ctx context.Context, id shared.ID) error

	// FindBaseline finds the most recent completed scan for incremental scanning.
	// Returns the baseline commit SHA from the last completed scan on the same branch/asset.
	FindBaseline(ctx context.Context, tenantID shared.ID, assetType, assetValue, branch string) (string, error)

	// GetStats returns scan session statistics for a tenant.
	GetStats(ctx context.Context, tenantID shared.ID, since time.Time) (*Stats, error)

	// ListRunning lists all running scans for a tenant.
	ListRunning(ctx context.Context, tenantID shared.ID) ([]*ScanSession, error)
}

Repository defines the interface for scan session persistence.

type ScanSession

type ScanSession struct {
	ID       shared.ID
	TenantID shared.ID
	AgentID  *shared.ID

	// Scanner info
	ScannerName    string
	ScannerVersion string
	ScannerType    string // sast, sca, secret, container, etc.

	// Asset info
	AssetType  string // repository, container, host, etc.
	AssetValue string // repo URL, image name, hostname
	AssetID    *shared.ID

	// Git context (for repository scans)
	CommitSha     string
	Branch        string
	BaseCommitSha string // Baseline commit for incremental scan

	// Status
	Status       Status
	ErrorMessage string

	// Results summary
	FindingsTotal      int
	FindingsNew        int
	FindingsFixed      int
	FindingsBySeverity map[string]int

	// Timing
	StartedAt   *time.Time
	CompletedAt *time.Time
	DurationMs  int64

	// Metadata
	Metadata map[string]any

	// Scan Profile and Quality Gate
	ScanProfileID     *shared.ID                     // Reference to the scan profile used
	QualityGateResult *scanprofile.QualityGateResult // Quality gate evaluation result

	// Audit
	CreatedAt time.Time
	UpdatedAt time.Time
}

ScanSession represents an individual scan execution from an agent. Unlike Scan (which is a configuration/definition), ScanSession tracks the actual execution lifecycle of a scan.

func NewScanSession

func NewScanSession(tenantID shared.ID, scannerName, assetType, assetValue string) (*ScanSession, error)

NewScanSession creates a new scan session.

func (*ScanSession) Cancel

func (s *ScanSession) Cancel() error

Cancel marks the scan as canceled.

func (*ScanSession) Complete

func (s *ScanSession) Complete(findingsTotal, findingsNew, findingsFixed int, findingsBySeverity map[string]int) error

Complete marks the scan as completed.

func (*ScanSession) Fail

func (s *ScanSession) Fail(errorMessage string) error

Fail marks the scan as failed.

func (*ScanSession) IsFinished

func (s *ScanSession) IsFinished() bool

IsFinished returns true if the scan has finished (completed, failed, canceled, or timeout).

func (*ScanSession) IsRunning

func (s *ScanSession) IsRunning() bool

IsRunning returns true if the scan is currently running.

func (*ScanSession) QualityGatePassed

func (s *ScanSession) QualityGatePassed() bool

QualityGatePassed returns true if quality gate passed or was not evaluated.

func (*ScanSession) Queue

func (s *ScanSession) Queue() error

Queue sets the scan to queued status (waiting for agent assignment).

func (*ScanSession) SetAgent

func (s *ScanSession) SetAgent(agentID shared.ID)

SetAgent sets the agent executing this scan.

func (*ScanSession) SetAsset

func (s *ScanSession) SetAsset(assetID shared.ID)

SetAsset links this session to an asset.

func (*ScanSession) SetGitContext

func (s *ScanSession) SetGitContext(commitSha, branch, baseCommitSha string)

SetGitContext sets git-related context.

func (*ScanSession) SetMetadata

func (s *ScanSession) SetMetadata(key string, value any)

SetMetadata sets custom metadata.

func (*ScanSession) SetQualityGateResult

func (s *ScanSession) SetQualityGateResult(result *scanprofile.QualityGateResult)

SetQualityGateResult stores the quality gate evaluation result.

func (*ScanSession) SetScanProfile

func (s *ScanSession) SetScanProfile(profileID shared.ID)

SetScanProfile links this session to a scan profile.

func (*ScanSession) SetScannerInfo

func (s *ScanSession) SetScannerInfo(version, scannerType string)

SetScannerInfo sets scanner version and type.

func (*ScanSession) Start

func (s *ScanSession) Start() error

Start marks the scan as running.

func (*ScanSession) Timeout

func (s *ScanSession) Timeout(errorMessage string) error

Timeout marks the scan as timed out.

type Stats

type Stats struct {
	Total     int64            `json:"total"`
	Pending   int64            `json:"pending"`
	Running   int64            `json:"running"`
	Completed int64            `json:"completed"`
	Failed    int64            `json:"failed"`
	Canceled  int64            `json:"canceled"`
	ByScanner map[string]int64 `json:"by_scanner"`
	ByAsset   map[string]int64 `json:"by_asset_type"`

	// Findings stats
	TotalFindings    int64 `json:"total_findings"`
	TotalFindingsNew int64 `json:"total_findings_new"`

	// Timing stats
	AvgDurationMs int64 `json:"avg_duration_ms"`
}

Stats represents scan session statistics.

type Status

type Status string

Status represents the scan session status.

const (
	StatusQueued    Status = "queued"    // Scan is queued, waiting for agent assignment
	StatusPending   Status = "pending"   // Scan is assigned to agent, waiting to start
	StatusRunning   Status = "running"   // Scan is actively running
	StatusCompleted Status = "completed" // Scan completed successfully
	StatusFailed    Status = "failed"    // Scan failed with error
	StatusCanceled  Status = "canceled"  // Scan was manually canceled
	StatusTimeout   Status = "timeout"   // Scan exceeded time limit
)

func AllStatuses

func AllStatuses() []Status

AllStatuses returns all valid statuses.

func (Status) IsActive

func (s Status) IsActive() bool

IsActive returns true if the status indicates an active/in-progress state.

func (Status) IsTerminal

func (s Status) IsTerminal() bool

IsTerminal returns true if the status is a terminal (final) state.

func (Status) IsValid

func (s Status) IsValid() bool

IsValid checks if the status is a valid status value.

func (Status) String

func (s Status) String() string

String returns the string representation of the status.

Jump to

Keyboard shortcuts

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