Skip to content

Commit

Permalink
Updating Arango and Ent with KnownSince (#1399)
Browse files Browse the repository at this point in the history
* Updated certifyBad

Signed-off-by: nathannaveen <[email protected]>

* Updating tests

Signed-off-by: nathannaveen <[email protected]>

* Updated Tests

Signed-off-by: nathannaveen <[email protected]>

* Included CertifyGood

Signed-off-by: nathannaveen <[email protected]>

* Included HasSBOM

Signed-off-by: nathannaveen <[email protected]>

* Ent HasSBOM

Signed-off-by: nathannaveen <[email protected]>

* Ent CertifyGood and Ent CertifyBad

Signed-off-by: nathannaveen <[email protected]>

* Fixed sbom test

Signed-off-by: nathannaveen <[email protected]>

* Fixed Lint and Tests

Signed-off-by: nathannaveen <[email protected]>

* Changed KnownSince to UTC

Signed-off-by: nathannaveen <[email protected]>

---------

Signed-off-by: nathannaveen <[email protected]>
  • Loading branch information
nathannaveen authored Oct 18, 2023
1 parent 9fd1846 commit 8829931
Show file tree
Hide file tree
Showing 27 changed files with 845 additions and 73 deletions.
1 change: 1 addition & 0 deletions pkg/assembler/backends/arangodb/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const (
origin string = "origin"
collector string = "collector"
justification string = "justification"
knownSince string = "knownSince"
maxRetires int = 100
retryTimer time.Duration = time.Microsecond
guacEmpty string = "guac-empty-@@"
Expand Down
57 changes: 39 additions & 18 deletions pkg/assembler/backends/arangodb/certifyBad.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"context"
"fmt"
"strings"
"time"

"github.com/arangodb/go-driver"
"github.com/guacsec/guac/internal/testing/ptrfrom"
Expand Down Expand Up @@ -172,6 +173,7 @@ func getSrcCertifyBadForQuery(ctx context.Context, c *arangoClient, arangoQueryB
'certifyBad_id': certifyBad._id,
'justification': certifyBad.justification,
'collector': certifyBad.collector,
'knownSince': certifyBad.knownSince,
'origin': certifyBad.origin
}`)

Expand All @@ -195,6 +197,7 @@ func getArtCertifyBadForQuery(ctx context.Context, c *arangoClient, arangoQueryB
'certifyBad_id': certifyBad._id,
'justification': certifyBad.justification,
'collector': certifyBad.collector,
'knownSince': certifyBad.knownSince,
'origin': certifyBad.origin
}`)

Expand Down Expand Up @@ -226,6 +229,7 @@ func getPkgCertifyBadForQuery(ctx context.Context, c *arangoClient, arangoQueryB
'certifyBad_id': certifyBad._id,
'justification': certifyBad.justification,
'collector': certifyBad.collector,
'knownSince': certifyBad.knownSince,
'origin': certifyBad.origin
}`)
} else {
Expand All @@ -242,6 +246,7 @@ func getPkgCertifyBadForQuery(ctx context.Context, c *arangoClient, arangoQueryB
'certifyBad_id': certifyBad._id,
'justification': certifyBad.justification,
'collector': certifyBad.collector,
'knownSince': certifyBad.knownSince,
'origin': certifyBad.origin
}`)
}
Expand Down Expand Up @@ -272,6 +277,11 @@ func setCertifyBadMatchValues(arangoQueryBuilder *arangoQueryBuilder, certifyBad
arangoQueryBuilder.filter("certifyBad", collector, "==", "@"+collector)
queryValues[collector] = *certifyBadSpec.Collector
}
if certifyBadSpec.KnownSince != nil {
certifyBadKnownSince := *certifyBadSpec.KnownSince
arangoQueryBuilder.filter("certifyBad", "knownSince", ">=", "@"+knownSince)
queryValues[knownSince] = certifyBadKnownSince.UTC()
}
}

