database

package
v0.0.0-...-c30fbfa Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package database is a generated GoMock package.

Index

Constants

View Source
const (
	DBDriverTypePostgres = "POSTGRES"
	DBDriverTypeLocal    = "LOCAL"
)
View Source
const (
	ApplicationIDType   idType = "application"
	ResourceIDType      idType = "resource"
	PackageIDType       idType = "package"
	VulnerabilityIDType idType = "vulnerability"
)
View Source
const (
	ApplicationResourcesJoinTableName        = "application_resources"
	ResourcePackagesJoinTableName            = "resource_packages"
	PackageVulnerabilitiesJoinTableName      = "package_vulnerabilities"
	ResourceCISDockerBenchmarkCheckTableName = "resource_cis_d_b_checks"
)
View Source
const DefaultViewRefreshIntervalSecond = 5

Variables

View Source
var (

	// IDViewQuery ids_view is base on `resources` table to support detached resources (resource not related to any application).
	IDViewQuery = `` /* 399-byte string literal not displayed */

)

Functions

func ApplicationFromDB

func ApplicationFromDB(view *ApplicationView) *models.Application

func ApplicationResourceFromDB

func ApplicationResourceFromDB(view *ResourceView) *models.ApplicationResource

func ArrayToDBArray

func ArrayToDBArray(arr []string) string

ArrayToDBArray Convert an array element to a DB array element.

func CISDockerBenchmarkLevelFilterGte

func CISDockerBenchmarkLevelFilterGte(db *gorm.DB, columnName string, value *string) *gorm.DB

func CISDockerBenchmarkLevelFilterLte

func CISDockerBenchmarkLevelFilterLte(db *gorm.DB, columnName string, value *string) *gorm.DB

func CreateApplicationID

func CreateApplicationID(app *models.ApplicationInfo) string

func CreateCVSSString

func CreateCVSSString(cvss *types.CVSS) string

func CreatePackageID

func CreatePackageID(pkgInfo *types.PackageInfo) string

func CreateResourceID

func CreateResourceID(info *types.ResourceInfo) string

func CreateTimeFilter

func CreateTimeFilter(timeColName string, startTime, endTime strfmt.DateTime) string

func CreateVulnerabilityID

func CreateVulnerabilityID(vul *types.PackageVulnerabilityScan) string

func DBArrayToArray

func DBArrayToArray(str string) []string

func FieldInTable

func FieldInTable(table, field string) string

func FilterArrayContains

func FilterArrayContains(db *gorm.DB, column string, values []string) *gorm.DB

func FilterArrayDoesntContain

func FilterArrayDoesntContain(db *gorm.DB, column string, values []string) *gorm.DB

func FilterContains

func FilterContains(db *gorm.DB, column string, values []string) *gorm.DB

func FilterEndsWith

func FilterEndsWith(db *gorm.DB, column string, value *string) *gorm.DB

func FilterGte

func FilterGte(db *gorm.DB, column string, value *int64) *gorm.DB

func FilterIs

func FilterIs(db *gorm.DB, column string, values []string) *gorm.DB

func FilterIsBool

func FilterIsBool(db *gorm.DB, column string, value *bool) *gorm.DB

func FilterIsEmptyString

func FilterIsEmptyString(db *gorm.DB, column string) *gorm.DB

func FilterIsNot

func FilterIsNot(db *gorm.DB, column string, values []string) *gorm.DB

func FilterIsNotEmptyString

func FilterIsNotEmptyString(db *gorm.DB, column string) *gorm.DB

func FilterIsNotNumber

func FilterIsNotNumber(db *gorm.DB, column string, values []int64) *gorm.DB

func FilterIsNumber

func FilterIsNumber(db *gorm.DB, column string, values []int64) *gorm.DB

func FilterLte

func FilterLte(db *gorm.DB, column string, value *int64) *gorm.DB

func FilterStartsWith

func FilterStartsWith(db *gorm.DB, column string, value *string) *gorm.DB

func PackageFromDB

func PackageFromDB(view *PackageView) *models.Package

func Paginate

func Paginate(page, pageSize int64) func(db *gorm.DB) *gorm.DB

func RuntimeQuickScanConfigFromDB

func RuntimeQuickScanConfigFromDB(config *QuickScanConfig) *models.RuntimeQuickScanConfig

func SeverityFilterGte

func SeverityFilterGte(db *gorm.DB, columnName string, value *string) *gorm.DB

func SeverityFilterIs

func SeverityFilterIs(db *gorm.DB, columnName string, values []string) *gorm.DB

func SeverityFilterIsNot

func SeverityFilterIsNot(db *gorm.DB, columnName string, values []string) *gorm.DB

func SeverityFilterLte

func SeverityFilterLte(db *gorm.DB, columnName string, value *string) *gorm.DB

func ToDBArrayElement

func ToDBArrayElement(s string) string

ToDBArrayElement Convert an array element to a DB array element.

func VulnerabilityFromDB

func VulnerabilityFromDB(view *VulnerabilityView) *models.Vulnerability

Types

type Application

type Application struct {
	ID string `gorm:"primarykey" faker:"-"` // consists of the application name

	Name         string                 `json:"name,omitempty" gorm:"column:name"`
	Type         models.ApplicationType `json:"type,omitempty" gorm:"column:type" faker:"oneof: IMAGE, DIRECTORY, FILE"`
	Labels       string                 `json:"labels,omitempty" gorm:"column:labels" faker:"oneof: |label1|, |label1||label2|, |label1||label2||label3|"`
	Environments string                 `json:"environments,omitempty" gorm:"column:environments" faker:"oneof: |env1|, |env1||env2|, |env1||env2||env3|"`
	Resources    []Resource             `json:"resources,omitempty" gorm:"many2many:application_resources;" faker:"-"`
}

