mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-23 15:37:50 -08:00
feat(java): support jar/war/ear (#837)
* refactor(server): remove Detect endpoint * refactor(library): do not use interface * refactor: add dbtest package * test: add bolt fixtures * feat: support jar scanning * refactor: rename node to npm * refactor: fix lint issues * test(maven): remove some tests * chore(mod): update fanal * docs: update README * chore(mod): update trivy-db * fix(library/drive): add ecosystem * fix: do not display 0 vulnerabilities * refactor(table): split method * Update README.md (#838) * fix(app): increase the default value of timeout (#842) * feat(maven): use go-mvn-version * test(maven): update tests * fix(scan): skip files and dirs before vulnerability detection * fix: display log messages only once per type * docs(README): add file suffixes * chore(mod): update go-mvn-version * feat(log): set go-dep-parser logger * chore(mod): update fanal * docs: update README * docs(README): add java source * test(maven): fix invalid case
This commit is contained in:
32
pkg/detector/library/npm/compare.go
Normal file
32
pkg/detector/library/npm/compare.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package npm
|
||||
|
||||
import (
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
npm "github.com/aquasecurity/go-npm-version/pkg"
|
||||
dbTypes "github.com/aquasecurity/trivy-db/pkg/types"
|
||||
"github.com/aquasecurity/trivy/pkg/detector/library/comparer"
|
||||
)
|
||||
|
||||
// Comparer represents a comparer for npm
|
||||
type Comparer struct{}
|
||||
|
||||
// IsVulnerable checks if the package version is vulnerable to the advisory.
|
||||
func (n Comparer) IsVulnerable(ver string, advisory dbTypes.Advisory) bool {
|
||||
return comparer.IsVulnerable(ver, advisory, n.matchVersion)
|
||||
}
|
||||
|
||||
// matchVersion checks if the package version satisfies the given constraint.
|
||||
func (n Comparer) matchVersion(currentVersion, constraint string) (bool, error) {
|
||||
v, err := npm.NewVersion(currentVersion)
|
||||
if err != nil {
|
||||
return false, xerrors.Errorf("npm version error (%s): %s", currentVersion, err)
|
||||
}
|
||||
|
||||
c, err := npm.NewConstraints(constraint)
|
||||
if err != nil {
|
||||
return false, xerrors.Errorf("npm constraint error (%s): %s", constraint, err)
|
||||
}
|
||||
|
||||
return c.Check(v), nil
|
||||
}
|
||||
Reference in New Issue
Block a user