component

package
v0.0.3-alpha Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 19 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidRunnerConfigLoggingLevel = errors.New("not a valid RunnerConfigLoggingLevel")
View Source
var ErrInvalidStoreType = errors.New("not a valid StoreType")

Functions

func ContextWithLogger

func ContextWithLogger(ctx context.Context, logger Logger) context.Context

ContextWithLogger returns a context with a logger in its values for reusability.

func NewDefaultPanicHandler

func NewDefaultPanicHandler() (*defaultPanicHandler, error)

NewDefaultPanicHandler returns a new default panic handler.

func NewNoopLogger

func NewNoopLogger() *noopLogger

NewNoopLogger can be used to get a NOOP Logger.

func RunEnricher

func RunEnricher(ctx context.Context, enricher Enricher, opts ...RunnerOption) error

RunEnricher runs an enricher after initialising the run context.

func RunFilter

func RunFilter(ctx context.Context, filter Filter, opts ...RunnerOption) error

RunFilter runs a filter after initialising the run context.

func RunReporter

func RunReporter(ctx context.Context, reporter Reporter, opts ...RunnerOption) error

RunReporter runs a reporter after initialising the run context.

func RunScanner

func RunScanner(ctx context.Context, scanner Scanner, opts ...RunnerOption) error

RunScanner runs a scanner after initialising the run context.

func RunTarget

func RunTarget(ctx context.Context, target Target, opts ...RunnerOption) error

RunTarget runs a target after initialising the run context.

Types

type Closer

type Closer interface {
	// Close can be implemented to gracefully close component dependencies.
	Close(context.Context) error
}

Closer allows to define behaviours to close component dependencies gracefully.

type Enricher

type Enricher interface {
	// Annotate enriches vulnerability findings by some criteria.
	Annotate(ctx context.Context, findings []*finding.VulnerabilityFinding) ([]*finding.VulnerabilityFinding, error)
}

Enricher allows enriching vulnerability findings by some criteria.

type ErrInvalidRunnerConfig

type ErrInvalidRunnerConfig struct {
	FieldName string
	Reason    string
}

ErrInvalidRunnerConfig is returned when a configuration is invalid.

func (ErrInvalidRunnerConfig) Error

func (er ErrInvalidRunnerConfig) Error() string

type ErrRunnerOption

type ErrRunnerOption struct {
	OptionName string
	Reason     string
}

ErrRunnerOption is returned when a supplied RunnerOption is not valid.

func (ErrRunnerOption) Error

func (er ErrRunnerOption) Error() string

type Filter

type Filter interface {
	// Filter returns filtered findings from the supplied ones applying some criteria.
	// It returns false if no findings have been filtered out.
	Filter(ctx context.Context, findings []*finding.VulnerabilityFinding) ([]*finding.VulnerabilityFinding, bool, error)
}

Filter allows filtering out vulnerability findings by some criteria.

type Logger

type Logger interface {
	Debug(msg string, keyvals ...any)
	Info(msg string, keyvals ...any)
	Warn(msg string, keyvals ...any)
	Error(msg string, keyvals ...any)
	With(args ...any) Logger
}

Logger exposes an slog.Logger compatible logger contract.

func LoggerFromContext

func LoggerFromContext(ctx context.Context) Logger

LoggerFromContext extracts a structured logger from the context for reusability.

type PanicHandler

type PanicHandler interface {
	// HandlePanic handles a panic and returns an optional error with a signal on whether it should be
	// fatal or not.
	HandlePanic(ctx context.Context, err any) (error, bool)
}

PanicHandler defines a generic contract for handling panics following the recover semantics.

type Reader

type Reader interface {
	// Read reads vulnerability findings from a storage.
	Read(ctx context.Context, instanceID uuid.UUID) ([]*finding.VulnerabilityFinding, error)
}

Reader allows reading vulnerability findings from a storage.

type Reporter

type Reporter interface {
	// Report reports vulnerability findings on a specified destination.
	// i.e. raises them as tickets on your favourite ticketing system.
	Report(ctx context.Context, findings []*finding.VulnerabilityFinding) error
}

Reporter advertises behaviours for reporting vulnerability findings.

type RunnerConfig

type RunnerConfig struct {
	SDKVersion    string
	ComponentName string
	InstanceID    uuid.UUID

	Logging      RunnerConfigLogging
	PanicHandler PanicHandler

	StoreConfig StoreConfig
}

RunnerConfig is used for centralised runner configuration to be shared between components. This should be extended with all related things with reliability and observability.

type RunnerConfigLogging

type RunnerConfigLogging struct {
	Level  RunnerConfigLoggingLevel
	Logger Logger
}

RunnerConfigLogging contains the configuration related with the runner logger.

type RunnerConfigLoggingLevel

type RunnerConfigLoggingLevel string

