Skip to content

Commit

Permalink
remove unused old nodes (pre 0.1) (#1035)
Browse files Browse the repository at this point in the history
* remove old nodes

Signed-off-by: Brandon Lum <lumjjb@gmail.com>

* remove references to GuacNodes

Signed-off-by: Brandon Lum <lumjjb@gmail.com>

* remove even more stuff

Signed-off-by: Brandon Lum <lumjjb@gmail.com>

* remove builder deadcode

Signed-off-by: Brandon Lum <lumjjb@gmail.com>

---------

Signed-off-by: Brandon Lum <lumjjb@gmail.com>
  • Loading branch information
lumjjb committed Jul 12, 2023
1 parent 2b9306d commit 1bb597c
Show file tree
Hide file tree
Showing 12 changed files with 2 additions and 1,461 deletions.
112 changes: 0 additions & 112 deletions internal/testing/testdata/testdata.go
Expand Up @@ -19,7 +19,6 @@ import (
_ "embed"
"encoding/base64"
"encoding/json"
"reflect"
"time"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -1942,117 +1941,6 @@ For the update to take effect, all services linked to the OpenSSL library must b
}
)

func GuacNodeSliceEqual(slice1, slice2 []assembler.GuacNode) bool {
if len(slice1) != len(slice2) {
return false
}

result := true

for _, node1 := range slice1 {
e := false
for _, node2 := range slice2 {
if node1.Type() == "Package" && node2.Type() == "Package" {
if node1.(assembler.PackageNode).Name == node2.(assembler.PackageNode).Name {
if reflect.DeepEqual(node1, node2) {
e = true
break
}
}
} else if node1.Type() == "Artifact" && node2.Type() == "Artifact" {
if node1.(assembler.ArtifactNode).Name == node2.(assembler.ArtifactNode).Name {
if reflect.DeepEqual(node1, node2) {
e = true
break
}
}
} else if node1.Type() == "Attestation" && node2.Type() == "Attestation" {
if node1.(assembler.AttestationNode).FilePath == node2.(assembler.AttestationNode).FilePath {
if reflect.DeepEqual(node1, node2) {
e = true
break
}
}
} else if node1.Type() == "Builder" && node2.Type() == "Builder" {
if node1.(assembler.BuilderNode).BuilderId == node2.(assembler.BuilderNode).BuilderId {
if reflect.DeepEqual(node1, node2) {
e = true
break
}
}
} else if node1.Type() == "Identity" && node2.Type() == "Identity" {
if node1.(assembler.IdentityNode).ID == node2.(assembler.IdentityNode).ID {
if reflect.DeepEqual(node1, node2) {
e = true
break
}
}
} else if node1.Type() == "Vulnerability" && node2.Type() == "Vulnerability" {
if node1.(assembler.VulnerabilityNode).ID == node2.(assembler.VulnerabilityNode).ID {
if reflect.DeepEqual(node1, node2) {
e = true
break
}
}
}
}
if !e {
result = false
break
}
}
return result
}

func GuacEdgeSliceEqual(slice1, slice2 []assembler.GuacEdge) bool {
if len(slice1) != len(slice2) {
return false
}

result := true
for _, edge1 := range slice1 {
e := false
for _, edge2 := range slice2 {
if edge1.Type() == "DependsOn" && edge2.Type() == "DependsOn" {
if reflect.DeepEqual(edge1, edge2) {
e = true
break
}
} else if edge1.Type() == "Contains" && edge2.Type() == "Contains" {
if reflect.DeepEqual(edge1, edge2) {
e = true
break
}
} else if edge1.Type() == "Attestation" && edge2.Type() == "Attestation" {
if reflect.DeepEqual(edge1, edge2) {
e = true
break
}
} else if edge1.Type() == "Identity" && edge2.Type() == "Identity" {
if reflect.DeepEqual(edge1, edge2) {
e = true
break
}
} else if edge1.Type() == "BuiltBy" && edge2.Type() == "BuiltBy" {
if reflect.DeepEqual(edge1, edge2) {
e = true
break
}
} else if edge1.Type() == "Vulnerable" && edge2.Type() == "Vulnerable" {
if reflect.DeepEqual(edge1, edge2) {
e = true
break
}
}
}
if !e {
result = false
break
}
}
return result
}