func CreateApplication

func CreateApplication(app *models.ApplicationInfo) *Application

func (Application) TableName

func (Application) TableName() string

func (*Application) UpdateApplicationInfo

func (a *Application) UpdateApplicationInfo(app *models.ApplicationInfo) *Application

type ApplicationResources

type ApplicationResources struct {
	ApplicationID string `json:"application_id,omitempty" gorm:"primarykey;column:application_id"`
	ResourceID    string `json:"resource_id,omitempty" gorm:"primarykey;column:resource_id"`
}

ApplicationResources join table of Application and Resource.

type ApplicationTable

type ApplicationTable interface {
	Create(app *Application, params *TransactionParams) error
	UpdateInfo(app *Application, params *TransactionParams) error
	Delete(app *Application) error
	GetApplicationsAndTotal(params GetApplicationsParams) ([]ApplicationView, int64, error)
	GetApplication(id string) (*models.ApplicationEx, error)
	GetDBApplication(id string, shouldGetRelationships bool) (*Application, error)
	Count(filters *CountFilters) (int64, error)
	GetMostVulnerable(limit int) ([]*models.Application, error)
}

type ApplicationTableHandler

type ApplicationTableHandler struct {
	IDsView IDsView
	// contains filtered or unexported fields
}

func (*ApplicationTableHandler) Count

func (a *ApplicationTableHandler) Count(filters *CountFilters) (int64, error)

func (*ApplicationTableHandler) Create

func (*ApplicationTableHandler) Delete

func (a *ApplicationTableHandler) Delete(app *Application) error

func (*ApplicationTableHandler) GetApplication

func (a *ApplicationTableHandler) GetApplication(id string) (*models.ApplicationEx, error)

func (*ApplicationTableHandler) GetApplicationsAndTotal

func (a *ApplicationTableHandler) GetApplicationsAndTotal(params GetApplicationsParams) ([]ApplicationView, int64, error)

func (*ApplicationTableHandler) GetDBApplication

func (a *ApplicationTableHandler) GetDBApplication(id string, shouldGetRelationships bool) (*Application, error)

func (*ApplicationTableHandler) GetMostVulnerable

func (a *ApplicationTableHandler) GetMostVulnerable(limit int) ([]*models.Application, error)

func (*ApplicationTableHandler) UpdateInfo

func (a *ApplicationTableHandler) UpdateInfo(app *Application, params *TransactionParams) error

type ApplicationView

type ApplicationView struct {
	Application
	Resources int `json:"resources,omitempty" gorm:"column:resources"`
	Packages  int `json:"packages,omitempty" gorm:"column:packages"`
	SeverityCounters
	CISDockerBenchmarkLevelCounters
}

type CISDockerBenchmarkCheck

type CISDockerBenchmarkCheck struct {
	ID string `gorm:"primarykey" faker:"-"` // consists of the Code name

	Code         string `json:"code,omitempty" gorm:"column:code" faker:"oneof: CIS-DI-0006, CIS-DI-0005, CIS-DI-0001"`
	Level        int    `json:"level,omitempty" gorm:"column:level" faker:"oneof: 3, 2, 1"`
	Descriptions string `json:"descriptions" gorm:"column:descriptions" faker:"oneof: desc3, desc2, desc1"`
}

func (CISDockerBenchmarkCheck) TableName

func (CISDockerBenchmarkCheck) TableName() string

type CISDockerBenchmarkCheckView

type CISDockerBenchmarkCheckView struct {
	CISDockerBenchmarkCheck
	ResourceID string `json:"resource_id,omitempty" gorm:"column:resource_id"`
}

type CISDockerBenchmarkLevelCounters

type CISDockerBenchmarkLevelCounters struct {
	TotalInfoCount                 int `json:"total_info_count,omitempty" gorm:"column:total_info_count"`
	TotalWarnCount                 int `json:"total_warn_count,omitempty" gorm:"column:total_warn_count"`
	TotalFatalCount                int `json:"total_fatal_count,omitempty" gorm:"column:total_fatal_count"`
	HighestCISDockerBenchmarkLevel int `json:"highest_level,omitempty" gorm:"column:highest_level"`
	LowestCISDockerBenchmarkLevel  int `json:"lowest_level,omitempty" gorm:"column:lowest_level"`
}

type CISDockerBenchmarkResultTable

type CISDockerBenchmarkResultTable interface {
	CountPerLevel(filters *CountFilters) ([]*models.CISDockerBenchmarkLevelCount, error)
	GetCISDockerBenchmarkResultsAndTotal(params operations.GetCisdockerbenchmarkresultsIDParams) ([]CISDockerBenchmarkCheckView, int64, error)
}

type CISDockerBenchmarkResultTableHandler

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

func (*CISDockerBenchmarkResultTableHandler) CountPerLevel

func (*CISDockerBenchmarkResultTableHandler) GetCISDockerBenchmarkResultsAndTotal

type CountFilters

type CountFilters struct {
	ApplicationIDs             []string
	VulnerabilitySeverityGte   *string
	CisDockerBenchmarkLevelGte *string
}