RunnerConfigLoggingLevel is used to represent log levels. ENUM(debug, info, error, warn)

const (
	// RunnerConfigLoggingLevelDebug is a RunnerConfigLoggingLevel of type debug.
	RunnerConfigLoggingLevelDebug RunnerConfigLoggingLevel = "debug"
	// RunnerConfigLoggingLevelInfo is a RunnerConfigLoggingLevel of type info.
	RunnerConfigLoggingLevelInfo RunnerConfigLoggingLevel = "info"
	// RunnerConfigLoggingLevelError is a RunnerConfigLoggingLevel of type error.
	RunnerConfigLoggingLevelError RunnerConfigLoggingLevel = "error"
	// RunnerConfigLoggingLevelWarn is a RunnerConfigLoggingLevel of type warn.
	RunnerConfigLoggingLevelWarn RunnerConfigLoggingLevel = "warn"
)

func ParseRunnerConfigLoggingLevel

func ParseRunnerConfigLoggingLevel(name string) (RunnerConfigLoggingLevel, error)

ParseRunnerConfigLoggingLevel attempts to convert a string to a RunnerConfigLoggingLevel.

func (RunnerConfigLoggingLevel) IsValid

func (x RunnerConfigLoggingLevel) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (RunnerConfigLoggingLevel) String

func (x RunnerConfigLoggingLevel) String() string

String implements the Stringer interface.

type RunnerConfigOption

type RunnerConfigOption func(*RunnerConfig) error

RunnerConfigOption can be used to override runner configuration defaults. For example overriding the default logger.

type RunnerOption

type RunnerOption func(r *runner) error

RunnerOption is used to customise the runner if the provided defaults are not enough.

func RunnerWithComponentName

func RunnerWithComponentName(name string) RunnerOption

RunnerWithComponentName allows customising the component name.

func RunnerWithInstanceID

func RunnerWithInstanceID(id uuid.UUID) RunnerOption

RunnerWithInstanceID allows customising the instance id.

func RunnerWithLogger

func RunnerWithLogger(logger Logger) RunnerOption

RunnerWithLogger allows customising the runner logger.

func RunnerWithStorer

func RunnerWithStorer(store Storer) RunnerOption

RunnerWithStorer can be used to customise the underlying storage.

type Scanner

type Scanner interface {
	// Transform transforms the raw scan data into vulnerability finding format.
	Transform(ctx context.Context) ([]*ocsf.VulnerabilityFinding, error)
}

Scanner reads a scan's result and produces vulnerability findings.

type StoreConfig

type StoreConfig struct {
	DisableStoreValidation bool
	StoreType              StoreType
	Storer                 Storer
}

StoreConfig contains store configuration.

type StoreType

type StoreType string

StoreType represents a store type ENUM(sqlite, postgresql, findings-client)

const (
	// StoreTypeSqlite is a StoreType of type sqlite.
	StoreTypeSqlite StoreType = "sqlite"
	// StoreTypePostgresql is a StoreType of type postgresql.
	StoreTypePostgresql StoreType = "postgresql"
	// StoreTypeFindingsClient is a StoreType of type findings-client.
	StoreTypeFindingsClient StoreType = "findings-client"
)

func ParseStoreType

func ParseStoreType(name string) (StoreType, error)

ParseStoreType attempts to convert a string to a StoreType.

func (StoreType) IsValid

func (x StoreType) IsValid() bool

IsValid provides a quick way to determine if the typed value is part of the allowed enumerated values

func (StoreType) String

func (x StoreType) String() string

String implements the Stringer interface.

type Storer

type Storer interface {
	Closer
	Validator
	Reader
	Updater
	Writer
}

Storer allows storing vulnerability findings in an underlying storage.

type Target

type Target interface {
	// Prepare prepares the target to be scanned.
	Prepare(ctx context.Context) error
}

Target prepares the workflow environment.

type Updater

type Updater interface {
	// Update updates existing vulnerability findings.
	Update(ctx context.Context, instanceID uuid.UUID, findings []*finding.VulnerabilityFinding) error
}

Updater allows updating vulnerability findings in an underlying storage.

type Validator

type Validator interface {
	// Validate validates the supplied vulnerability finding and returns an error if invalid.
	Validate(finding *ocsf.VulnerabilityFinding) error
}

Validator allows validating vulnerability findings by a specified criteria.

type Writer

type Writer interface {
	// Write writes non-existing vulnerability findings.
	Write(ctx context.Context, instanceID uuid.UUID, findings []*ocsf.VulnerabilityFinding) error
}

Writer allows writing non-existent vulnerability findings in an underlying storage.

Directories

Path Synopsis
examples
internal
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.
local/sqlite/sqlc/migrations
empty file used to track migrations
empty file used to track migrations

Jump to

Keyboard shortcuts

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