Skip to content

Commit

Permalink
Implement transitive dependency search
Browse files Browse the repository at this point in the history
Signed-off-by: Marco Deicas <mdeicas@google.com>
  • Loading branch information
mdeicas committed Apr 26, 2024
1 parent b7df3a3 commit e31535d
Show file tree
Hide file tree
Showing 16 changed files with 1,688 additions and 57 deletions.
37 changes: 37 additions & 0 deletions pkg/assembler/helpers/purl.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"sort"
"strings"

"github.com/guacsec/guac/internal/testing/ptrfrom"
model "github.com/guacsec/guac/pkg/assembler/clients/generated"
purl "github.com/package-url/packageurl-go"
)
Expand All @@ -42,6 +43,35 @@ func PurlToPkg(purlUri string) (*model.PkgInputSpec, error) {
return purlConvert(p)
}

// PurlToPkgFilter converts a purl URI string into a graphql package filter spec.
// The result will only match the input purl, and no other packages. The filter
// is created with Guac's purl special casing.
func PurlToPkgFilter(purl string) (model.PkgSpec, error) {
inputSpec, err := PurlToPkg(purl)
if err != nil {
return model.PkgSpec{}, err
}

var qualifiers []model.PackageQualifierSpec
for _, q := range inputSpec.Qualifiers {
q := q
qualifiers = append(qualifiers, model.PackageQualifierSpec{
Key: q.Key,
Value: &q.Value,
})
}

return model.PkgSpec{
Type: &inputSpec.Type,
Namespace: ptrfrom.String(nilToEmpty(inputSpec.Namespace)),
Name: &inputSpec.Name,
Version: ptrfrom.String(nilToEmpty(inputSpec.Version)),
Qualifiers: qualifiers,
Subpath: ptrfrom.String(nilToEmpty(inputSpec.Subpath)),
MatchOnlyEmptyQualifiers: ptrfrom.Bool(len(qualifiers) == 0),
}, nil
}

// AllPkgTreeToPurl takes one package trie evaluation and converts it into a PURL
// it will only do this for one PURL, and will ignore other pkg tries in the fragment
func AllPkgTreeToPurl(v *model.AllPkgTree) string {
Expand Down Expand Up @@ -258,3 +288,10 @@ func GuacGenericPurl(s string) string {
return fmt.Sprintf("pkg:guac/generic/%s", sanitizedString)
}
}

func nilToEmpty(s *string) string {
if s == nil {
return ""
}
return *s
}
56 changes: 46 additions & 10 deletions pkg/guacrest/client/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 19 additions & 4 deletions pkg/guacrest/client/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 19 additions & 4 deletions pkg/guacrest/generated/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 24 additions & 15 deletions pkg/guacrest/generated/server.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 20 additions & 16 deletions pkg/guacrest/generated/spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e31535d

Please sign in to comment.