diff --git a/internal/resultstore/result.go b/internal/resultstore/result.go index 40b50a33..988e2aa3 100644 --- a/internal/resultstore/result.go +++ b/internal/resultstore/result.go @@ -1,24 +1,12 @@ package resultstore +import "github.com/ossf/package-analysis/pkg/api/pkgecosystem" + // Pkg describes the various package details used to populate the package part // of the analysis results. type Pkg interface { + Ecosystem() pkgecosystem.Ecosystem EcosystemName() string Name() string Version() string } - -// pkg is an internal representation of a Pkg, which can be marshalled into JSON. -type pkg struct { - Ecosystem string `json:"Ecosystem"` - Name string `json:"Name"` - Version string `json:"Version"` -} - -// DynamicAnalysisRecord is the top-level struct which is serialised to produce JSON results files -// for dynamic analysis -type DynamicAnalysisRecord struct { - Package pkg `json:"Package"` - CreatedTimestamp int64 `json:"CreatedTimestamp"` - Analysis any `json:"Analysis"` -} diff --git a/internal/resultstore/resultstore.go b/internal/resultstore/resultstore.go index 83720c7c..dc89fa99 100644 --- a/internal/resultstore/resultstore.go +++ b/internal/resultstore/resultstore.go @@ -19,6 +19,7 @@ import ( "github.com/ossf/package-analysis/internal/pkgmanager" "github.com/ossf/package-analysis/internal/utils" + "github.com/ossf/package-analysis/pkg/api/analysisrun" "github.com/ossf/package-analysis/pkg/api/staticanalysis" ) @@ -248,9 +249,9 @@ func (rs *ResultStore) SaveDynamicAnalysis(ctx context.Context, p Pkg, analysis filename = DefaultFilename(p) } - data := &DynamicAnalysisRecord{ - Package: pkg{ - Ecosystem: p.EcosystemName(), + data := &analysisrun.DynamicAnalysisRecord{ + Package: analysisrun.Key{ + Ecosystem: p.Ecosystem(), Name: p.Name(), Version: p.Version(), }, diff --git a/pkg/api/analysisrun/key.go b/pkg/api/analysisrun/key.go index 2000efba..f010e75d 100644 --- a/pkg/api/analysisrun/key.go +++ b/pkg/api/analysisrun/key.go @@ -7,9 +7,9 @@ import ( ) type Key struct { - Ecosystem pkgecosystem.Ecosystem - Name string - Version string + Ecosystem pkgecosystem.Ecosystem `json:"Ecosystem"` + Name string `json:"Name"` + Version string `json:"Version"` } func (k Key) String() string { diff --git a/pkg/api/analysisrun/result.go b/pkg/api/analysisrun/result.go index 696dfba6..d6af5318 100644 --- a/pkg/api/analysisrun/result.go +++ b/pkg/api/analysisrun/result.go @@ -11,6 +11,14 @@ type ( DynamicAnalysisExecutionLog string ) +// DynamicAnalysisRecord is the top-level struct which is serialised to produce JSON results files +// for dynamic analysis. +type DynamicAnalysisRecord struct { + Package Key `json:"Package"` + CreatedTimestamp int64 `json:"CreatedTimestamp"` + Analysis any `json:"Analysis"` +} + type DynamicAnalysisResults struct { StraceSummary DynamicAnalysisStraceSummary FileWritesSummary DynamicAnalysisFileWritesSummary