Skip to content

Commit

Permalink
[CWS] use modernc.org/sqlite in CWS functional tests (#34702)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcacheux authored Mar 4, 2025
1 parent fb1424d commit e93e159
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 10 deletions.
35 changes: 35 additions & 0 deletions LICENSE-3rdparty.csv

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ require (
github.com/mattn/go-sqlite3 v1.14.24
github.com/shirou/gopsutil/v4 v4.25.1
go.opentelemetry.io/collector/component/componenttest v0.120.0
modernc.org/sqlite v1.34.1
)

require (
Expand Down Expand Up @@ -789,6 +790,7 @@ require (
github.com/moby/sys/user v0.3.0 // indirect
github.com/moby/sys/userns v0.1.0 // indirect
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/nxadm/tail v1.4.11 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/connector/spanmetricsconnector v0.120.1 // indirect
github.com/open-telemetry/opentelemetry-collector-contrib/exporter/sapmexporter v0.120.1 // indirect
Expand Down Expand Up @@ -845,6 +847,7 @@ require (
github.com/prometheus/common/sigv4 v0.1.0 // indirect
github.com/prometheus/prometheus v0.300.1 // indirect
github.com/puzpuzpuz/xsync/v3 v3.4.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/rs/zerolog v1.33.0 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
Expand Down Expand Up @@ -911,6 +914,12 @@ require (
honnef.co/go/tools v0.5.1 // indirect
k8s.io/kms v0.31.2 // indirect
k8s.io/sample-controller v0.31.2 // indirect
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect
modernc.org/libc v1.55.3 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.8.0 // indirect
modernc.org/strutil v1.2.0 // indirect
modernc.org/token v1.1.0 // indirect
rsc.io/binaryregexp v0.2.0 // indirect
)

Expand Down
12 changes: 12 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions pkg/util/trivy/sqlite_functests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

//go:build trivy && functionaltests

// Package trivy holds the scan components
package trivy

import (
// used to read RPM database
// mattn/go-sqlite3 is currently not fully supported by our functional tests setup
_ "modernc.org/sqlite"
)
23 changes: 23 additions & 0 deletions pkg/util/trivy/sqlite_no_functests.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

//go:build trivy && !functionaltests

// Package trivy holds the scan components
package trivy

import (
// used to read RPM database
"database/sql"

"github.com/mattn/go-sqlite3"
)

// This is required to load sqlite based RPM databases
func init() {
// mattn/go-sqlite3 is only registering the sqlite3 driver
// let's register the sqlite (no 3) driver as well
sql.Register("sqlite", &sqlite3.SQLiteDriver{})
}
10 changes: 0 additions & 10 deletions pkg/util/trivy/trivy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ package trivy

import (
"context"
"database/sql"
"errors"
"fmt"
"io/fs"
Expand All @@ -34,22 +33,13 @@ import (
"github.com/aquasecurity/trivy/pkg/types"
"github.com/aquasecurity/trivy/pkg/vulnerability"

"github.com/mattn/go-sqlite3"

"github.com/DataDog/datadog-agent/comp/core/config"
workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def"
"github.com/DataDog/datadog-agent/pkg/sbom"
"github.com/DataDog/datadog-agent/pkg/util/log"
"github.com/DataDog/datadog-agent/pkg/util/option"
)

// This is required to load sqlite based RPM databases
func init() {
// mattn/go-sqlite3 is only registering the sqlite3 driver
// let's register the sqlite (no 3) driver as well
sql.Register("sqlite", &sqlite3.SQLiteDriver{})
}

const (
OSAnalyzers = "os" // OSAnalyzers defines an OS analyzer
LanguagesAnalyzers = "languages" // LanguagesAnalyzers defines a language analyzer
Expand Down

0 comments on commit e93e159

Please sign in to comment.