type DBConfig

type DBConfig struct {
	EnableInfoLogs            bool
	DriverType                string
	DBPassword                string
	DBUser                    string
	DBHost                    string
	DBPort                    string
	DBName                    string
	DBSSLMode                 string
	ViewRefreshIntervalSecond int
}

type Database

type Database interface {
	ApplicationTable() ApplicationTable
	ResourceTable() ResourceTable
	PackageTable() PackageTable
	VulnerabilityTable() VulnerabilityTable
	NewVulnerabilityTable() NewVulnerabilityTable
	JoinTables() JoinTables
	IDsView() IDsView
	ObjectTree() ObjectTree
	QuickScanConfigTable() QuickScanConfigTable
	SchedulerTable() SchedulerTable
	CISDockerBenchmarkResultTable() CISDockerBenchmarkResultTable
}

nolint:interfacebloat

type DeleteRelationshipsParams

type DeleteRelationshipsParams struct {
	ApplicationIDsToRemove []string
	ResourceIDsToRemove    []string
	PackageIDsToRemove     []string
}

type GetApplicationResourcesParams

type GetApplicationResourcesParams struct {
	operations.GetApplicationResourcesParams
	// List of application IDs that were affected by the last runtime scan.
	RuntimeScanApplicationIDs []string
}

type GetApplicationsParams

type GetApplicationsParams struct {
	operations.GetApplicationsParams
	// List of application IDs that were affected by the last runtime scan.
	RuntimeScanApplicationIDs []string
}

type GetIDsParams

type GetIDsParams struct {
	FilterIDs    []string // The IDs to filter by
	FilterIDType idType   // The ID type to filter by
	LookupIDType idType   // The ID type to lookup for
}

type GetPackagesParams

type GetPackagesParams struct {
	operations.GetPackagesParams
	// List of application IDs that were affected by the last runtime scan.
	RuntimeScanApplicationIDs []string
}

type GetVulnerabilitiesParams

type GetVulnerabilitiesParams struct {
	operations.GetVulnerabilitiesParams
	// List of application IDs that were affected by the last runtime scan.
	RuntimeScanApplicationIDs []string
}

type Handler

type Handler struct {
	DriverType         string
	DB                 *gorm.DB
	ViewRefreshHandler *ViewRefreshHandler
}

func Init

func Init(config *DBConfig) *Handler

func (*Handler) ApplicationTable

func (db *Handler) ApplicationTable() ApplicationTable

func (*Handler) CISDockerBenchmarkResultTable

func (db *Handler) CISDockerBenchmarkResultTable() CISDockerBenchmarkResultTable

func (*Handler) CreateFakeData

func (db *Handler) CreateFakeData()

nolint:cyclop,gocognit

func (*Handler) IDsView

func (db *Handler) IDsView() IDsView

func (*Handler) JoinTables

func (db *Handler) JoinTables() JoinTables

func (*Handler) NewVulnerabilityTable

func (db *Handler) NewVulnerabilityTable() NewVulnerabilityTable

func (*Handler) ObjectTree

func (db *Handler) ObjectTree() ObjectTree

func (*Handler) PackageTable

func (db *Handler) PackageTable() PackageTable

func (*Handler) QuickScanConfigTable

func (db *Handler) QuickScanConfigTable() QuickScanConfigTable

func (*Handler) RefreshMaterializedViews

func (db *Handler) RefreshMaterializedViews()

func (*Handler) ResourceTable

func (db *Handler) ResourceTable() ResourceTable

func (*Handler) SchedulerTable

func (db *Handler) SchedulerTable() SchedulerTable

func (*Handler) SetMaterializedViewHandler

func (db *Handler) SetMaterializedViewHandler(config *DBConfig)

func (*Handler) VulnerabilityTable

func (db *Handler) VulnerabilityTable() VulnerabilityTable

type IDsView

type IDsView interface {
	GetIDs(params GetIDsParams, idsShouldMatch bool) ([]string, error)
}

type IDsViewHandler

type IDsViewHandler struct {
	IDsView *gorm.DB
}

func (*IDsViewHandler) GetIDs

func (i *IDsViewHandler) GetIDs(params GetIDsParams, idsShouldMatch bool) ([]string, error)

type JoinTables

type JoinTables interface {
	DeleteRelationships(params DeleteRelationshipsParams) error
	// GetResourcePackageIDToAnalyzers returns a map of ResourcePkgID to analyzers list for the given `resourceIDs`,
	// retrieved from the PackageResources join table.
	// ResourcePackage is a package that is associated to a resource.
	// ResourcePackageID is a combination of resource and package ID.
	GetResourcePackageIDToAnalyzers(resourceIDs []string) (map[ResourcePkgID][]string, error)
	GetPackageResourcesAndTotal(params operations.GetPackagesIDApplicationResourcesParams) ([]PackageResourcesInfoView, int64, error)
	GetResourcePackagesByResources(resourceIDs []string) ([]ResourcePackages, error)
	GetResourcePackagesByPackages(packageIDs []string) ([]ResourcePackages, error)
	GetPackageVulnerabilitiesByPackages(packageIDs []string) ([]PackageVulnerabilities, error)
	GetPackageVulnerabilitiesByVulnerabilities(vulnerabilityIDs []string) ([]PackageVulnerabilities, error)
}

type JoinTablesHandler

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

func (*JoinTablesHandler) DeleteRelationships

