Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing error in JSON output w/ OS matches #61

Merged
merged 2 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func startWorker(userInput string, failOnEolFound bool, eolMatchDate time.Time)
var store *store.Store
var status *db.Status
var dbCloser *db.Closer
var sbomPackages []pkg.Package
var packages []pkg.Package
var sbom *sbom.SBOM
var pkgContext pkg.Context
var wg = &sync.WaitGroup{}
Expand All @@ -236,7 +236,7 @@ func startWorker(userInput string, failOnEolFound bool, eolMatchDate time.Time)
go func() {
defer wg.Done()
log.Debugf("gathering packages")
sbomPackages, pkgContext, sbom, err = pkg.Provide(userInput, getProviderConfig())
packages, pkgContext, sbom, err = pkg.Provide(userInput, getProviderConfig())
if err != nil {
errs <- fmt.Errorf("failed to catalog: %w", err)
return
Expand All @@ -257,7 +257,7 @@ func startWorker(userInput string, failOnEolFound bool, eolMatchDate time.Time)
Distro: distroMatcher.MatcherConfig(appConfig.Match.Distro),
})

allMatches, err := xeol.FindEol(*store, pkgContext.Distro, matchers, sbomPackages, failOnEolFound, eolMatchDate)
allMatches, err := xeol.FindEol(*store, pkgContext.Distro, matchers, packages, failOnEolFound, eolMatchDate)
if err != nil {
errs <- err
if !errors.Is(err, xeolerr.ErrEolFound) {
Expand All @@ -267,7 +267,7 @@ func startWorker(userInput string, failOnEolFound bool, eolMatchDate time.Time)

pb := models.PresenterConfig{
Matches: allMatches,
Packages: sbomPackages,
Packages: packages,
SBOM: sbom,
Context: pkgContext,
AppConfig: appConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,41 @@
"modularityLabel": ""
}
}
},
{
"Cycle": {
"ProductName": "Ubuntu",
"ReleaseCycle": "16.04",
"Eol": "2021-04-02",
"LatestRelease": "",
"LatestReleaseDate": "2016-07-31",
"ReleaseDate": "2016-07-31"
},
"Package": {
"ID": "",
"Name": "",
"Version": "",
"Locations": {},
"Language": "",
"Licenses": null,
"Type": "",
"CPEs": null,
"PURL": "",
"Upstreams": null,
"MetadataType": "",
"Metadata": null
},
"artifact": {
"name": "ubuntu",
"version": "16.04",
"type": "os",
"locations": [],
"language": "",
"licenses": [],
"cpes": [],
"purl": "",
"upstreams": []
}
}
],
"source": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,41 @@
"modularityLabel": ""
}
}
},
{
"Cycle": {
"ProductName": "Ubuntu",
"ReleaseCycle": "16.04",
"Eol": "2021-04-02",
"LatestRelease": "",
"LatestReleaseDate": "2016-07-31",
"ReleaseDate": "2016-07-31"
},
"Package": {
"ID": "",
"Name": "",
"Version": "",
"Locations": {},
"Language": "",
"Licenses": null,
"Type": "",
"CPEs": null,
"PURL": "",
"Upstreams": null,
"MetadataType": "",
"Metadata": null
},
"artifact": {
"name": "ubuntu",
"version": "16.04",
"type": "os",
"locations": [],
"language": "",
"licenses": [],
"cpes": [],
"purl": "",
"upstreams": []
}
}
],
"source": {
Expand Down
19 changes: 13 additions & 6 deletions xeol/presenter/models/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,20 @@ func NewDocument(packages []pkg.Package, context pkg.Context, matches match.Matc
// we must preallocate the findings to ensure the JSON document does not show "null" when no matches are found
var findings = make([]Match, 0)
for _, m := range matches.Sorted() {
p := pkg.ByID(m.Package.ID, packages)
if p == nil {
return Document{}, fmt.Errorf("unable to find package in collection: %+v", p)
}
// syft doesn't treat OS packages as real "packages", so they won't exist in the
// packages collection. we need to handle this case separately.
if m.Package.Type == "os" {
matchModel := newMatch(m, m.Package)
findings = append(findings, *matchModel)
} else {
p := pkg.ByID(m.Package.ID, packages)
if p == nil {
return Document{}, fmt.Errorf("unable to find package in collection: %+v", p)
}

matchModel := newMatch(m, *p)
findings = append(findings, *matchModel)
matchModel := newMatch(m, *p)
findings = append(findings, *matchModel)
}
}

var src *source
Expand Down
17 changes: 16 additions & 1 deletion xeol/presenter/models/models_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func generateMatches(t *testing.T, p, p2 pkg.Package) match.Matches {
Package: p,
},
{

Cycle: eol.Cycle{
ProductName: "MongoDB Server",
ReleaseDate: "2016-07-31",
Expand All @@ -93,6 +92,22 @@ func generateMatches(t *testing.T, p, p2 pkg.Package) match.Matches {
},
Package: p2,
},
{
Cycle: eol.Cycle{
ProductName: "Ubuntu",
ReleaseDate: "2016-07-31",
ReleaseCycle: "16.04",
Eol: "2021-04-02",
EolBool: false,
LatestReleaseDate: "2016-07-31",
},
Package: pkg.Package{
ID: pkg.ID(uuid.NewString()),
Name: "ubuntu",
Version: "16.04",
Type: "os",
},
},
}

collection := match.NewMatches(matches...)
Expand Down
6 changes: 3 additions & 3 deletions xeol/presenter/table/presenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ var now = time.Now

// Presenter is a generic struct for holding fields needed for reporting
type Presenter struct {
results match.Matches
matches match.Matches
packages []pkg.Package
}

// NewPresenter is a *Presenter constructor
func NewPresenter(pb models.PresenterConfig) *Presenter {
return &Presenter{
results: pb.Matches,
matches: pb.Matches,
packages: pb.Packages,
}
}
Expand All @@ -36,7 +36,7 @@ func (pres *Presenter) Present(output io.Writer) error {

columns := []string{"NAME", "VERSION", "EOL", "DAYS EOL", "TYPE"}
// Generate rows for matches
for m := range pres.results.Enumerate() {
for m := range pres.matches.Enumerate() {
if m.Package.Name == "" {
continue
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
NAME VERSION EOL DAYS EOL TYPE
package-1 1.1.1 2018-07-31 1614 rpm
package-2 2.2.2 YES - deb
ubuntu 16.04 2021-04-02 638 os