Skip to content

Commit

Permalink
Add CreatedAt to the JSON report. (#5542)
Browse files Browse the repository at this point in the history
  • Loading branch information
u5surf committed Nov 13, 2023
1 parent cb241a8 commit 531f9e3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/docs/supply-chain/attestation/vuln.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ $ trivy image --format cosign-vuln --output vuln.json alpine:3.10
},
"result": {
"SchemaVersion": 2,
"CreatedAt": 1629894030,
"ArtifactName": "alpine:3.10",
"ArtifactType": "container_image",
"Metadata": {
Expand Down
2 changes: 2 additions & 0 deletions pkg/scanner/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/google/wire"
"golang.org/x/xerrors"

"github.com/aquasecurity/trivy/pkg/clock"
"github.com/aquasecurity/trivy/pkg/fanal/artifact"
aimage "github.com/aquasecurity/trivy/pkg/fanal/artifact/image"
flocal "github.com/aquasecurity/trivy/pkg/fanal/artifact/local"
Expand Down Expand Up @@ -172,6 +173,7 @@ func (s Scanner) ScanArtifact(ctx context.Context, options types.ScanOptions) (t

return types.Report{
SchemaVersion: report.SchemaVersion,
CreatedAt: clock.Now().Unix(),
ArtifactName: artifactInfo.Name,
ArtifactType: artifactInfo.Type,
Metadata: types.Metadata{
Expand Down
4 changes: 4 additions & 0 deletions pkg/scanner/scan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"context"
"errors"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/aquasecurity/trivy/pkg/clock"
"github.com/aquasecurity/trivy/pkg/fanal/artifact"
ftypes "github.com/aquasecurity/trivy/pkg/fanal/types"
"github.com/aquasecurity/trivy/pkg/types"
Expand All @@ -17,6 +19,7 @@ func TestScanner_ScanArtifact(t *testing.T) {
type args struct {
options types.ScanOptions
}
clock.SetFakeTime(t, time.Date(2021, 8, 25, 12, 20, 30, 5, time.UTC))
tests := []struct {
name string
args args
Expand Down Expand Up @@ -96,6 +99,7 @@ func TestScanner_ScanArtifact(t *testing.T) {
},
want: types.Report{
SchemaVersion: 2,
CreatedAt: 1629894030,
ArtifactName: "alpine:3.11",
ArtifactType: ftypes.ArtifactContainerImage,
Metadata: types.Metadata{
Expand Down
1 change: 1 addition & 0 deletions pkg/types/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
// Report represents a scan result
type Report struct {
SchemaVersion int `json:",omitempty"`
CreatedAt int64 `json:",omitempty"`
ArtifactName string `json:",omitempty"`
ArtifactType ftypes.ArtifactType `json:",omitempty"`
Metadata Metadata `json:",omitempty"`
Expand Down

0 comments on commit 531f9e3

Please sign in to comment.