func (j *JoinTablesHandler) DeleteRelationships(params DeleteRelationshipsParams) error

func (*JoinTablesHandler) GetPackageResourcesAndTotal

func (*JoinTablesHandler) GetPackageVulnerabilitiesByPackages

func (j *JoinTablesHandler) GetPackageVulnerabilitiesByPackages(packageIDs []string) ([]PackageVulnerabilities, error)

func (*JoinTablesHandler) GetPackageVulnerabilitiesByVulnerabilities

func (j *JoinTablesHandler) GetPackageVulnerabilitiesByVulnerabilities(vulnerabilityIDs []string) ([]PackageVulnerabilities, error)

func (*JoinTablesHandler) GetResourcePackageIDToAnalyzers

func (j *JoinTablesHandler) GetResourcePackageIDToAnalyzers(resourceIDs []string) (map[ResourcePkgID][]string, error)

func (*JoinTablesHandler) GetResourcePackagesByPackages

func (j *JoinTablesHandler) GetResourcePackagesByPackages(packageIDs []string) ([]ResourcePackages, error)

func (*JoinTablesHandler) GetResourcePackagesByResources

func (j *JoinTablesHandler) GetResourcePackagesByResources(resourceIDs []string) ([]ResourcePackages, error)

type Level

type Level int
const (
	CISDockerBenchmarkLevelIGNORE Level = iota
	CISDockerBenchmarkLevelINFO
	CISDockerBenchmarkLevelWARN
	CISDockerBenchmarkLevelFATAL
)

func FromDockleTypeToLevel

func FromDockleTypeToLevel(level int64) Level

type MockHandler

type MockHandler struct {
	*MockResourceTable
}

func (*MockHandler) ApplicationTable

func (m *MockHandler) ApplicationTable() ApplicationTable

func (*MockHandler) CISDockerBenchmarkResultTable

func (m *MockHandler) CISDockerBenchmarkResultTable() CISDockerBenchmarkResultTable

func (*MockHandler) IDsView

func (m *MockHandler) IDsView() IDsView

func (*MockHandler) JoinTables

func (m *MockHandler) JoinTables() JoinTables

func (*MockHandler) NewVulnerabilityTable

func (m *MockHandler) NewVulnerabilityTable() NewVulnerabilityTable

func (*MockHandler) ObjectTree

func (m *MockHandler) ObjectTree() ObjectTree

func (*MockHandler) PackageTable

func (m *MockHandler) PackageTable() PackageTable

func (*MockHandler) QuickScanConfigTable

func (m *MockHandler) QuickScanConfigTable() QuickScanConfigTable

func (*MockHandler) ResourceTable

func (m *MockHandler) ResourceTable() ResourceTable

func (*MockHandler) SchedulerTable

func (m *MockHandler) SchedulerTable() SchedulerTable

func (*MockHandler) VulnerabilityTable

func (m *MockHandler) VulnerabilityTable() VulnerabilityTable

type MockResourceTable

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

MockResourceTable is a mock of ResourceTable interface

func NewMockResourceTable

func NewMockResourceTable(ctrl *gomock.Controller) *MockResourceTable

NewMockResourceTable creates a new mock instance

func (*MockResourceTable) Count

func (m *MockResourceTable) Count(arg0 *CountFilters) (int64, error)

Count mocks base method

func (*MockResourceTable) Create

func (m *MockResourceTable) Create(arg0 *Resource) error

Create mocks base method

func (*MockResourceTable) Delete

func (m *MockResourceTable) Delete(arg0 *Resource) error

Delete mocks base method

func (*MockResourceTable) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MockResourceTable) GetApplicationResource

func (m *MockResourceTable) GetApplicationResource(arg0 string) (*models.ApplicationResourceEx, error)

GetApplicationResource mocks base method

func (*MockResourceTable) GetApplicationResourcesAndTotal

func (m *MockResourceTable) GetApplicationResourcesAndTotal(arg0 GetApplicationResourcesParams) ([]ResourceView, int64, error)

GetApplicationResourcesAndTotal mocks base method

func (*MockResourceTable) GetDBResource

func (m *MockResourceTable) GetDBResource(arg0 string, arg1 bool) (*Resource, error)

GetDBResource mocks base method

func (*MockResourceTable) GetMostVulnerable

func (m *MockResourceTable) GetMostVulnerable(arg0 int) ([]*models.ApplicationResource, error)

GetMostVulnerable mocks base method

type MockResourceTableMockRecorder

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

MockResourceTableMockRecorder is the mock recorder for MockResourceTable

func (*MockResourceTableMockRecorder) Count

func (mr *MockResourceTableMockRecorder) Count(arg0 interface{}) *gomock.Call

Count indicates an expected call of Count

func (*MockResourceTableMockRecorder) Create

func (mr *MockResourceTableMockRecorder) Create(arg0 interface{}) *gomock.Call

Create indicates an expected call of Create

func (*MockResourceTableMockRecorder) Delete

func (mr *MockResourceTableMockRecorder) Delete(arg0 interface{}) *gomock.Call

Delete indicates an expected call of Delete

func (*MockResourceTableMockRecorder) GetApplicationResource

func (mr *MockResourceTableMockRecorder) GetApplicationResource(arg0 interface{}) *gomock.Call

GetApplicationResource indicates an expected call of GetApplicationResource

func (*MockResourceTableMockRecorder) GetApplicationResourcesAndTotal

