Skip to content

Commit c40e7e8

Browse files
feat!(contrib/trivy): delete image tag from server name when scanning by trivy (#2250)
* fix(contrib/trivy) delete image tag from server name when scanning by trivy * fix(contirib/trivy) fix test
1 parent 98d2965 commit c40e7e8

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

contrib/trivy/parser/v2/parser.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package v2
22

33
import (
44
"encoding/json"
5-
"fmt"
65
"regexp"
76
"time"
87

@@ -54,9 +53,9 @@ func setScanResultMeta(scanResult *models.ScanResult, report *types.Report) erro
5453
imageName = matches[1]
5554
imageTag = matches[2]
5655
}
57-
scanResult.ServerName = fmt.Sprintf("%s:%s", imageName, imageTag)
56+
scanResult.ServerName = imageName
5857
if scanResult.Optional == nil {
59-
scanResult.Optional = map[string]interface{}{}
58+
scanResult.Optional = map[string]any{}
6059
}
6160
scanResult.Optional["TRIVY_IMAGE_NAME"] = imageName
6261
scanResult.Optional["TRIVY_IMAGE_TAG"] = imageTag

contrib/trivy/parser/v2/parser_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ var redisTrivy = []byte(`
229229

230230
var redisSR = &models.ScanResult{
231231
JSONVersion: 4,
232-
ServerName: "redis:latest",
232+
ServerName: "redis",
233233
Family: "debian",
234234
Release: "10.10",
235235
ScannedBy: "trivy",
@@ -864,7 +864,7 @@ var osAndLibTrivy = []byte(`
864864

865865
var osAndLibSR = &models.ScanResult{
866866
JSONVersion: 4,
867-
ServerName: "quay.io/fluentd_elasticsearch/fluentd:v2.9.0",
867+
ServerName: "quay.io/fluentd_elasticsearch/fluentd",
868868
Family: "debian",
869869
Release: "10.2",
870870
ScannedBy: "trivy",
@@ -1354,7 +1354,7 @@ var osAndLib2Trivy = []byte(`
13541354

13551355
var osAndLib2SR = &models.ScanResult{
13561356
JSONVersion: 4,
1357-
ServerName: "quay.io/fluentd_elasticsearch/fluentd:v2.9.0",
1357+
ServerName: "quay.io/fluentd_elasticsearch/fluentd",
13581358
Family: "debian",
13591359
Release: "10.2",
13601360
ScannedBy: "trivy",
@@ -2085,7 +2085,7 @@ var oneCVEtoNVulnerabilityTrivy = []byte(`
20852085

20862086
var oneCVEtoNVulnerabilitySR = &models.ScanResult{
20872087
JSONVersion: 4,
2088-
ServerName: "test-cve-2013-1629-cve-2023-26154:latest",
2088+
ServerName: "test-cve-2013-1629-cve-2023-26154",
20892089
Family: "debian",
20902090
Release: "10.13",
20912091
ScannedBy: "trivy",

0 commit comments

Comments
 (0)