forked from anchore/syft
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
port dotnet cataloger to new generic cataloger pattern (anchore#1286)
Signed-off-by: Alex Goodman <[email protected]> Signed-off-by: Alex Goodman <[email protected]>
- Loading branch information
Showing
8 changed files
with
229 additions
and
135 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
package dotnet | ||
|
||
import ( | ||
"github.com/anchore/syft/syft/pkg/cataloger/common" | ||
"github.com/anchore/syft/syft/pkg/cataloger/generic" | ||
) | ||
|
||
// NewDotnetDepsCataloger returns a new Dotnet cataloger object base on deps json files. | ||
func NewDotnetDepsCataloger() *common.GenericCataloger { | ||
globParsers := map[string]common.ParserFn{ | ||
"**/*.deps.json": parseDotnetDeps, | ||
} | ||
const catalogerName = "dotnet-deps-cataloger" | ||
|
||
return common.NewGenericCataloger(nil, globParsers, "dotnet-deps-cataloger") | ||
// NewDotnetDepsCataloger returns a new Dotnet cataloger object base on deps json files. | ||
func NewDotnetDepsCataloger() *generic.Cataloger { | ||
return generic.NewCataloger(catalogerName). | ||
WithParserByGlobs(parseDotnetDeps, "**/*.deps.json") | ||
} |
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,55 @@ | ||
package dotnet | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/anchore/packageurl-go" | ||
"github.com/anchore/syft/syft/pkg" | ||
"github.com/anchore/syft/syft/source" | ||
) | ||
|
||
func newDotnetDepsPackage(nameVersion string, lib dotnetDepsLibrary, locations ...source.Location) *pkg.Package { | ||
if lib.Type != "package" { | ||
return nil | ||
} | ||
|
||
fields := strings.Split(nameVersion, "/") | ||
name := fields[0] | ||
version := fields[1] | ||
|
||
m := pkg.DotnetDepsMetadata{ | ||
Name: name, | ||
Version: version, | ||
Path: lib.Path, | ||
Sha512: lib.Sha512, | ||
HashPath: lib.HashPath, | ||
} | ||
|
||
p := &pkg.Package{ | ||
Name: name, | ||
Version: version, | ||
Locations: source.NewLocationSet(locations...), | ||
PURL: packageURL(m), | ||
Language: pkg.Dotnet, | ||
Type: pkg.DotnetPkg, | ||
MetadataType: pkg.DotnetDepsMetadataType, | ||
Metadata: m, | ||
} | ||
|
||
p.SetID() | ||
|
||
return p | ||
} | ||
|
||
func packageURL(m pkg.DotnetDepsMetadata) string { | ||
var qualifiers packageurl.Qualifiers | ||
|
||
return packageurl.NewPackageURL( | ||
packageurl.TypeDotnet, | ||
"", | ||
m.Name, | ||
m.Version, | ||
qualifiers, | ||
"", | ||
).ToString() | ||
} |
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
Oops, something went wrong.