Skip to content
This repository has been archived by the owner on Jun 21, 2022. It is now read-only.

Commit

Permalink
Created analyzer for NuGet.
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Tegnér <johannes@jitesoft.com>
  • Loading branch information
Johannestegner committed Oct 14, 2020
1 parent 719c92b commit 7d817d6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions analyzer/library/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const (
Cargo = "cargo"
Composer = "composer"
Npm = "npm"
NuGet = "nuget"
Pipenv = "pipenv"
Poetry = "poetry"
Yarn = "yarn"
Expand Down
36 changes: 36 additions & 0 deletions analyzer/library/nuget/nuget.go
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
}

0 comments on commit 7d817d6

Please sign in to comment.