cgbigquery

package
v0.0.0-...-9c9d7cb Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CveQueryType            = "cve"
	ImageScanQueryType      = "scan"
	LegacyScanQueryType     = "legacyscan"
	VulnWithImagesQueryType = "vulnwithimages"
)
View Source
const (
	LegacyCsvHeader    = `f0_,image,scanner,time,low_cve_cnt,med_cve_cnt,high_cve_cnt,crit_cve_cnt,unknown_cve_cnt,tot_cve_cnt,digest`
	ImageScanCsvHeader = `image,package,vulnerability,version,type,s`

	AllVulnsQuery = `
SELECT DISTINCT vulnerability
FROM ` + vulnsTable

	AffectedImagesQuery = `
SELECT scan.image, scan.time as time,
FROM ` + vulnsTable + ` AS vulns
INNER JOIN ` + summaryTable + ` AS scan
ON scan.id = vulns.scan_id
WHERE vulns.vulnerability = @vulnerability
GROUP BY scan.time, scan.image
ORDER BY scan.image, scan.time
`

	AllVulnsWithImagesQuery = `
SELECT
  vulns.vulnerability,
  scan.image,
  ARRAY_AGG(DISTINCT FORMAT_DATE('%Y-%m-%d', DATE(scan.time)) ORDER BY FORMAT_DATE('%Y-%m-%d', DATE(scan.time))) AS dates
FROM ` + vulnsTable + ` AS vulns
INNER JOIN ` + summaryTable + ` AS scan
  ON scan.id = vulns.scan_id
WHERE scan.time >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 31 DAY)
GROUP BY vulns.vulnerability, scan.image
`

	LegacyCsvQuery = `
SELECT
	ROW_NUMBER() OVER (ORDER BY time),
	image,
    tags,
	scanner,
	FORMAT_DATETIME("%Y-%m-%d %H:%M:%S", DATE(time)) as time,
	low_cve_count as low_cve_cnt,
	med_cve_count as med_cve_cnt,
	high_cve_count as high_cve_cnt,
	crit_cve_count as crit_cve_cnt,
	unknown_cve_count as unknown_cve_cnt,
	low_cve_count + med_cve_count + high_cve_count + crit_cve_count + unknown_cve_count AS tot_cve_cnt,
	digest
FROM ` + summaryTable + `
WHERE tags NOT LIKE '%latest-dev%'
AND time >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 31 DAY)
AND (image NOT LIKE 'cgr.dev%%' OR image LIKE 'cgr.dev/chainguard/%%')`

	ImageComparisonCsvQuery = `
WITH ruuuumble AS (
	SELECT scan.image,
		scan.time as t,
		vulns.name as package,
		vulns.vulnerability,
		vulns.installed as version,
		vulns.type,
		vulns.severity
	FROM ` + vulnsTable + ` AS vulns
	INNER JOIN ` + summaryTable + ` AS scan ON scan.id = vulns.scan_id
	WHERE scan.time >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 31 DAY)
	AND ((scan.image = @theirs AND scan.tags = @their_tag)
	OR (scan.image = @ours AND scan.tags = @our_tag))
	)
	SELECT image, package, vulnerability, version, type, severity FROM ruuuumble
	GROUP BY vulnerability, image, package, version, type, severity
	ORDER BY (
	CASE WHEN severity = "Critical" THEN 1
		WHEN severity = "High" THEN 2
		WHEN severity = "Medium" THEN 3
		WHEN severity = "Low" THEN 4
		WHEN severity = "Negligible" THEN 5
		WHEN severity = "Unknown" THEN 6
		ELSE 7
	END
	)
`
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BqClient

type BqClient struct {
	Client *bigquery.Client
	Ctx    context.Context
}

func NewBqClient

func NewBqClient(project, db string) (BqClient, error)

func (*BqClient) Query

func (b *BqClient) Query(q *bigquery.Query, queryType string) ([]interface{}, error)

type ImageScan

type ImageScan struct {
	Image         string
	T             string
	Package       string
	Vulnerability string
	Version       string
	Type          string
	Severity      string
}

type LegacyScan

type LegacyScan struct {
	Row             int64
	Image           string
	Tags            string
	Scanner         string
	Time            string
	Low_cve_cnt     int64
	Med_cve_cnt     int64
	High_cve_cnt    int64
	Crit_cve_cnt    int64
	Unknown_cve_cnt int64
	Tot_cve_cnt     int64
	Digest          string
}

type VulnWithImages

type VulnWithImages struct {
	Vulnerability string
	Image         string
	Dates         []string
}

Jump to

Keyboard shortcuts

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