Skip to content

Commit

Permalink
make aws relaseToDist consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
ldelossa committed Jan 23, 2020
1 parent 1fde039 commit 9afde98
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 15 deletions.
2 changes: 1 addition & 1 deletion aws/distributionscanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestDistributionScanner(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
scanner := DistributionScanner{}
dist := scanner.parse(bytes.NewBuffer(tt.osRelease))
cmpDist, _ := releaseToDist(tt.release)
cmpDist := releaseToDist(tt.release)
if !cmp.Equal(dist, cmpDist) {
t.Fatalf("%v", cmp.Diff(dist, cmpDist))
}
Expand Down
5 changes: 1 addition & 4 deletions aws/distributionscannner.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,7 @@ func (ds *DistributionScanner) Scan(ctx context.Context, l *claircore.Layer) ([]
func (ds *DistributionScanner) parse(buff *bytes.Buffer) *claircore.Distribution {
for _, ur := range awsRegexes {
if ur.regexp.Match(buff.Bytes()) {
dist, err := releaseToDist(ur.release)
if err != nil {
panic("aws distrubution scanner: awsRegex configured with unknown release")
}
dist := releaseToDist(ur.release)
return dist
}
}
Expand Down
11 changes: 5 additions & 6 deletions aws/releases.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package aws

import (
"fmt"

"github.com/quay/claircore"
)

Expand Down Expand Up @@ -33,13 +31,14 @@ var linux2Dist = &claircore.Distribution{
CPE: "cpe:2.3:o:amazon:amazon_linux:2",
}

func releaseToDist(release Release) (*claircore.Distribution, error) {
func releaseToDist(release Release) *claircore.Distribution {
switch release {
case Linux1:
return linux1Dist, nil
return linux1Dist
case Linux2:
return linux2Dist, nil
return linux2Dist
default:
return nil, fmt.Errorf("unknown release")
// return empty dist
return &claircore.Distribution{}
}
}
5 changes: 1 addition & 4 deletions aws/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ func (u *Updater) Parse(ctx context.Context, contents io.ReadCloser) ([]*clairco
if err != nil {
return nil, fmt.Errorf("failed to unmarshal updates xml: %v", err)
}
dist, err := releaseToDist(u.release)
if err != nil {
return nil, fmt.Errorf("failed to classify vulns with distribution: %w", err)
}
dist := releaseToDist(u.release)

vulns := []*claircore.Vulnerability{}
for _, update := range updates.Updates {
Expand Down

0 comments on commit 9afde98

Please sign in to comment.