scans

package
v1.1.14 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const MaxScanAge = 5

MaxScanAge Max number of days a scan be in "creating checks state"

Variables

View Source
var ErrNoDefaultQueueDefined = errors.New("at least a queue with the name 'default' must be defined")

ErrNoDefaultQueueDefined is returned when the initial default queues configuration does not contain a entry with the key "default".

Functions

This section is empty.

Types

type CheckNotifier

type CheckNotifier interface {
	CheckUpdated(c api.Check, programID string)
}

CheckNotifier is used by the ChecksRunner to send notifications when a Check has ben created or sent to a queue.

type ChecksRunner

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

ChecksRunner allows to create the checks of a scan in a stateless way.

func NewJobsCreator

func NewJobsCreator(store Store,
	sender JobSender, ctinformer ChecktypeInformer, checkListener CheckNotifier, checkpoint int, l Logger) *ChecksRunner

NewJobsCreator creates and returns a new JobsCreator given its dependencies.

func (*ChecksRunner) CreateIncompleteScansChecks

func (c *ChecksRunner) CreateIncompleteScansChecks() error

CreateIncompleteScansChecks queries the db for incomplete scans. For each of those scans either it creates the pending checks or it finishes the scan in case it's older than MaxScanAge.

func (*ChecksRunner) CreateScanChecks

func (c *ChecksRunner) CreateScanChecks(id string) error

CreateScanChecks checks if a scan has still checks to be created and run, if it does, it locks the scan and creates the pending checks. The process of creating the checks of is done in a way that it can be stopped unexpectedly at any time and it will be automatically resumed using at least once semantincs.

type ChecksRunnerForTask

type ChecksRunnerForTask interface {
	CreateIncompleteScansChecks() error
}

type ChecksRunnerTask

type ChecksRunnerTask struct {
	ChecksRunnerForTask
}

ChecksRunnerTask implements a periodic check creator than can be run by the Scheduler.

func (*ChecksRunnerTask) Execute

func (c *ChecksRunnerTask) Execute() error

func (*ChecksRunnerTask) Name

func (c *ChecksRunnerTask) Name() string

func (*ChecksRunnerTask) Type

func (c *ChecksRunnerTask) Type() string

type ChecktypeInformer

type ChecktypeInformer interface {
	GetChecktype(name string) (*client.Checktype, error)
}

ChecktypeInformer defines the services required by the JobCreator type to be able to query information about checktypes.

type Job

type Job struct {
	CheckID       string            `json:"check_id"`      // Required
	ScanID        string            `json:"scan_id"`       // Required
	ScanStartTime time.Time         `json:"start_time"`    // Required
	Image         string            `json:"image"`         // Required
	Target        string            `json:"target"`        // Required
	Timeout       int               `json:"timeout"`       // Required
	AssetType     string            `json:"assettype"`     // Optional
	Options       string            `json:"options"`       // Optional
	RequiredVars  []string          `json:"required_vars"` // Optional
	Metadata      map[string]string `json:"metadata"`      // Optional
}

Job stores the information necessary to create a new check job to be sent to an agent.

func JobFromCheck

func JobFromCheck(c api.Check) (Job, error)

JobFromCheck crates a Job with the required info for a check to be run by an agent.

type JobSender

type JobSender interface {
	Send(queueName string, checktypeName string, job Job) error
}

JobSender send a job to be run by an agent.

type JobsQueueSender

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

JobsQueueSender allows to send jobs to the proper agent queue considering a map of default queues for checks.

func NewJobQueueSender

func NewJobQueueSender(sender NamedQueuesSender, defaultCTQueues map[string]string) (*JobsQueueSender, error)

NewJobQueueSender creates a new JobQueueSender given the corresponder named queues message sender and the default queue names for checktypes.

func (*JobsQueueSender) Send

func (j *JobsQueueSender) Send(queueName string, checktypeName string, job Job) error

Send sends a job to the specified queue.

type Logger

type Logger interface {
	Log(keyvals ...interface{}) error
}

type NamedQueuesSender

type NamedQueuesSender interface {
	Send(queueName string, body string) error
}

NamedQueuesSender allows to send messages to a queue given its name.

type Store

type Store interface {
	GetCreatingScans() ([]string, error)
	TryLockScan(id string) (*db.Lock, error)
	ReleaseScanLock(l *db.Lock) error
	GetScanByID(id uuid.UUID) (api.Scan, error)
	UpdateScan(id uuid.UUID, scan api.Scan, updateStates []string) (int64, error)
	InsertCheckIfNotExists(c api.Check) (string, error)
}

Store defines the methods required by the check creator to query and update checks and scans.

Jump to

Keyboard shortcuts

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