var IngestPredicatesCmpOpts = []cmp.Option{
cmpopts.EquateEmpty(),
cmpopts.SortSlices(certifyScorecardLess),
Expand Down
121 changes: 0 additions & 121 deletions pkg/assembler/assembler.go
Expand Up @@ -25,127 +25,6 @@ import (

type assembler struct{} //nolint: unused

// NOTE: `GuacNode` and `GuacEdge` interfaces are very experimental and might
// change in the future as we discover issues with reading/writing from the
// graph database.
//
// For now, the design of the interface follows these guidelines:
//
// 1. We want to serialize `GuacNode`s and `GuacEdge`s to graph database
// (e.g. Neo4j) without creating duplicate nodes. To do this, we need
// ability to uniquely identify a node. Since a node could be created from
// different document types, it can be uniquely identified by different
// subsets of attributes/properties. For example, we could have a node
// that is identified by an `"id"` field from one document and by the pair
// `"name"`, `"digest"` from another one.
// 2. Nodes can also have attributes that are not unique and are generated
// from various documents.
// 3. In order to write the serialization/deserialization code, we need to
// get the name of the attributes separate from the pairing between the
// attribute and the value.
//
// In broad lines, the serialization process for a node would look like:
//
// 1. For each identifiable set in `IdentifiablePropertyNames()` check if the
// node has values for all of the specified properties. If one is missing,
// try the next set. If no set is left, panic.
// 2. If a set of identifiable properties is found and we have values for all
// of these, write a query that would match on nodes which have these
// property:value attributes. The graph database engine will allow us to
// run separate code if a node already exists or one is newly created. In
// our case, in both instances we will just need to set the other
// attributes that have a value. To do this, the `Properties()` returned
// map will be passed directly to the prepared statement (which uses
// `Type()` to select the graph database node type and `PropertyNames()`
// to build the rest of the query).
//
// The serialization process for an edge would be similar, with the caveat that
// an edge is always created between two existing nodes.
//
// Deserialization is left for later, with the only caveat that we might
// envision a case where we'd like to match on edges without first matching on
// their endpoints (e.g., "retrieve all attestations from this time period and
// for each of them return the artifact nodes"). Hence, we need ways to
// uniquely identify edges without having endpoint nodes.
//
// TODO(mihaimaruseac): Look into using tags of fields to automate
// serialization/deserialization, similar to how json is done.

// GuacNode represents a node in the GUAC graph
// Note: this is experimental and might change. Please refer to source code for
// more details about usage.
type GuacNode interface {
// Type returns the type of node
Type() string

// Properties returns the list of properties of the node
Properties() map[string]interface{}

// PropertyNames returns the names of the properties of the node.
//
// If a string `s` is in the list returned by `PropertyNames` then it
// should also be a key in the map returned by `Properties`.
PropertyNames() []string

// IdentifiablePropertyNames returns a list of property names that can
// uniquely specify a GuacNode.
//
// Any string found in the list returned by `IdentifiablePropertyNames`
// must also be returned by `PropertyNames`.
IdentifiablePropertyNames() []string
}

// GuacEdge represents an edge in the GUAC graph
// Note: this is experimental and might change. Please refer to source code for
// more details about usage.
type GuacEdge interface {
// Type returns the type of edge
Type() string

// Nodes returns the (v,u) nodes of the edge
//
// For directional edges: v-[edge]->u.
// For non-directional edges there is no guaranteed order.
Nodes() (v, u GuacNode)

// Properties returns the list of properties of the edge
Properties() map[string]interface{}

// PropertyNames returns the names of the properties of the edge.
//
// If a string `s` is in the list returned by `PropertyNames` then it
// should also be a key in the map returned by `Properties`.
PropertyNames() []string

// IdentifiablePropertyNames returns a list of property names that can
// that can uniquely specify a GuacEdge, as an alternative to the two
// node endpoints.
//
// Any string found in the list returned by `IdentifiablePropertyNames`
// must also be returned by `PropertyNames`.
//
// TODO(mihaimaruseac): We might not need this?
IdentifiablePropertyNames() []string
}

// Graph represents a subgraph read from the database or written to it.
// Note: this is experimental and might change. Please refer to source code for
// more details about usage.
type Graph struct {
Nodes []GuacNode
Edges []GuacEdge
}

// AppendGraph appends the graph g with additional graphs
func (g *Graph) AppendGraph(gs ...Graph) {
for _, add := range gs {
g.Nodes = append(g.Nodes, add.Nodes...)
g.Edges = append(g.Edges, add.Edges...)
}
}

// TODO(mihaimaruseac): Write queries to write/read subgraphs from DB?

// IngestPredicates contains the set of predicates that want to be
// ingested based on the GUAC ontology. It only has evidence trees as
// ingestion of the software trees are implicit and handled by the
Expand Down
27 changes: 0 additions & 27 deletions pkg/assembler/backends/neo4j/artifact.go
Expand Up @@ -24,33 +24,6 @@ import (
"github.com/neo4j/neo4j-go-driver/v4/neo4j"
)

// ArtifactNode is a node that represents an artifact
type artifactNode struct {
algorithm string
digest string
}

func (an *artifactNode) Type() string {
return "Artifact"
}

func (an *artifactNode) Properties() map[string]interface{} {
properties := make(map[string]interface{})
properties["algorithm"] = an.algorithm
properties["digest"] = strings.ToLower(an.digest)
return properties
}

func (an *artifactNode) PropertyNames() []string {
fields := []string{"algorithm", "digest"}
return fields
}

func (an *artifactNode) IdentifiablePropertyNames() []string {
// An artifact can be uniquely identified by algorithm and digest
return []string{"algorithm", "digest"}
}

func (c *neo4jClient) Artifacts(ctx context.Context, artifactSpec *model.ArtifactSpec) ([]*model.Artifact, error) {
session := c.driver.NewSession(neo4j.SessionConfig{AccessMode: neo4j.AccessModeRead})
defer session.Close()
Expand Down
24 changes: 0 additions & 24 deletions pkg/assembler/backends/neo4j/builder.go
Expand Up @@ -23,30 +23,6 @@ import (
"github.com/neo4j/neo4j-go-driver/v4/neo4j"
)

// builderNode represents the builder
type builderNode struct {
uri string
}

func (bn builderNode) Type() string {
return "Builder"
}

func (bn builderNode) Properties() map[string]interface{} {
properties := make(map[string]interface{})
properties["uri"] = bn.uri
return properties
}

func (bn builderNode) PropertyNames() []string {
fields := []string{"uri"}
return fields
}

func (bn builderNode) IdentifiablePropertyNames() []string {
return []string{"uri"}
}

func (c *neo4jClient) Builders(ctx context.Context, builderSpec *model.BuilderSpec) ([]*model.Builder, error) {
session := c.driver.NewSession(neo4j.SessionConfig{AccessMode: neo4j.AccessModeRead})
defer session.Close()
Expand Down

0 comments on commit 1bb597c

Please sign in to comment.