Skip to content

Commit

Permalink
update to skip type guac purls in deps.dev (#2039)
Browse files Browse the repository at this point in the history
Signed-off-by: pxp928 <parth.psu@gmail.com>
  • Loading branch information
pxp928 authored Jul 22, 2024
1 parent bc9361d commit 621b66f
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions pkg/handler/collector/deps_dev/deps_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,21 +333,27 @@ func (d *depsCollector) getAllDependencies(ctx context.Context, purls []datasour
packageInput, err := helpers.PurlToPkg(purl)
if err != nil {
logger.Infof("failed to parse purl to pkg: %s", purl)
return nil
continue
}

// skip all type guac as they are generated by guac and will not be found in deps.dev
if packageInput.Type == "guac" {
logger.Debugf("guac purl, skipping deps.dev query: %s", purl)
continue
}

// if version is not specified, cannot obtain accurate information from deps.dev. Log as info and skip the purl.
if packageInput != nil && *packageInput.Version == "" {
logger.Debugf("purl does not contain version, skipping deps.dev query: %s", purl)
return nil
continue
}

// Make an RPC Request. The returned result is a stream of
// DependenciesResponse structs.
versionKey, err := getVersionKey(packageInput.Type, packageInput.Namespace, packageInput.Name, packageInput.Version)
if err != nil {
logger.Debugf("failed to getVersionKey with the following error: %v", err)
return nil
continue
}
// send the version key to the version channel
versionChan <- versionKey
Expand All @@ -359,7 +365,7 @@ func (d *depsCollector) getAllDependencies(ctx context.Context, purls []datasour
deps, err := d.client.GetDependencies(ctx, dependenciesReq)
if err != nil {
logger.Debugf("failed to get dependencies %v", err)
return nil
continue
}
logger.Infof("Retrieved dependencies for %s", purl)
d.dependencies[versionKey.String()] = deps
Expand All @@ -376,6 +382,12 @@ func (d *depsCollector) getAllDependencies(ctx context.Context, purls []datasour
pkgtype = strings.ToLower(node.VersionKey.System.String())
}

// skip all type guac as they are generated by guac and will not be found in deps.dev
if pkgtype == "guac" {
logger.Debugf("guac purl, skipping deps.dev query: %s", purl)
continue
}

depPurl := "pkg:" + pkgtype + "/" + node.VersionKey.Name + "@" + node.VersionKey.Version
depPackageInput, err := helpers.PurlToPkg(depPurl)
if err != nil {
Expand Down Expand Up @@ -414,6 +426,12 @@ func (d *depsCollector) fetchDependencies(ctx context.Context, purl string, docC
return nil
}

// skip all type guac as they are generated by guac and will not be found in deps.dev
if packageInput.Type == "guac" {
logger.Debugf("guac purl, skipping deps.dev query: %s", purl)
return nil
}

// if version is not specified, cannot obtain accurate information from deps.dev. Log as info and skip the purl.
if *packageInput.Version == "" {
logger.Infof("purl does not contain version, skipping deps.dev query: %s", purl)
Expand Down Expand Up @@ -538,6 +556,11 @@ func (d *depsCollector) fetchDependencies(ctx context.Context, purl string, docC
func (d *depsCollector) collectAdditionalMetadata(ctx context.Context, pkgType string, namespace *string, name string, version *string, pkgComponent *PackageComponent) error {
logger := logging.FromContext(ctx)

// skip all type guac as they are generated by guac and will not be found in deps.dev
if pkgType == "guac" {
return fmt.Errorf("guac purl, skipping deps.dev query: %s", strings.Join([]string{pkgType, *namespace, name}, "/"))
}

versionKey, err := getVersionKey(pkgType, namespace, name, version)
if err != nil {
return fmt.Errorf("failed to getVersionKey with the following error: %w", err)
Expand Down

0 comments on commit 621b66f

Please sign in to comment.