Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions internal/capabilities/packages/asdf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Cataloger capabilities. See ../README.md for documentation.

catalogers:
- ecosystem: other # MANUAL
name: asdf-cataloger # AUTO-GENERATED
type: generic # AUTO-GENERATED
source: # AUTO-GENERATED
file: syft/pkg/cataloger/asdf/cataloger.go
function: NewInstalledFileCataloger
selectors: # AUTO-GENERATED
- asdf
- directory
- image
- installed
- package
2 changes: 2 additions & 0 deletions internal/task/package_tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/anchore/syft/syft/pkg/cataloger/ai"
"github.com/anchore/syft/syft/pkg/cataloger/alpine"
"github.com/anchore/syft/syft/pkg/cataloger/arch"
"github.com/anchore/syft/syft/pkg/cataloger/asdf"
"github.com/anchore/syft/syft/pkg/cataloger/binary"
bitnamiSbomCataloger "github.com/anchore/syft/syft/pkg/cataloger/bitnami"
"github.com/anchore/syft/syft/pkg/cataloger/conda"
Expand Down Expand Up @@ -154,6 +155,7 @@ func DefaultPackageTaskFactories() Factories {
newSimplePackageTaskFactory(lua.NewPackageCataloger, pkgcataloging.DirectoryTag, pkgcataloging.InstalledTag, pkgcataloging.ImageTag, pkgcataloging.LanguageTag, "lua"),

// other package catalogers ///////////////////////////////////////////////////////////////////////////
newSimplePackageTaskFactory(asdf.NewInstalledFileCataloger, pkgcataloging.DirectoryTag, pkgcataloging.InstalledTag, pkgcataloging.ImageTag, "asdf"),
newPackageTaskFactory(
func(cfg CatalogingFactoryConfig) pkg.Cataloger {
return binary.NewClassifierCataloger(cfg.PackagesConfig.Binary)
Expand Down
12 changes: 12 additions & 0 deletions syft/pkg/cataloger/asdf/cataloger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package asdf

import (
"github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/pkg/cataloger/generic"
)

// NewInstalledFileCataloger returns a new cataloger for installed asdf-managed files
func NewInstalledFileCataloger() pkg.Cataloger {
return generic.NewCataloger("asdf-cataloger").
WithParserByGlobs(parseAsdfInstallations, asdfInstallGlob)
}
64 changes: 64 additions & 0 deletions syft/pkg/cataloger/asdf/parser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package asdf

import (
"context"
"strings"

"github.com/anchore/syft/internal/log"
"github.com/anchore/syft/syft/artifact"
"github.com/anchore/syft/syft/file"
"github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/pkg/cataloger/common/cpe"
"github.com/anchore/syft/syft/pkg/cataloger/generic"
"github.com/anchore/syft/syft/pkg/cataloger/internal/licenses"
)

const asdfCataloger = "asdf"
const asdfInstallGlob = "**/.asdf/installs/*/*/bin/*"

// parseAsdfInstallations parses asdf version manager installations
func parseAsdfInstallations(ctx context.Context, resolver file.Resolver, _ *generic.Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) {
name := ""
version := ""

root := -1
parts := strings.Split(reader.AccessPath, "/")
for i, part := range parts {
if part == "installs" {
root = i
break
}
}

if root < 0 {
return nil, nil, nil
}

if len(parts) > root+2 {
name = parts[root+1]
version = parts[root+2]
}

if name == "" || version == "" {
log.Debug("no name or version found at %v", reader.AccessPath)
return nil, nil, nil
}

p := pkg.Package{
Name: name,
Version: version,
FoundBy: asdfCataloger,
Locations: file.NewLocationSet(reader.WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation)),
Licenses: pkg.NewLicenseSet(licenses.FindRelativeToLocations(ctx, resolver, reader.Location)...),
Language: "",
Type: pkg.BinaryPkg,
CPEs: nil,
PURL: "",
Metadata: nil,
}

p.CPEs = cpe.Generate(p)
p.SetID()

return []pkg.Package{p}, nil, nil
}
23 changes: 23 additions & 0 deletions syft/pkg/cataloger/asdf/parser_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package asdf

import (
"testing"

"github.com/anchore/syft/syft/pkg/cataloger/internal/pkgtest"
"github.com/anchore/syft/syft/source"
"github.com/anchore/syft/syft/source/directorysource"
"github.com/stretchr/testify/require"
)

func Test_AsdfCataloger(t *testing.T) {
src, err := directorysource.NewFromPath("test-fixtures")
require.NoError(t, err)

res, err := src.FileResolver(source.SquashedScope)
require.NoError(t, err)

pkgtest.NewCatalogTester().
ExpectsPackageStrings([]string{"curl @ 5.2.1 (.asdf/installs/curl/5.2.1/bin/curl)"}).
WithResolver(res).
TestCataloger(t, NewInstalledFileCataloger())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
executable
Loading