This repository has been archived by the owner on Jun 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Johannes Tegnér <johannes@jitesoft.com>
- Loading branch information
1 parent
719c92b
commit 7d817d6
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package nuget | ||
|
||
import ( | ||
"github.com/aquasecurity/fanal/analyzer" | ||
"github.com/aquasecurity/fanal/analyzer/library" | ||
"github.com/aquasecurity/fanal/utils" | ||
"github.com/aquasecurity/go-dep-parser/pkg/nuget" | ||
"golang.org/x/xerrors" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
func init() { | ||
analyzer.RegisterAnalyzer(&nugetLibraryAnalyzer{}) | ||
} | ||
|
||
var requiredFiles = []string{"packages.lock.json"} | ||
|
||
type nugetLibraryAnalyzer struct{} | ||
|
||
func (a nugetLibraryAnalyzer) Analyze(content []byte) (analyzer.AnalyzeReturn, error) { | ||
ret, err := library.Analyze(content, nuget.Parse) | ||
if err != nil { | ||
return analyzer.AnalyzeReturn{}, xerrors.Errorf("unable to parse packages.lock.json: %w", err) | ||
} | ||
return ret, nil | ||
} | ||
|
||
func (a nugetLibraryAnalyzer) Required(filePath string, _ os.FileInfo) bool { | ||
fileName := filepath.Base(filePath) | ||
return utils.StringInSlice(fileName, requiredFiles) | ||
} | ||
|
||
func (a nugetLibraryAnalyzer) Name() string { | ||
return library.NuGet | ||
} |