Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
dcaravel committed Jan 14, 2025
1 parent fc9527e commit 724cbcf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
31 changes: 27 additions & 4 deletions database/pgsql/rhelv2_layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/stackrox/rox/pkg/utils"
"github.com/stackrox/scanner/database"
"github.com/stackrox/scanner/database/metrics"
"github.com/stackrox/scanner/pkg/env"
)

func (pgSQL *pgSQL) InsertRHELv2Layer(layer *database.RHELv2Layer) error {
Expand Down Expand Up @@ -46,11 +47,18 @@ func (pgSQL *pgSQL) InsertRHELv2Layer(layer *database.RHELv2Layer) error {
func (pgSQL *pgSQL) insertRHELv2Layer(tx *sql.Tx, layer *database.RHELv2Layer) error {
defer metrics.ObserveQueryTime("insertRHELv2Layer", "layer", time.Now())

_, err := tx.Exec(insertRHELv2Layer, layer.Hash, layer.ParentHash, layer.Dist, pq.Array(layer.CPEs), layer.Lineage, layer.ParentLineage)
var lineage string
var parentLineage string
if env.RHLineage.Enabled() {
lineage = layer.Lineage
parentLineage = layer.ParentLineage
}

_, err := tx.Exec(insertRHELv2Layer, layer.Hash, layer.ParentHash, layer.Dist, pq.Array(layer.CPEs), lineage, parentLineage)
return err
}

func (pgSQL *pgSQL) insertRHELv2Packages(tx *sql.Tx, layer string, pkgs []*database.RHELv2Package, lineage string) error {
func (pgSQL *pgSQL) insertRHELv2Packages(tx *sql.Tx, layer string, pkgs []*database.RHELv2Package, layerLineage string) error {
// Sort packages to avoid potential deadlock.
// Sort by the unique index (name, version, module, arch).
sort.SliceStable(pkgs, func(i, j int) bool {
Expand Down Expand Up @@ -80,6 +88,11 @@ func (pgSQL *pgSQL) insertRHELv2Packages(tx *sql.Tx, layer string, pkgs []*datab
}
}

var lineage string
if env.RHLineage.Enabled() {
lineage = layerLineage
}

for _, pkg := range pkgs {
if pkg.Name == "" {
continue
Expand Down Expand Up @@ -112,7 +125,12 @@ func (pgSQL *pgSQL) GetRHELv2Layers(layerHash, layerLineage string) ([]*database
return nil, handleError("GetRHELv2Layers.Begin()", err)
}

rows, err := tx.Query(searchRHELv2Layers, layerHash, layerLineage)
var lineage string
if env.RHLineage.Enabled() {
lineage = layerLineage
}

rows, err := tx.Query(searchRHELv2Layers, layerHash, lineage)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -177,7 +195,12 @@ func (pgSQL *pgSQL) populatePackages(tx *sql.Tx, layers []*database.RHELv2Layer)
func (pgSQL *pgSQL) getPackagesByLayer(tx *sql.Tx, layer *database.RHELv2Layer) error {
defer metrics.ObserveQueryTime("getRHELv2Layers", "packagesByLayer", time.Now())

rows, err := tx.Query(searchRHELv2Package, layer.Hash, layer.Lineage)
var lineage string
if env.RHLineage.Enabled() {
lineage = layer.Lineage
}

rows, err := tx.Query(searchRHELv2Package, layer.Hash, lineage)
if err != nil {
return err
}
Expand Down
7 changes: 7 additions & 0 deletions pkg/env/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,11 @@ var (
// LegacyNVDLoader when true will cause the loader to pull NVD data using
// the NVD Legacy Data Feeds, if false will pull from the NVD 2.0 API.
LegacyNVDLoader = RegisterBooleanSetting("ROX_LEGACY_NVD_LOADER", false)

// RHLineage when true will cause all parent layers (a.k.a lineage) to be considered when
// storing scan results for RHEL image layers.
//
// Setting this to false will cause known image scan inaccuracies and should only be set as a
// temporary measure to address unforeseen stability issues.
RHLineage = RegisterBooleanSetting("ROX_RHEL_LINEAGE", true)
)

0 comments on commit 724cbcf

Please sign in to comment.