func getCertifyBadQueryValues(pkg *model.PkgInputSpec, pkgMatchType *model.MatchFlags, artifact *model.ArtifactInputSpec, source *model.SourceInputSpec, certifyBad *model.CertifyBadInputSpec) map[string]any {
Expand All @@ -295,6 +305,7 @@ func getCertifyBadQueryValues(pkg *model.PkgInputSpec, pkgMatchType *model.Match
values["justification"] = certifyBad.Justification
values["origin"] = certifyBad.Origin
values["collector"] = certifyBad.Collector
values[knownSince] = certifyBad.KnownSince.UTC()

return values
}
Expand Down Expand Up @@ -329,8 +340,8 @@ func (c *arangoClient) IngestCertifyBad(ctx context.Context, subject model.Packa
)
LET certifyBad = FIRST(
UPSERT { packageID:firstPkg.version_id, justification:@justification, collector:@collector, origin:@origin }
INSERT { packageID:firstPkg.version_id, justification:@justification, collector:@collector, origin:@origin }
UPSERT { packageID:firstPkg.version_id, justification:@justification, collector:@collector, origin:@origin, knownSince:@knownSince }
INSERT { packageID:firstPkg.version_id, justification:@justification, collector:@collector, origin:@origin, knownSince:@knownSince }
UPDATE {} IN certifyBads
RETURN NEW
)
Expand All @@ -355,6 +366,7 @@ func (c *arangoClient) IngestCertifyBad(ctx context.Context, subject model.Packa
'certifyBad_id': certifyBad._id,
'justification': certifyBad.justification,
'collector': certifyBad.collector,
'knownSince': certifyBad.knownSince,
'origin': certifyBad.origin
}`

Expand Down Expand Up @@ -396,8 +408,8 @@ func (c *arangoClient) IngestCertifyBad(ctx context.Context, subject model.Packa
)
LET certifyBad = FIRST(
UPSERT { packageID:firstPkg.name_id, justification:@justification, collector:@collector, origin:@origin }
INSERT { packageID:firstPkg.name_id, justification:@justification, collector:@collector, origin:@origin }
UPSERT { packageID:firstPkg.name_id, justification:@justification, collector:@collector, origin:@origin, knownSince:@knownSince }
INSERT { packageID:firstPkg.name_id, justification:@justification, collector:@collector, origin:@origin, knownSince:@knownSince }
UPDATE {} IN certifyBads
RETURN NEW
)
Expand All @@ -418,6 +430,7 @@ func (c *arangoClient) IngestCertifyBad(ctx context.Context, subject model.Packa
'certifyBad_id': certifyBad._id,
'justification': certifyBad.justification,
'collector': certifyBad.collector,
'knownSince': certifyBad.knownSince,
'origin': certifyBad.origin
}`

Expand All @@ -443,8 +456,8 @@ func (c *arangoClient) IngestCertifyBad(ctx context.Context, subject model.Packa
query := `LET artifact = FIRST(FOR art IN artifacts FILTER art.algorithm == @art_algorithm FILTER art.digest == @art_digest RETURN art)
LET certifyBad = FIRST(
UPSERT { artifactID:artifact._id, justification:@justification, collector:@collector, origin:@origin }
INSERT { artifactID:artifact._id, justification:@justification, collector:@collector, origin:@origin }
UPSERT { artifactID:artifact._id, justification:@justification, collector:@collector, origin:@origin, knownSince:@knownSince }
INSERT { artifactID:artifact._id, justification:@justification, collector:@collector, origin:@origin, knownSince:@knownSince }
UPDATE {} IN certifyBads
RETURN NEW
)
Expand All @@ -462,6 +475,7 @@ func (c *arangoClient) IngestCertifyBad(ctx context.Context, subject model.Packa
'certifyBad_id': certifyBad._id,
'justification': certifyBad.justification,
'collector': certifyBad.collector,
'knownSince': certifyBad.knownSince,
'origin': certifyBad.origin
}`

Expand Down Expand Up @@ -505,8 +519,8 @@ func (c *arangoClient) IngestCertifyBad(ctx context.Context, subject model.Packa
)
LET certifyBad = FIRST(
UPSERT { sourceID:firstSrc.name_id, justification:@justification, collector:@collector, origin:@origin }
INSERT { sourceID:firstSrc.name_id, justification:@justification, collector:@collector, origin:@origin }
UPSERT { sourceID:firstSrc.name_id, justification:@justification, collector:@collector, origin:@origin, knownSince:@knownSince }
INSERT { sourceID:firstSrc.name_id, justification:@justification, collector:@collector, origin:@origin, knownSince:@knownSince }
UPDATE {} IN certifyBads
RETURN NEW
)
Expand All @@ -529,6 +543,7 @@ func (c *arangoClient) IngestCertifyBad(ctx context.Context, subject model.Packa
'certifyBad_id': certifyBad._id,
'justification': certifyBad.justification,
'collector': certifyBad.collector,
'knownSince': certifyBad.knownSince,
'origin': certifyBad.origin
}`

Expand Down Expand Up @@ -611,8 +626,8 @@ func (c *arangoClient) IngestCertifyBads(ctx context.Context, subjects model.Pac
)
LET certifyBad = FIRST(
UPSERT { packageID:firstPkg.version_id, justification:doc.justification, collector:doc.collector, origin:doc.origin }
INSERT { packageID:firstPkg.version_id, justification:doc.justification, collector:doc.collector, origin:doc.origin }
UPSERT { packageID:firstPkg.version_id, justification:doc.justification, collector:doc.collector, origin:doc.origin, knownSince:doc.knownSince }
INSERT { packageID:firstPkg.version_id, justification:doc.justification, collector:doc.collector, origin:doc.origin, knownSince:doc.knownSince }
UPDATE {} IN certifyBads
RETURN NEW
)
Expand All @@ -637,6 +652,7 @@ func (c *arangoClient) IngestCertifyBads(ctx context.Context, subjects model.Pac
'certifyBad_id': certifyBad._id,
'justification': certifyBad.justification,
'collector': certifyBad.collector,
'knownSince': certifyBad.knownSince,
'origin': certifyBad.origin
}`

Expand Down Expand Up @@ -676,8 +692,8 @@ func (c *arangoClient) IngestCertifyBads(ctx context.Context, subjects model.Pac
)
LET certifyBad = FIRST(
UPSERT { packageID:firstPkg.name_id, justification:doc.justification, collector:doc.collector, origin:doc.origin }
INSERT { packageID:firstPkg.name_id, justification:doc.justification, collector:doc.collector, origin:doc.origin }
UPSERT { packageID:firstPkg.name_id, justification:doc.justification, collector:doc.collector, origin:doc.origin, knownSince:doc.knownSince }
INSERT { packageID:firstPkg.name_id, justification:doc.justification, collector:doc.collector, origin:doc.origin, knownSince:doc.knownSince }
UPDATE {} IN certifyBads
RETURN NEW
)
Expand All @@ -698,6 +714,7 @@ func (c *arangoClient) IngestCertifyBads(ctx context.Context, subjects model.Pac
'certifyBad_id': certifyBad._id,
'justification': certifyBad.justification,
'collector': certifyBad.collector,
'knownSince': certifyBad.knownSince,
'origin': certifyBad.origin
}`

Expand Down Expand Up @@ -749,8 +766,8 @@ func (c *arangoClient) IngestCertifyBads(ctx context.Context, subjects model.Pac
query := `LET artifact = FIRST(FOR art IN artifacts FILTER art.algorithm == doc.art_algorithm FILTER art.digest == doc.art_digest RETURN art)
LET certifyBad = FIRST(
UPSERT { artifactID:artifact._id, justification:doc.justification, collector:doc.collector, origin:doc.origin }
INSERT { artifactID:artifact._id, justification:doc.justification, collector:doc.collector, origin:doc.origin }
UPSERT { artifactID:artifact._id, justification:doc.justification, collector:doc.collector, origin:doc.origin, knownSince:doc.knownSince }
INSERT { artifactID:artifact._id, justification:doc.justification, collector:doc.collector, origin:doc.origin, knownSince:doc.knownSince }
UPDATE {} IN certifyBads
RETURN NEW
)
Expand All @@ -768,6 +785,7 @@ func (c *arangoClient) IngestCertifyBads(ctx context.Context, subjects model.Pac
'certifyBad_id': certifyBad._id,
'justification': certifyBad.justification,
'collector': certifyBad.collector,
'knownSince': certifyBad.knownSince,
'origin': certifyBad.origin
}`

Expand Down Expand Up @@ -837,8 +855,8 @@ func (c *arangoClient) IngestCertifyBads(ctx context.Context, subjects model.Pac
)
LET certifyBad = FIRST(
UPSERT { sourceID:firstSrc.name_id, justification:doc.justification, collector:doc.collector, origin:doc.origin }
INSERT { sourceID:firstSrc.name_id, justification:doc.justification, collector:doc.collector, origin:doc.origin }
UPSERT { sourceID:firstSrc.name_id, justification:doc.justification, collector:doc.collector, origin:doc.origin, knownSince:doc.knownSince }
INSERT { sourceID:firstSrc.name_id, justification:doc.justification, collector:doc.collector, origin:doc.origin, knownSince:doc.knownSince }
UPDATE {} IN certifyBads
RETURN NEW
)
Expand All @@ -861,6 +879,7 @@ func (c *arangoClient) IngestCertifyBads(ctx context.Context, subjects model.Pac
'certifyBad_id': certifyBad._id,
'justification': certifyBad.justification,
'collector': certifyBad.collector,
'knownSince': certifyBad.knownSince,
'origin': certifyBad.origin
}`

Expand Down Expand Up @@ -891,6 +910,7 @@ func getCertifyBadFromCursor(ctx context.Context, cursor driver.Cursor) ([]*mode
CertifyBadID string `json:"certifyBad_id"`
Justification string `json:"justification"`
Collector string `json:"collector"`
KnownSince time.Time `json:"knownSince"`
Origin string `json:"origin"`
}

Expand Down Expand Up @@ -924,8 +944,9 @@ func getCertifyBadFromCursor(ctx context.Context, cursor driver.Cursor) ([]*mode
certifyBad := &model.CertifyBad{
ID: createdValue.CertifyBadID,
Justification: createdValue.Justification,
Origin: createdValue.Origin,
Collector: createdValue.Collector,
Origin: createdValue.Collector,
Collector: createdValue.Origin,
KnownSince: createdValue.KnownSince,
}

if pkg != nil {
Expand Down
44 changes: 44 additions & 0 deletions pkg/assembler/backends/arangodb/certifyBad_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"strings"
"testing"
"time"

"github.com/google/go-cmp/cmp"
"github.com/guacsec/guac/internal/testing/ptrfrom"
Expand All @@ -39,6 +40,8 @@ func TestCertifyBad(t *testing.T) {
if err != nil {
t.Fatalf("error creating arango backend: %v", err)
}
curTime := time.Now()
timeAfterOneSecond := curTime.Add(time.Second)
type call struct {
Sub model.PackageSourceOrArtifactInput
Match *model.MatchFlags
Expand Down Expand Up @@ -193,6 +196,47 @@ func TestCertifyBad(t *testing.T) {
},
},
},
{
Name: "Query on KnownSince",
InPkg: []*model.PkgInputSpec{testdata.P1},
Calls: []call{
{
Sub: model.PackageSourceOrArtifactInput{
Package: testdata.P1,
},
Match: &model.MatchFlags{
Pkg: model.PkgMatchTypeSpecificVersion,
},
CB: &model.CertifyBadInputSpec{
Justification: "test justification one",
KnownSince: curTime,
},
},
{
Sub: model.PackageSourceOrArtifactInput{
Package: testdata.P1,
},
Match: &model.MatchFlags{
Pkg: model.PkgMatchTypeSpecificVersion,
},
CB: &model.CertifyBadInputSpec{
Justification: "test justification two",
KnownSince: timeAfterOneSecond,
},
},
},
Query: &model.CertifyBadSpec{
Justification: ptrfrom.String("test justification one"),
KnownSince: ptrfrom.Time(curTime),
},
ExpCB: []*model.CertifyBad{
{
Subject: testdata.P1out,
Justification: "test justification one",
KnownSince: curTime,
},
},
},
{
Name: "Query on Package",
InPkg: []*model.PkgInputSpec{testdata.P4},
Expand Down
Loading

0 comments on commit 8829931

Please sign in to comment.