func (mr *MockResourceTableMockRecorder) GetApplicationResourcesAndTotal(arg0 interface{}) *gomock.Call

GetApplicationResourcesAndTotal indicates an expected call of GetApplicationResourcesAndTotal

func (*MockResourceTableMockRecorder) GetDBResource

func (mr *MockResourceTableMockRecorder) GetDBResource(arg0, arg1 interface{}) *gomock.Call

GetDBResource indicates an expected call of GetDBResource

func (*MockResourceTableMockRecorder) GetMostVulnerable

func (mr *MockResourceTableMockRecorder) GetMostVulnerable(arg0 interface{}) *gomock.Call

GetMostVulnerable indicates an expected call of GetMostVulnerable

type NewVulnerability

type NewVulnerability struct {
	ID string `gorm:"primarykey"` // consists of the vulnerability ID + package ID (PkgVulID)

	VulID   string    `json:"vul_id,omitempty" gorm:"column:vul_id"`
	AddedAt time.Time `json:"added_at,omitempty" gorm:"column:added_at" faker:"-"`
}

func (NewVulnerability) TableName

func (NewVulnerability) TableName() string

type NewVulnerabilityTable

type NewVulnerabilityTable interface {
	Create(vul *NewVulnerability) error
	CreateNewVulnerabilitiesTrends(application *Application) error
	GetNewVulnerabilitiesTrends(params operations.GetDashboardTrendsVulnerabilitiesParams) ([]*models.NewVulnerabilitiesTrend, error)
}

type NewVulnerabilityTableHandler

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

func (*NewVulnerabilityTableHandler) Create

func (*NewVulnerabilityTableHandler) CreateNewVulnerabilitiesTrends

func (v *NewVulnerabilityTableHandler) CreateNewVulnerabilitiesTrends(application *Application) error

func (*NewVulnerabilityTableHandler) GetNewVulnerabilitiesTrends

type NewVulnerabilityView

type NewVulnerabilityView struct {
	AddedAt time.Time `json:"added_at,omitempty" gorm:"column:added_at" faker:"-"`
	SeverityCounters
}

type ObjectTree

type ObjectTree interface {
	SetApplication(app *Application, params *TransactionParams, shouldUpdatePackageVulnerabilities bool) error
	SetResource(resource *Resource, params *TransactionParams, shouldUpdatePackageVulnerabilities bool) error
}

type ObjectTreeHandler

type ObjectTreeHandler struct {
	DriverType string
	// contains filtered or unexported fields
}

func (*ObjectTreeHandler) LockTable

func (o *ObjectTreeHandler) LockTable(tx *gorm.DB, tableName string) *gorm.DB

func (*ObjectTreeHandler) SetApplication

func (o *ObjectTreeHandler) SetApplication(app *Application, params *TransactionParams, shouldUpdatePackageVulnerabilities bool) error

func (*ObjectTreeHandler) SetResource

func (o *ObjectTreeHandler) SetResource(resource *Resource, params *TransactionParams, shouldUpdatePackageVulnerabilities bool) error

type Package

type Package struct {
	ID string `gorm:"primarykey" faker:"-"` // consists of the package name + version

	Name            string          `json:"name,omitempty" gorm:"column:name" faker:"oneof: pkg1, pkg2, pkg3"`
	Version         string          `json:"version,omitempty" gorm:"column:version" faker:"oneof: v1, v2, v3"`
	License         string          `json:"license,omitempty" gorm:"column:license" faker:"oneof: MIT, , Apache 2.0"`
	Language        string          `json:"language,omitempty" gorm:"column:language" faker:"oneof: go, , java, python"`
	Vulnerabilities []Vulnerability `json:"vulnerabilities,omitempty" gorm:"many2many:package_vulnerabilities" faker:"-"`
}

func CreatePackage

func CreatePackage(pkg *types.PackageInfo, vuls []Vulnerability) *Package

func CreatePackageFromContentAnalysis

func CreatePackageFromContentAnalysis(pkgInfo *models.PackageInfo) *Package

func CreatePackageFromRuntimeContentAnalysis

func CreatePackageFromRuntimeContentAnalysis(pkgInfo *runtime_scan_models.PackageInfo) *Package

func (Package) TableName

func (Package) TableName() string

type PackageResourcesInfoView

type PackageResourcesInfoView struct {
	ResourcePackages
	ResourceName string `json:"resource_name,omitempty" gorm:"column:resource_name"`
	ResourceHash string `json:"resource_hash,omitempty" gorm:"column:resource_hash"`
}

func (PackageResourcesInfoView) TableName

func (PackageResourcesInfoView) TableName() string

type PackageTable

type PackageTable interface {
	Create(pkg *Package) error
	GetPackagesAndTotal(params GetPackagesParams) ([]PackageView, int64, error)
	GetPackage(id string) (*models.Package, error)
	GetPackagesCountPerLanguage() ([]*models.PackagesCountPerLanguage, error)
	GetPackagesCountPerLicense() ([]*models.PackagesCountPerLicense, error)
	Count(filters *CountFilters) (int64, error)
	GetMostVulnerable(limit int) ([]*models.Package, error)
	DeleteByIDs(pkgIDs []string) error
	GetDBPackage(id string) (*Package, error)
}

type PackageTableHandler

type PackageTableHandler struct {
	IDsView IDsView
	// contains filtered or unexported fields
}

func (*PackageTableHandler) Count

