Skip to content

Commit

Permalink
Drop identifiersFromDigests
Browse files Browse the repository at this point in the history
The generation of identifiers is now handled by the openvex discovery module so we
drop it from the vex processor implementation and also delete the test file.

Signed-off-by: Adolfo Garcia Veytia (puerco) <puerco@chainguard.dev>
  • Loading branch information
puerco committed Nov 29, 2023
1 parent bcb8e2a commit ba27a98
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 89 deletions.
50 changes: 0 additions & 50 deletions grype/vex/openvex/implementation.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ package openvex
import (
"errors"
"fmt"
"net/url"
"strings"

"github.com/google/go-containerregistry/pkg/name"
"github.com/openvex/discovery/pkg/discovery"
"github.com/openvex/discovery/pkg/oci"
openvex "github.com/openvex/go-vex/pkg/vex"

"github.com/anchore/grype/grype/match"
"github.com/anchore/grype/grype/pkg"
"github.com/anchore/packageurl-go"
"github.com/anchore/syft/syft/source"
)

Expand Down Expand Up @@ -81,53 +78,6 @@ func productIdentifiersFromContext(pkgContext *pkg.Context) ([]string, error) {
}
}

func identifiersFromDigests(digests []string) []string {
identifiers := []string{}

for _, d := range digests {
// The first identifier is the original image reference:
identifiers = append(identifiers, d)

// Not an image reference, skip
ref, err := name.ParseReference(d)
if err != nil {
continue
}

var digestString, repoURL string
shaString := ref.Identifier()

// If not a digest, we can't form a purl, so skip it
if !strings.HasPrefix(shaString, "sha256:") {
continue
}

digestString = url.QueryEscape(shaString)

pts := strings.Split(ref.Context().RepositoryStr(), "/")
name := pts[len(pts)-1]
repoURL = strings.TrimSuffix(
ref.Context().RegistryStr()+"/"+ref.Context().RepositoryStr(),
fmt.Sprintf("/%s", name),
)

qMap := map[string]string{}

if repoURL != "" {
qMap["repository_url"] = repoURL
}
qs := packageurl.QualifiersFromMap(qMap)
identifiers = append(identifiers, packageurl.NewPackageURL(
"oci", "", name, digestString, qs, "",
).String())

// Add a hash to the identifier list in case people want to vex
// using the value of the image digest
identifiers = append(identifiers, strings.TrimPrefix(shaString, "sha256:"))
}
return identifiers
}

// subcomponentIdentifiersFromMatch returns the list of identifiers from the
// package where grype did the match.
func subcomponentIdentifiersFromMatch(m *match.Match) []string {
Expand Down
38 changes: 0 additions & 38 deletions grype/vex/openvex/implementation_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion grype/vex/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type ProcessorOptions struct {
func (vm *Processor) ApplyVEX(pkgContext *pkg.Context, remainingMatches *match.Matches, ignoredMatches []match.IgnoredMatch) (*match.Matches, []match.IgnoredMatch, error) {
var err error

// If no VEX documents are loaded, just pass through the matches, effectivly NOOP
// If no VEX documents are loaded, just pass through the matches, effectively a NOOP
if len(vm.Options.Documents) == 0 && !vm.Options.Autodiscover {
return remainingMatches, ignoredMatches, nil
}
Expand Down

0 comments on commit ba27a98

Please sign in to comment.