Skip to content

Commit

Permalink
Updated Design and Included Tests
Browse files Browse the repository at this point in the history
Signed-off-by: nathannaveen <[email protected]>
  • Loading branch information
nathannaveen committed Sep 3, 2024
1 parent 36d8213 commit fa57306
Show file tree
Hide file tree
Showing 11 changed files with 499 additions and 154 deletions.
36 changes: 2 additions & 34 deletions pkg/guacrest/client/client.go

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

15 changes: 12 additions & 3 deletions pkg/guacrest/client/models.go

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

15 changes: 12 additions & 3 deletions pkg/guacrest/generated/models.go

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

22 changes: 3 additions & 19 deletions pkg/guacrest/generated/server.go

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

57 changes: 29 additions & 28 deletions pkg/guacrest/generated/spec.go

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

26 changes: 11 additions & 15 deletions pkg/guacrest/helpers/getPackageInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import (
)

type QueryType struct {
Vulns *bool
Dependencies *bool
Licenses *bool
LatestSBOM *bool
Vulns bool
Dependencies bool
LatestSBOM bool
}

func GetInfoForPackage(ctx context.Context, gqlClient graphql.Client, pkgInput *model.PkgInputSpec, shouldQuery QueryType) (*gen.PackageInfoResponseJSONResponse, error) {
Expand All @@ -25,13 +24,13 @@ func GetInfoForPackage(ctx context.Context, gqlClient graphql.Client, pkgInput *
Name: &pkgInput.Name,
}

if *pkgInput.Namespace != "" {
if pkgInput.Namespace != nil && *pkgInput.Namespace != "" {
pkgSpec.Namespace = pkgInput.Namespace
}
if *pkgInput.Version != "" {
if pkgInput.Version != nil && *pkgInput.Version != "" {
pkgSpec.Version = pkgInput.Version
}
if *pkgInput.Subpath != "" {
if pkgInput.Subpath != nil && *pkgInput.Subpath != "" {
pkgSpec.Subpath = pkgInput.Subpath
}

Expand Down Expand Up @@ -61,26 +60,23 @@ func GetInfoForPackage(ctx context.Context, gqlClient graphql.Client, pkgInput *
latestSbom := &model.AllHasSBOMTree{}

// If the LatestSBOM query is specified then all other queries should be for the latest SBOM
if shouldQuery.LatestSBOM != nil && *shouldQuery.LatestSBOM {
if len(packageIds) > 1 {
return nil, fmt.Errorf("cant find latest SBOM when more than one package found for given purl")
}
latestSbom, err = LatestSBOMForAGivenId(ctx, gqlClient, packageIds[0])
if shouldQuery.LatestSBOM {
latestSbom, err = LatestSBOMFromID(ctx, gqlClient, packageIds)
if err != nil {
return nil, err
}
searchSoftware = true
}

if shouldQuery.Vulns != nil && *shouldQuery.Vulns {
if shouldQuery.Vulns {
logger.Infof("Searching for vulnerabilities in package %s", pkgInput.Name)
vulnerabilities, err := searchAttachedVulns(ctx, gqlClient, pkgSpec, searchSoftware, *latestSbom)
if err != nil {
return nil, err
}
response.Vulnerabilities = &vulnerabilities
}
if shouldQuery.Dependencies != nil && *shouldQuery.Dependencies {
if shouldQuery.Dependencies {
logger.Infof("Searching for dependencies in package %s", pkgInput.Name)

var dependencies []gen.PackageInfo
Expand Down Expand Up @@ -202,7 +198,7 @@ func searchDependencies(ctx context.Context, gqlClient graphql.Client, pkgSpec m
hasSboms = &model.HasSBOMsResponse{
HasSBOM: []model.HasSBOMsHasSBOM{
{
startSBOM,
AllHasSBOMTree: startSBOM,
},
},
}
Expand Down
Loading

0 comments on commit fa57306

Please sign in to comment.