Skip to content

Commit

Permalink
move DynamicAnalysisRecord struct to public API (#986)
Browse files Browse the repository at this point in the history
Signed-off-by: Max Fisher <[email protected]>
  • Loading branch information
maxfisher-g authored Dec 21, 2023
1 parent 8ebae41 commit 93da81c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
18 changes: 3 additions & 15 deletions internal/resultstore/result.go
Original file line number Diff line number Diff line change
@@ -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"`
}
7 changes: 4 additions & 3 deletions internal/resultstore/resultstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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(),
},
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/analysisrun/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions pkg/api/analysisrun/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 93da81c

Please sign in to comment.