func (p *PackageTableHandler) Count(filters *CountFilters) (int64, error)

func (*PackageTableHandler) Create

func (p *PackageTableHandler) Create(pkg *Package) error

func (*PackageTableHandler) DeleteByIDs

func (p *PackageTableHandler) DeleteByIDs(pkgIDs []string) error

func (*PackageTableHandler) GetDBPackage

func (p *PackageTableHandler) GetDBPackage(id string) (*Package, error)

func (*PackageTableHandler) GetMostVulnerable

func (p *PackageTableHandler) GetMostVulnerable(limit int) ([]*models.Package, error)

func (*PackageTableHandler) GetPackage

func (p *PackageTableHandler) GetPackage(id string) (*models.Package, error)

func (*PackageTableHandler) GetPackagesAndTotal

func (p *PackageTableHandler) GetPackagesAndTotal(params GetPackagesParams) ([]PackageView, int64, error)

func (*PackageTableHandler) GetPackagesCountPerLanguage

func (p *PackageTableHandler) GetPackagesCountPerLanguage() ([]*models.PackagesCountPerLanguage, error)

func (*PackageTableHandler) GetPackagesCountPerLicense

func (p *PackageTableHandler) GetPackagesCountPerLicense() ([]*models.PackagesCountPerLicense, error)

type PackageView

type PackageView struct {
	Package
	Applications int `json:"applications,omitempty" gorm:"column:applications"`
	Resources    int `json:"resources,omitempty" gorm:"column:resources"`
	SeverityCounters
}

type PackageVulnerabilities

type PackageVulnerabilities struct {
	PackageID       string `json:"package_id,omitempty" gorm:"primarykey;column:package_id"`
	VulnerabilityID string `json:"vulnerability_id,omitempty" gorm:"primarykey;column:vulnerability_id"`
	FixVersion      string `json:"fix_version,omitempty" gorm:"column:fix_version"`
}

PackageVulnerabilities join table of Package and Vulnerability.

func (*PackageVulnerabilities) BeforeSave

func (pv *PackageVulnerabilities) BeforeSave(db *gorm.DB) error

type PkgVulID

type PkgVulID string

func CreatePkgVulID

func CreatePkgVulID(pkgID, vulID string) PkgVulID

type QuickScanConfig

type QuickScanConfig struct {
	ID string `gorm:"primarykey" faker:"-"`

	CISDockerBenchmarkEnabled bool  `json:"cis_docker_benchmark_enabled,omitempty" gorm:"column:cis_docker_benchmark_enabled"`
	MaxScanParallelism        int64 `json:"max_scan_parallelism,omitempty" gorm:"column:max_scan_parallelism"`
}

func DBQuickScanConfigFromAPI

func DBQuickScanConfigFromAPI(runtimeQuickScanConfig *models.RuntimeQuickScanConfig) *QuickScanConfig

func (QuickScanConfig) TableName

func (QuickScanConfig) TableName() string

type QuickScanConfigTable

type QuickScanConfigTable interface {
	Get() (*models.RuntimeQuickScanConfig, error)
	Set(conf *models.RuntimeQuickScanConfig) error
	SetDefault() error
}

type QuickScanConfigTableHandler

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

func (*QuickScanConfigTableHandler) Get

func (*QuickScanConfigTableHandler) Set

func (*QuickScanConfigTableHandler) SetDefault

func (q *QuickScanConfigTableHandler) SetDefault() error

type Resource

type Resource struct {
	ID string `gorm:"primarykey" faker:"-"` // consists of the resource hash

	Hash                     string                    `json:"hash,omitempty" gorm:"column:hash" faker:"oneof: hash1, hash2, hash3"`
	Name                     string                    `json:"name,omitempty" gorm:"column:name" faker:"oneof: resource1, resource2, resource3"`
	Type                     types.ResourceType        `json:"type,omitempty" gorm:"column:type" faker:"oneof: IMAGE, DIRECTORY, FILE"`
	SbomID                   string                    `json:"sbom_id,omitempty" gorm:"column:sbom_id" faker:"oneof: smobID1, smobID2, smobID3"`
	ReportingAnalyzers       string                    `json:"reporting_analyzers,omitempty" gorm:"column:reporting_analyzers" faker:"oneof: |analyzer1|, |analyzer1||analyzer2|"`
	Packages                 []Package                 `json:"packages,omitempty" gorm:"many2many:resource_packages;" faker:"-"`
	CISDockerBenchmarkChecks []CISDockerBenchmarkCheck `json:"cis_d_b_checks,omitempty" gorm:"many2many:resource_cis_d_b_checks;" faker:"-"`
}

func CreateResource

func CreateResource(info *types.ResourceInfo) *Resource

func CreateResourceFromContentAnalysis

func CreateResourceFromContentAnalysis(resourceContentAnalysis *models.ResourceContentAnalysis, params *TransactionParams) *Resource

func CreateResourceFromRuntimeContentAnalysis

func CreateResourceFromRuntimeContentAnalysis(resourceContentAnalysis *runtime_scan_models.ResourceContentAnalysis, params *TransactionParams) *Resource

func CreateResourceFromVulnerabilityScan

func CreateResourceFromVulnerabilityScan(resourceVulnerabilityScan *types.ResourceVulnerabilityScan, params *TransactionParams) *Resource

func UpdateResourceAnalyzers

func UpdateResourceAnalyzers(resources []Resource, resourcePkgIDToAnalyzers map[ResourcePkgID][]string) []Resource

