Skip to content

Commit

Permalink
Add PkgEqual and HashEqual predictaes -- testing + code planning (gua…
Browse files Browse the repository at this point in the history
…csec#1069)

* first commit eql planning

Signed-off-by: Rebecca Metzman <rmetzman@google.com>

* fixing lint

Signed-off-by: Rebecca Metzman <rmetzman@google.com>

* fixing comment plan

Signed-off-by: Rebecca Metzman <rmetzman@google.com>

* added code

Signed-off-by: Rebecca Metzman <rmetzman@google.com>

* using ctx

Signed-off-by: Rebecca Metzman <rmetzman@google.com>

---------

Signed-off-by: Rebecca Metzman <rmetzman@google.com>
Co-authored-by: Rebecca Metzman <rmetzman@google.com>
  • Loading branch information
rmetzman and Rebecca Metzman authored Jul 19, 2023
1 parent 1f147b7 commit 08bfd91
Show file tree
Hide file tree
Showing 2 changed files with 268 additions and 23 deletions.
22 changes: 22 additions & 0 deletions pkg/guacanalytics/patchPlanning.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ func caseOnPredicates(ctx context.Context, gqlClient graphql.Client, q *queueVal
exploreIsOccurrenceFromSubject(ctx, gqlClient, q, *neighbor)
case *model.NeighborsNeighborsHasSourceAt:
exploreHasSourceAtFromPackage(ctx, gqlClient, q, *neighbor)
case *model.NeighborsNeighborsPkgEqual:
explorePkgEqual(ctx, gqlClient, q, *neighbor)
}
case SourceName:
switch neighbor := neighbor.(type) {
Expand All @@ -172,6 +174,8 @@ func caseOnPredicates(ctx context.Context, gqlClient graphql.Client, q *queueVal
exploreHasSLSAFromArtifact(ctx, gqlClient, q, *neighbor)
case *model.NeighborsNeighborsIsOccurrence:
exploreIsOccurrenceFromArtifact(ctx, gqlClient, q, *neighbor)
case *model.NeighborsNeighborsHashEqual:
exploreHashEqual(ctx, gqlClient, q, *neighbor)
}

}
Expand Down Expand Up @@ -230,6 +234,24 @@ func exploreHasSourceAtFromSource(ctx context.Context, gqlClient graphql.Client,
return nil
}

// TODO: Expand to not just deal with packageVersions
func explorePkgEqual(ctx context.Context, gqlClient graphql.Client, q *queueValues, pkgEqual model.NeighborsNeighborsPkgEqual) {
for _, pkg := range pkgEqual.Packages {
if pkg.Namespaces[0].Names[0].Versions[0].Id != q.now {
q.addNodeToQueue(PackageVersion, nil, pkg.Namespaces[0].Names[0].Versions[0].Id)
q.addNodeToQueue(PackageName, []string{pkg.Namespaces[0].Names[0].Versions[0].Id}, pkg.Namespaces[0].Names[0].Id)
}
}
}

func exploreHashEqual(ctx context.Context, gqlClient graphql.Client, q *queueValues, hashEqual model.NeighborsNeighborsHashEqual) {
for _, artifact := range hashEqual.Artifacts {
if artifact.Id != q.now {
q.addNodeToQueue(Artifact, nil, artifact.Id)
}
}
}

func exploreHasSourceAtFromPackage(ctx context.Context, gqlClient graphql.Client, q *queueValues, hasSourceAt model.NeighborsNeighborsHasSourceAt) {
node, seen := q.nodeMap[hasSourceAt.Source.Namespaces[0].Names[0].Id]

Expand Down
Loading

0 comments on commit 08bfd91

Please sign in to comment.