-
Notifications
You must be signed in to change notification settings - Fork 45
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
Migrate trusty eval engine to Trusty v2 API. #5013
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -299,7 +299,7 @@ func (sph *summaryPrHandler) generateSummary() (string, error) { | |
malicious = append(malicious, maliciousTemplateData{ | ||
templatePackageData: packageData, | ||
Summary: alternative.trustyReply.Malicious.Summary, | ||
Details: preprocessDetails(alternative.trustyReply.Malicious.Details), | ||
Details: alternative.trustyReply.Malicious.Details, | ||
}) | ||
continue | ||
} | ||
|
@@ -323,8 +323,9 @@ func (sph *summaryPrHandler) generateSummary() (string, error) { | |
// Since (1) we don't have score anymore, and | ||
// (2) we don't suggest malicious packages, I | ||
// suggest getting rid of this check | ||
// altogether. | ||
if altData.Score != nil && *altData.Score <= lowScorePackages[alternative.Dependency.Name].Score { | ||
// altogether and always report all available | ||
// alternatives. | ||
if comparePackages(altData, lowScorePackages[alternative.Dependency.Name]) == worse { | ||
continue | ||
} | ||
|
||
|
@@ -333,9 +334,11 @@ func (sph *summaryPrHandler) generateSummary() (string, error) { | |
Ecosystem: altData.PackageType, | ||
PackageName: altData.PackageName, | ||
TrustyURL: altData.TrustyURL, | ||
Score: *altData.Score, | ||
}, | ||
} | ||
if altData.Score != nil { | ||
altPackageData.templatePackageData.Score = *altData.Score | ||
} | ||
|
||
dep := lowScorePackages[alternative.Dependency.Name] | ||
dep.Alternatives = append(dep.Alternatives, altPackageData) | ||
|
@@ -346,6 +349,23 @@ func (sph *summaryPrHandler) generateSummary() (string, error) { | |
return sph.compileTemplate(malicious, lowScorePackages) | ||
} | ||
|
||
type packageComparison int | ||
|
||
const ( | ||
better packageComparison = iota | ||
worse | ||
) | ||
|
||
// comparePackages compares two packages to determine whether the | ||
// first argument is better or worse than the second one. It does so | ||
// by checking Trusty scores. | ||
func comparePackages(alt alternative, examined templatePackage) packageComparison { | ||
if alt.Score != nil && *alt.Score != 0 && *alt.Score <= examined.Score { | ||
return worse | ||
} | ||
return better | ||
} | ||
|
||
// buildProvenanceStruct builds the provenance data structure for the PR template | ||
func buildProvenanceStruct(r *trustyReport) *templateProvenance { | ||
if r == nil || r.Provenance == nil { | ||
|
@@ -428,8 +448,12 @@ func newSummaryPrHandler( | |
}, nil | ||
} | ||
|
||
func preprocessDetails(s string) string { | ||
scanner := bufio.NewScanner(strings.NewReader(s)) | ||
func preprocessDetails(s *string) string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why change this to take a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because its argument |
||
if s == nil { | ||
return "" | ||
} | ||
|
||
scanner := bufio.NewScanner(strings.NewReader(*s)) | ||
text := "" | ||
for scanner.Scan() { | ||
if strings.HasPrefix(scanner.Text(), "#") { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use the same contract as e.g.
slices.SortFunc
and use positive numbers to indicatea > b
, and negative numbers fora < b
?That would also allow us to use
slices.SortFunc
elsewhere for lists of packages with the comparison function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately,
comparePackages
arguments are of different types, so it would not be possible to use that as argument toslices.SortFunc
.I'm inclined to keep this implementation because
pr_trusty_check
rule to Data Sources and Rego evaluation type