tasks

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package tasks provides tasks for submitting orphan resources discovered by Inventory as findings to the Open Delivery Gear API.

The flow for submitting findings to the Delivery Service API is as follows.

1. Fetch orphan resources from Inventory

Get the orphan resources from Inventory first, then convert them to findings, which the Delivery Service understands.

2. Wipe out old/previous findings for the artefact type

We need to delete the old/previous findings for the artefact type associated with the component name and version. This ensures no old entries exist in the database, since the Delivery Service does not have a retention mechanism for cleaning up such findings.

Also, we need to delete old/previous runtime artefacts for each finding.

3. Submit the orphan resources from step 1

The latest orphan resources fetched from step 1 are submitted to the Delivery Service API.

4. Create runtime artefacts, so that findings can be evaluated and compliance issues created or updated for them.

If we have no orphan resources to report, then we don't report anything to the remote API.

Index

Constants

View Source
const TaskReportOrphanPublicAddressGCP = "odg:task:report-orphan-ip-addresses-gcp"

TaskReportOrphanPublicAddressGCP is the name of the task, which reports orphan GCP public IP addresses as findings.

View Source
const TaskReportOrphanVirtualMachinesAWS = "odg:task:report-orphan-vms-aws"

TaskReportOrphanVirtualMachinesAWS is the name of the task, which reports orphan AWS EC2 Instances as findings.

View Source
const TaskReportOrphanVirtualMachinesAzure = "odg:task:report-orphan-vms-az"

TaskReportOrphanVirtualMachinesAzure is the name of the task, which reports orphan Azure Virtual Machines as findings.

View Source
const TaskReportOrphanVirtualMachinesGCP = "odg:task:report-orphan-vms-gcp"

TaskReportOrphanVirtualMachinesGCP is the name of the task, which reports orphan GCP Virtual Machines as findings.

View Source
const TaskReportOrphanVirtualMachinesOpenStack = "odg:task:report-orphan-vms-openstack"

TaskReportOrphanVirtualMachinesOpenStack is the name of the task, which reports orphan OpenStack Virtual Machines as findings.

Variables

View Source
var ErrNoComponentName = errors.New("no component name specified")

ErrNoComponentName is an error, which is returned by task handlers, which expect an OCM component name to be specified as part of the payload, but none was provided.

View Source
var ErrNoPayload = errors.New("no payload specified")

ErrNoPayload is an error, which is returned by task handlers, which expect a payload, but none was provided.

View Source
var ErrNoQuery = errors.New("no query specified")

ErrNoQuery is an error, which is returned by task handlers, which expect a query to be provided as part of the payload, but none was provided.

Functions

func FetchResourcesFromDB

func FetchResourcesFromDB(ctx context.Context, db *bun.DB, query string, dest any) error

FetchResourcesFromDB fetches the resources from the database using the given query into the given dest value.

func HandleReportOrphanPublicAddressGCP

func HandleReportOrphanPublicAddressGCP(ctx context.Context, t *asynq.Task) error

HandleReportOrphanPublicAddressGCP is a handler, which reports orphan GCP public IP addresses as findings.

func HandleReportOrphanVirtualMachinesAWS

func HandleReportOrphanVirtualMachinesAWS(ctx context.Context, t *asynq.Task) error

HandleReportOrphanVirtualMachinesAWS is a handler, which reports orphan AWS virtual machines as findings.

func HandleReportOrphanVirtualMachinesAzure

func HandleReportOrphanVirtualMachinesAzure(ctx context.Context, t *asynq.Task) error

HandleReportOrphanVirtualMachinesAzure is a handler, which reports orphan Azure virtual machines as findings.

func HandleReportOrphanVirtualMachinesGCP

func HandleReportOrphanVirtualMachinesGCP(ctx context.Context, t *asynq.Task) error

HandleReportOrphanVirtualMachinesGCP is a handler, which reports orphan GCP virtual machines as findings.

func HandleReportOrphanVirtualMachinesOpenStack added in v0.1.6

func HandleReportOrphanVirtualMachinesOpenStack(ctx context.Context, t *asynq.Task) error

HandleReportOrphanVirtualMachinesOpenStack is a handler, which reports orphan OpenStack virtual machines as findings.

func MaybeSkipRetry

func MaybeSkipRetry(err error) error

MaybeSkipRetry wraps known API errors with asynq.SkipRetry, so that the tasks which these errors originate from won't be retried.

Types

type Payload

type Payload struct {
	// Query represents the SQL query to use when fetching orphan resources.
	Query string `yaml:"query" json:"query"`

	// ComponentName specifies the name of the OCM component with which to
	// associate the submitted findings.
	ComponentName string `yaml:"component_name" json:"component_name"`

	// ComponentVersion specifies the version of the OCM component with
	// which to associate the submitted findings.
	ComponentVersion string `yaml:"component_version" json:"component_version"`
}

Payload represents the payload expected by tasks which report orphan resources to the Open Delivery Gear API.

func DecodePayload

func DecodePayload(t *asynq.Task) (*Payload, error)

DecodePayload decodes the payload for the given asynq.Task.

Jump to

Keyboard shortcuts

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