func (Resource) TableName

func (Resource) TableName() string

func (*Resource) WithAnalyzers

func (r *Resource) WithAnalyzers(analyzers []string) *Resource

func (*Resource) WithCISDockerBenchmarkChecks

func (r *Resource) WithCISDockerBenchmarkChecks(checks []CISDockerBenchmarkCheck) *Resource

func (*Resource) WithPackages

func (r *Resource) WithPackages(packages []Package) *Resource

type ResourceCISDBChecks

type ResourceCISDBChecks struct {
	CISDockerBenchmarkCheckID string `json:"cis_docker_benchmark_check_id,omitempty" gorm:"primarykey;column:cis_docker_benchmark_check_id"`
	ResourceID                string `json:"resource_id,omitempty" gorm:"primarykey;column:resource_id"`
}

ResourceCISDBChecks join table of Resource and CISDockerBenchmarkCheck.

func (ResourceCISDBChecks) TableName

func (ResourceCISDBChecks) TableName() string

type ResourcePackages

type ResourcePackages struct {
	ResourceID string `json:"resource_id,omitempty" gorm:"primarykey;column:resource_id"`
	PackageID  string `json:"package_id,omitempty" gorm:"primarykey;column:package_id"`
	Analyzers  string `json:"analyzers,omitempty" gorm:"column:analyzers"`
}

ResourcePackages join table of Resource and Package.

func (*ResourcePackages) BeforeSave

func (rp *ResourcePackages) BeforeSave(db *gorm.DB) error

type ResourcePkgID

type ResourcePkgID string

func CreateResourcePkgID

func CreateResourcePkgID(resourceID, pkgID string) ResourcePkgID

type ResourceTable

type ResourceTable interface {
	Create(resource *Resource) error
	GetApplicationResourcesAndTotal(params GetApplicationResourcesParams) ([]ResourceView, int64, error)
	GetApplicationResource(id string) (*models.ApplicationResourceEx, error)
	GetDBResource(id string, shouldGetRelationships bool) (*Resource, error)
	Count(filters *CountFilters) (int64, error)
	GetMostVulnerable(limit int) ([]*models.ApplicationResource, error)
	Delete(resource *Resource) error
}

type ResourceTableHandler

type ResourceTableHandler struct {
	IDsView IDsView
	// contains filtered or unexported fields
}

func (*ResourceTableHandler) Count

func (r *ResourceTableHandler) Count(filters *CountFilters) (int64, error)

func (*ResourceTableHandler) Create

func (r *ResourceTableHandler) Create(resource *Resource) error

func (*ResourceTableHandler) Delete

func (r *ResourceTableHandler) Delete(resource *Resource) error

func (*ResourceTableHandler) GetApplicationResource

func (r *ResourceTableHandler) GetApplicationResource(id string) (*models.ApplicationResourceEx, error)

func (*ResourceTableHandler) GetApplicationResourcesAndTotal

func (r *ResourceTableHandler) GetApplicationResourcesAndTotal(params GetApplicationResourcesParams) ([]ResourceView, int64, error)

func (*ResourceTableHandler) GetDBResource

func (r *ResourceTableHandler) GetDBResource(id string, shouldGetRelationships bool) (*Resource, error)

func (*ResourceTableHandler) GetMostVulnerable

func (r *ResourceTableHandler) GetMostVulnerable(limit int) ([]*models.ApplicationResource, error)

type ResourceView

type ResourceView struct {
	Resource
	Applications int `json:"applications,omitempty" gorm:"column:applications"`
	Packages     int `json:"packages,omitempty" gorm:"column:packages"`
	SeverityCounters
	CISDockerBenchmarkLevelCounters
}

type Scheduler

type Scheduler struct {
	ID string `gorm:"primarykey" faker:"-"`

	NextScanTime string `json:"next_scan_time,omitempty" gorm:"column:next_scan_time"`
	Config       string `json:"config,omitempty" gorm:"column:config"`
	Interval     int64  `json:"interval,omitempty" gorm:"column:interval"`
}

func (Scheduler) TableName

func (Scheduler) TableName() string

type SchedulerTable

type SchedulerTable interface {
	Get() (*Scheduler, error)
	Set(scheduler *Scheduler) error
	UpdateNextScanTime(t string) error
}

type SchedulerTableHandler

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

func (*SchedulerTableHandler) Get

func (s *SchedulerTableHandler) Get() (*Scheduler, error)

func (*SchedulerTableHandler) Set

func (s *SchedulerTableHandler) Set(scheduler *Scheduler) error

func (*SchedulerTableHandler) UpdateNextScanTime

func (s *SchedulerTableHandler) UpdateNextScanTime(t string) error

type Severity

type Severity int
const (
	NEGLIGIBLE Severity = iota
	LOW
	MEDIUM
	HIGH
	CRITICAL
)

type SeverityCounters

type SeverityCounters struct {
	TotalNegCount      int `json:"total_neg_count,omitempty" gorm:"column:total_neg_count"`
	TotalLowCount      int `json:"total_low_count,omitempty" gorm:"column:total_low_count"`
	TotalMediumCount   int `json:"total_medium_count,omitempty" gorm:"column:total_medium_count"`
	TotalHighCount     int `json:"total_high_count,omitempty" gorm:"column:total_high_count"`
	TotalCriticalCount int `json:"total_critical_count,omitempty" gorm:"column:total_critical_count"`
	HighestSeverity    int `json:"highest_severity,omitempty" gorm:"column:highest_severity"`
	LowestSeverity     int `json:"lowest_severity,omitempty" gorm:"column:lowest_severity"`
}

