persistence

package
v1.1.26 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrChecksFinishedNotInitialized is returned by the AddCheckAsFinished when trying to add
	// a check finished to its scan.
	ErrChecksFinishedNotInitialized = errors.New("field checks_finished is not initialized")
)

Functions

This section is empty.

Types

type Persistence

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

Persistence implements ScansStore interface by using the underlying document store.

func NewPersistence

func NewPersistence(s db.DB) Persistence

NewPersistence creates and initializes a store.

func (Persistence) AddCheckAsFinished

func (db Persistence) AddCheckAsFinished(checkID uuid.UUID) (int64, error)

AddCheckAsFinished mark the given check as finished in the given scan by increasing the the number the field ChecksFinished in the giver scan. The operation is idempotent That is if for a given scanID and CheckID the operation will only increase the field ChecksFinished of the scan one time, no matters the number of times it is called.

func (Persistence) Close

func (db Persistence) Close() error

Close closes the underlaying connection to the store.

func (Persistence) CreateScan

func (db Persistence) CreateScan(id uuid.UUID, scan api.Scan) (int64, error)

CreateScan creates a new scan in the database.

func (Persistence) DeleteScanChecks

func (db Persistence) DeleteScanChecks(scanID uuid.UUID) error

DeleteScanChecks deletes all the checks of a given scan.

func (Persistence) GetCheckByID

func (db Persistence) GetCheckByID(id uuid.UUID) (api.Check, error)

GetCheckByID returns the check for the given ID.

func (Persistence) GetCreatingScans

func (db Persistence) GetCreatingScans() ([]string, error)

func (Persistence) GetScanByID

func (db Persistence) GetScanByID(id uuid.UUID) (api.Scan, error)

GetScanByID returns a scan given its ID.

func (Persistence) GetScanChecks

func (db Persistence) GetScanChecks(scanID uuid.UUID) ([]api.Check, error)

GetScanChecks returns all checks of a scan.

func (Persistence) GetScanChecksByStatus

func (db Persistence) GetScanChecksByStatus(scanID uuid.UUID, status string) ([]api.Check, error)

GetScanChecksByStatus returns all checks of a scan that have the given status.

func (Persistence) GetScanIDForCheck

func (db Persistence) GetScanIDForCheck(ID uuid.UUID) (uuid.UUID, error)

func (Persistence) GetScanStats

func (db Persistence) GetScanStats(scanID uuid.UUID) (map[string]int, error)

GetScanStats returns the number of checks by status for the given scan.

func (Persistence) GetScanStatus

func (db Persistence) GetScanStatus(ID uuid.UUID) (api.Scan, error)

GetScanStatus returns a scan struct with only the fields: Status, CheckCount, ChecksFinished filled.

func (Persistence) GetScans

func (db Persistence) GetScans(offset, limit uint32) ([]api.Scan, error)

GetScans returns the list of scans.

func (Persistence) GetScansByExternalID

func (db Persistence) GetScansByExternalID(ID string, offset, limit uint32) ([]api.Scan, error)

GetScansByExternalID returns scans with a given ExternalID applying the given offset and limit.

func (Persistence) InsertCheckIfNotExists

func (db Persistence) InsertCheckIfNotExists(c api.Check) (string, error)

InsertCheckIfNotExists looks if a check exists in the database with the same ScanID and ScanIndex than the passed check. If it exists, the function returns the id of the check in the database. If it does not exist the function inserts the passed check and returns the id of the inserted check id.

func (Persistence) ReleaseScanLock

func (db Persistence) ReleaseScanLock(l *db.Lock) error

func (Persistence) TryLockScan

func (db Persistence) TryLockScan(id string) (*db.Lock, error)

func (Persistence) UpdateScan

func (db Persistence) UpdateScan(id uuid.UUID, scan api.Scan, updateStates []string) (int64, error)

UpdateScan updates a scan in the database. The data of the current scan in the db it is not replaced, but merged using json merge as is defined in the concatenate operation here: https://www.postgresql.org/docs/9.5/functions-json.html

func (Persistence) UpsertCheck

func (db Persistence) UpsertCheck(scanID, id uuid.UUID, check api.Check, updateStates []string) (int64, error)

UpsertCheck adds or updates a check of a given scan.

type ScansStore

type ScansStore interface {
	CreateScan(id uuid.UUID, scan api.Scan) (int64, error)
	UpsertCheck(scanID, id uuid.UUID, check api.Check, updateStates []string) (int64, error)
	GetScans(offset, limit uint32) ([]api.Scan, error)
	GetScanChecks(scanID uuid.UUID) ([]api.Check, error)
	GetScanChecksByStatus(scanID uuid.UUID, status string) ([]api.Check, error)
	GetScanByID(id uuid.UUID) (api.Scan, error)
	GetScanStats(scanID uuid.UUID) (map[string]int, error)
	UpdateScan(id uuid.UUID, scan api.Scan, updateStates []string) (int64, error)
	GetScansByExternalID(ID string, offset, limit uint32) ([]api.Scan, error)
	GetCheckByID(id uuid.UUID) (api.Check, error)
	DeleteScanChecks(scanID uuid.UUID) error
	GetScanIDForCheck(ID uuid.UUID) (uuid.UUID, error)
	AddCheckAsFinished(checkID uuid.UUID) (int64, error)
	GetScanStatus(ID uuid.UUID) (api.Scan, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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