Skip to content

Commit

Permalink
pointer-nil-condition
Browse files Browse the repository at this point in the history
  • Loading branch information
an1l4 committed Nov 8, 2023
1 parent cb94110 commit 5af755c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
43 changes: 31 additions & 12 deletions client/pkg/clickhouse/db_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,19 +607,38 @@ func (c *DBClient) InsertTrivySbomMetrics(metrics model.Sbom) {
tx, _ = c.conn.Begin()
stmt, _ = tx.Prepare(InsertTrivySbom)
)
if _,err:= stmt.Exec(
metrics.ID,
result.CycloneDX.Metadata.Component.Name,
result.CycloneDX.Metadata.Component.Version,
result.CycloneDX.Metadata.Component.PackageURL,
result.CycloneDX.Metadata.Component.MIMEType,
result.CycloneDX.Metadata.Component.BOMRef,
result.CycloneDX.SerialNumber,
result.CycloneDX.Version,
result.CycloneDX.BOMFormat,
); err!=nil {
log.Fatal(err)
if result.CycloneDX != nil {
if _,err:= stmt.Exec(
metrics.ID,
result.CycloneDX.Metadata.Component.Name,
result.CycloneDX.Metadata.Component.PackageURL,
result.CycloneDX.Metadata.Component.BOMRef,
result.CycloneDX.SerialNumber,
result.CycloneDX.Version,
result.CycloneDX.BOMFormat,
result.CycloneDX.Metadata.Component.Version,
result.CycloneDX.Metadata.Component.MIMEType,
); err!=nil {
log.Fatal(err)
}

}else {
if _,err:= stmt.Exec(
metrics.ID,
"-",
"-",
"-",
"-",
"-",
"-",
"-",
"-",
); err!=nil {
log.Fatal(err)
}

}

if err:=tx.Commit();err!=nil {
log.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion client/pkg/clickhouse/statements.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,6 @@ const InsertTrivyVul string = "INSERT INTO trivy_vul (id, cluster_name, namespac
const InsertTrivyImage string = "INSERT INTO trivyimage (id, cluster_name, artifact_name, vul_id, vul_pkg_id, vul_pkg_name, vul_installed_version, vul_fixed_version, vul_title, vul_severity, vul_published_date, vul_last_modified_date) VALUES ( ?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
const InsertTrivyMisconfig string = "INSERT INTO trivy_misconfig (id, cluster_name, namespace, kind, name, misconfig_id, misconfig_avdid, misconfig_type, misconfig_title, misconfig_desc, misconfig_msg, misconfig_query, misconfig_resolution, misconfig_severity, misconfig_status, EventTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
const InsertAzureContainerPushEvent DBStatement = "INSERT INTO azurecontainerpush (RegistryURL, RepositoryName, Tag, ImageName, Event, Size, SHAID, EventTime) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?)"
const InsertTrivySbom string = "INSERT INTO trivysbom (id, image_name, image_version, package_url, mime_type, bom_ref, serial_number, version, bom_format) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"
const InsertTrivySbom string = "INSERT INTO trivysbom (id, image_name, package_url, bom_ref, serial_number, version, bom_format, component_version, component_mimetype) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"
const InsertQuayContainerPushEvent DBStatement = "INSERT INTO quaycontainerpush (name, repository, nameSpace, dockerURL, homePage, tag, Event, EventTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"
const InsertJfrogContainerPushEvent DBStatement = "INSERT INTO jfrogcontainerpush (Domain, EventType, RegistryURL, RepositoryName, SHAID, Size, ImageName, Tag, Event, EventTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
4 changes: 2 additions & 2 deletions sql/0000015_trivysbom.up.sql
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
CREATE TABLE IF NOT EXISTS trivysbom (
id UUID,
image_name String,
image_version String,
package_url String,
mime_type String,
bom_ref String,
serial_number String,
version INTEGER
bom_format String,
component_version String,
component_mime_type String,
ExpiryDate DateTime DEFAULT now() + INTERVAL {{.TTLValue}} {{.TTLUnit}}
) ENGINE = MergeTree()
ORDER BY ExpiryDate
Expand Down

0 comments on commit 5af755c

Please sign in to comment.