type TransactionParams

type TransactionParams struct {
	// map package.id + vulnerability.id to fix version
	FixVersions map[PkgVulID]string
	// map resource.id + package.id to analyzers list
	Analyzers map[ResourcePkgID][]string
	// map resource.id + package.id to scanners list
	Scanners map[ResourcePkgID][]string

	Timestamp time.Time

	VulnerabilitySource models.VulnerabilitySource
}

type ViewRefreshHandler

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

func (*ViewRefreshHandler) GetAndClearChanges

func (vh *ViewRefreshHandler) GetAndClearChanges() map[string]bool

func (*ViewRefreshHandler) IsSetViewRefreshHandler

func (vh *ViewRefreshHandler) IsSetViewRefreshHandler() bool

func (*ViewRefreshHandler) TableChanged

func (vh *ViewRefreshHandler) TableChanged(table string)

type Vulnerability

type Vulnerability struct {
	ID string `gorm:"primarykey" faker:"-"` // consists of the vulnerability name

	Name        string    `json:"name,omitempty" gorm:"column:name" faker:"oneof: vul1, vul2, vul3, vul4, vul5"`
	ScannedAt   time.Time `json:"scanned_at,omitempty" gorm:"column:scanned_at" faker:"-"`
	Severity    int       `json:"severity,omitempty" gorm:"column:severity" faker:"oneof: 3, 2, 1, 0"`
	Description string    `json:"description,omitempty" gorm:"column:description" faker:"-"`
	Links       string    `json:"links,omitempty" gorm:"column:links" faker:"oneof: |link1|, |link1||link2|"`
	// Serialized CVSS struct
	CVSS              string                     `json:"cvss,omitempty" gorm:"column:cvss" faker:"-"`
	CVSSBaseScore     float64                    `json:"cvss_base_score,omitempty" gorm:"column:cvss_base_score" faker:"-"`
	CVSSSeverity      int                        `json:"cvss_severity,omitempty" gorm:"column:cvss_severity" faker:"-"`
	ReportingScanners string                     `json:"reporting_scanners,omitempty" gorm:"column:reporting_scanners" faker:"oneof: |scanner1|, |scanner1||scanner2|"`
	Source            models.VulnerabilitySource `json:"source,omitempty" gorm:"column:source" faker:"oneof: CICD, RUNTIME"`
}

func (Vulnerability) TableName

func (Vulnerability) TableName() string

type VulnerabilityTable

type VulnerabilityTable interface {
	Create(vul *Vulnerability) error
	GetVulnerability(vulID, pkgID string) (*models.VulnerabilityEx, error)
	GetVulnerabilitiesAndTotal(params GetVulnerabilitiesParams) ([]VulnerabilityView, int64, error)
	CountVulnerabilitiesWithFix() ([]*models.VulnerabilitiesWithFix, error)
	CountPerSeverity(filters *CountFilters) ([]*models.VulnerabilityCount, error)
	Count(filters *CountFilters) (int64, error)
	DeleteByIDs(vulIDs []string) error
	GetDBVulnerability(id string) (*Vulnerability, error)
}

type VulnerabilityTableHandler

type VulnerabilityTableHandler struct {
	IDsView IDsView
	// contains filtered or unexported fields
}

func (*VulnerabilityTableHandler) Count

func (v *VulnerabilityTableHandler) Count(filters *CountFilters) (int64, error)

func (*VulnerabilityTableHandler) CountPerSeverity

func (v *VulnerabilityTableHandler) CountPerSeverity(filters *CountFilters) ([]*models.VulnerabilityCount, error)

func (*VulnerabilityTableHandler) CountVulnerabilitiesWithFix

func (v *VulnerabilityTableHandler) CountVulnerabilitiesWithFix() ([]*models.VulnerabilitiesWithFix, error)

func (*VulnerabilityTableHandler) Create

func (*VulnerabilityTableHandler) DeleteByIDs

func (v *VulnerabilityTableHandler) DeleteByIDs(vulIDs []string) error

func (*VulnerabilityTableHandler) GetDBVulnerability

func (v *VulnerabilityTableHandler) GetDBVulnerability(id string) (*Vulnerability, error)

func (*VulnerabilityTableHandler) GetVulnerabilitiesAndTotal

func (v *VulnerabilityTableHandler) GetVulnerabilitiesAndTotal(params GetVulnerabilitiesParams) ([]VulnerabilityView, int64, error)

func (*VulnerabilityTableHandler) GetVulnerability

func (v *VulnerabilityTableHandler) GetVulnerability(vulID, pkgID string) (*models.VulnerabilityEx, error)

type VulnerabilityView

type VulnerabilityView struct {
	Vulnerability
	Resources      int    `json:"resources,omitempty" gorm:"column:resources"`
	Applications   int    `json:"applications,omitempty" gorm:"column:applications"`
	PackageID      string `json:"package_id,omitempty" gorm:"column:package_id"`
	PackageName    string `json:"package_name,omitempty" gorm:"column:package_name"`
	PackageVersion string `json:"package_version,omitempty" gorm:"column:package_version"`
	FixVersion     string `json:"fix_version,omitempty" gorm:"column:fix_version"`
}

Jump to

Keyboard shortcuts

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