Skip to content

Commit

Permalink
Update graphQL, resolvers and add backend stubs for pagination (#1862)
Browse files Browse the repository at this point in the history
* implement pagination for artifact

Signed-off-by: pxp928 <parth.psu@gmail.com>

* implement artifactList for keyvalue and ent

Signed-off-by: pxp928 <parth.psu@gmail.com>

* add builder pagination for keyvalue and ent

Signed-off-by: pxp928 <parth.psu@gmail.com>

* gql schema changes for pagination for certifyBad, certifyGood, certifyLegal and certifyScorecard

Signed-off-by: pxp928 <parth.psu@gmail.com>

* gql schema changes for pagination for certifyVex and certifyVuln

Signed-off-by: pxp928 <parth.psu@gmail.com>

* gql schema changes for pagination for poc or hashEqual

Signed-off-by: pxp928 <parth.psu@gmail.com>

* gql schema changes for pagination for hashSBOM and hasSLSA

Signed-off-by: pxp928 <parth.psu@gmail.com>

* gql schema changes for pagination for hasSourceAt, isDep, isOccur, license

Signed-off-by: pxp928 <parth.psu@gmail.com>

* gql schema changes for pagination for meta, package, pkgEqual, source, vulnEqual, vuln, vulnMeta

Signed-off-by: pxp928 <parth.psu@gmail.com>

* add to backends interface

Signed-off-by: pxp928 <parth.psu@gmail.com>

* add stubs to all backends for paginated query

Signed-off-by: pxp928 <parth.psu@gmail.com>

* add search and neighbor pagination

Signed-off-by: pxp928 <parth.psu@gmail.com>

---------

Signed-off-by: pxp928 <parth.psu@gmail.com>
  • Loading branch information
pxp928 committed Apr 25, 2024
1 parent 5ff8e90 commit d861241
Show file tree
Hide file tree
Showing 180 changed files with 18,861 additions and 1,044 deletions.
375 changes: 375 additions & 0 deletions internal/testing/mocks/backend.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions pkg/assembler/backends/arangodb/artifact.go
Expand Up @@ -25,6 +25,10 @@ import (
"github.com/guacsec/guac/pkg/assembler/graphql/model"
)

func (c *arangoClient) ArtifactsList(ctx context.Context, artifactSpec model.ArtifactSpec, after *string, first *int) (*model.ArtifactConnection, error) {
return nil, fmt.Errorf("not implemented: ArtifactsList")
}

func (c *arangoClient) Artifacts(ctx context.Context, artifactSpec *model.ArtifactSpec) ([]*model.Artifact, error) {
values := map[string]any{}

Expand Down
4 changes: 4 additions & 0 deletions pkg/assembler/backends/arangodb/builder.go
Expand Up @@ -25,6 +25,10 @@ import (
"github.com/guacsec/guac/pkg/assembler/graphql/model"
)

func (c *arangoClient) BuildersList(ctx context.Context, builderSpec model.BuilderSpec, after *string, first *int) (*model.BuilderConnection, error) {
return nil, fmt.Errorf("not implemented: BuildersList")
}

func (c *arangoClient) Builders(ctx context.Context, builderSpec *model.BuilderSpec) ([]*model.Builder, error) {
values := map[string]any{}
arangoQueryBuilder := setBuilderMatchValues(builderSpec, values)
Expand Down
4 changes: 4 additions & 0 deletions pkg/assembler/backends/arangodb/certifyBad.go
Expand Up @@ -27,6 +27,10 @@ import (
"github.com/guacsec/guac/pkg/assembler/helpers"
)

func (c *arangoClient) CertifyBadList(ctx context.Context, certifyBadSpec model.CertifyBadSpec, after *string, first *int) (*model.CertifyBadConnection, error) {
return nil, fmt.Errorf("not implemented: CertifyBadList")
}

func (c *arangoClient) CertifyBad(ctx context.Context, certifyBadSpec *model.CertifyBadSpec) ([]*model.CertifyBad, error) {

if certifyBadSpec != nil && certifyBadSpec.ID != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/assembler/backends/arangodb/certifyGood.go
Expand Up @@ -27,6 +27,10 @@ import (
"github.com/guacsec/guac/pkg/assembler/helpers"
)

func (c *arangoClient) CertifyGoodList(ctx context.Context, certifyGoodSpec model.CertifyGoodSpec, after *string, first *int) (*model.CertifyGoodConnection, error) {
return nil, fmt.Errorf("not implemented: CertifyBadList")
}

func (c *arangoClient) CertifyGood(ctx context.Context, certifyGoodSpec *model.CertifyGoodSpec) ([]*model.CertifyGood, error) {

if certifyGoodSpec != nil && certifyGoodSpec.ID != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/assembler/backends/arangodb/certifyLegal.go
Expand Up @@ -27,6 +27,10 @@ import (
"github.com/guacsec/guac/pkg/assembler/helpers"
)

func (c *arangoClient) CertifyLegalList(ctx context.Context, certifyLegalSpec model.CertifyLegalSpec, after *string, first *int) (*model.CertifyLegalConnection, error) {
return nil, fmt.Errorf("not implemented: CertifyBadList")
}

func (c *arangoClient) CertifyLegal(ctx context.Context, certifyLegalSpec *model.CertifyLegalSpec) ([]*model.CertifyLegal, error) {

if certifyLegalSpec != nil && certifyLegalSpec.ID != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/assembler/backends/arangodb/certifyScorecard.go
Expand Up @@ -39,6 +39,10 @@ const (

// Query Scorecards

func (c *arangoClient) ScorecardsList(ctx context.Context, scorecardSpec model.CertifyScorecardSpec, after *string, first *int) (*model.CertifyScorecardConnection, error) {
return nil, fmt.Errorf("not implemented: ScorecardsList")
}

func (c *arangoClient) Scorecards(ctx context.Context, certifyScorecardSpec *model.CertifyScorecardSpec) ([]*model.CertifyScorecard, error) {

if certifyScorecardSpec != nil && certifyScorecardSpec.ID != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/assembler/backends/arangodb/certifyVEXStatement.go
Expand Up @@ -35,6 +35,10 @@ const (
knownSinceStr string = "knownSince"
)

func (c *arangoClient) CertifyVEXStatementList(ctx context.Context, certifyVEXStatementSpec model.CertifyVEXStatementSpec, after *string, first *int) (*model.VEXConnection, error) {
return nil, fmt.Errorf("not implemented: CertifyVEXStatementList")
}

func (c *arangoClient) CertifyVEXStatement(ctx context.Context, certifyVEXStatementSpec *model.CertifyVEXStatementSpec) ([]*model.CertifyVEXStatement, error) {

if certifyVEXStatementSpec != nil && certifyVEXStatementSpec.ID != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/assembler/backends/arangodb/certifyVuln.go
Expand Up @@ -34,6 +34,10 @@ const (
scannerVersionStr string = "scannerVersion"
)

func (c *arangoClient) CertifyVulnList(ctx context.Context, certifyVulnSpec model.CertifyVulnSpec, after *string, first *int) (*model.CertifyVulnConnection, error) {
return nil, fmt.Errorf("not implemented: CertifyVulnList")
}

func (c *arangoClient) CertifyVuln(ctx context.Context, certifyVulnSpec *model.CertifyVulnSpec) ([]*model.CertifyVuln, error) {

if certifyVulnSpec != nil && certifyVulnSpec.ID != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/assembler/backends/arangodb/hasMetadata.go
Expand Up @@ -32,6 +32,10 @@ const (
valueStr string = "value"
)

func (c *arangoClient) HasMetadataList(ctx context.Context, hasMetadataSpec model.HasMetadataSpec, after *string, first *int) (*model.HasMetadataConnection, error) {
return nil, fmt.Errorf("not implemented: HasMetadataList")
}

func (c *arangoClient) HasMetadata(ctx context.Context, hasMetadataSpec *model.HasMetadataSpec) ([]*model.HasMetadata, error) {

if hasMetadataSpec != nil && hasMetadataSpec.ID != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/assembler/backends/arangodb/hasSBOM.go
Expand Up @@ -29,6 +29,10 @@ import (
"github.com/guacsec/guac/pkg/assembler/helpers"
)

func (c *arangoClient) HasSBOMList(ctx context.Context, hasSBOMSpec model.HasSBOMSpec, after *string, first *int) (*model.HasSBOMConnection, error) {
return nil, fmt.Errorf("not implemented: HasSBOMList")
}

func (c *arangoClient) HasSBOM(ctx context.Context, hasSBOMSpec *model.HasSBOMSpec) ([]*model.HasSbom, error) {

if hasSBOMSpec != nil && hasSBOMSpec.ID != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/assembler/backends/arangodb/hasSLSA.go
Expand Up @@ -37,6 +37,10 @@ const (
builtFromStr string = "builtFrom"
)

func (c *arangoClient) HasSLSAList(ctx context.Context, hasSLSASpec model.HasSLSASpec, after *string, first *int) (*model.HasSLSAConnection, error) {
return nil, fmt.Errorf("not implemented: HasSLSAList")
}

func (c *arangoClient) HasSlsa(ctx context.Context, hasSLSASpec *model.HasSLSASpec) ([]*model.HasSlsa, error) {

if hasSLSASpec != nil && hasSLSASpec.ID != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/assembler/backends/arangodb/hasSourceAt.go
Expand Up @@ -27,6 +27,10 @@ import (
"github.com/guacsec/guac/pkg/assembler/helpers"
)

func (c *arangoClient) HasSourceAtList(ctx context.Context, hasSourceAtSpec model.HasSourceAtSpec, after *string, first *int) (*model.HasSourceAtConnection, error) {
return nil, fmt.Errorf("not implemented: HasSourceAtList")
}

func (c *arangoClient) HasSourceAt(ctx context.Context, hasSourceAtSpec *model.HasSourceAtSpec) ([]*model.HasSourceAt, error) {

if hasSourceAtSpec != nil && hasSourceAtSpec.ID != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/assembler/backends/arangodb/hashEqual.go
Expand Up @@ -26,6 +26,10 @@ import (
"github.com/guacsec/guac/pkg/assembler/graphql/model"
)

func (c *arangoClient) HashEqualList(ctx context.Context, hashEqualSpec model.HashEqualSpec, after *string, first *int) (*model.HashEqualConnection, error) {
return nil, fmt.Errorf("not implemented: HashEqualList")
}

func (c *arangoClient) HashEqual(ctx context.Context, hashEqualSpec *model.HashEqualSpec) ([]*model.HashEqual, error) {

if hashEqualSpec != nil && hashEqualSpec.ID != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/assembler/backends/arangodb/isDependency.go
Expand Up @@ -54,6 +54,10 @@ func checkPkgNameDependency(isDependencySpec *model.IsDependencySpec) bool {

// Query IsDependency

func (c *arangoClient) IsDependencyList(ctx context.Context, isDependencySpec model.IsDependencySpec, after *string, first *int) (*model.IsDependencyConnection, error) {
return nil, fmt.Errorf("not implemented: IsDependencyList")
}

func (c *arangoClient) IsDependency(ctx context.Context, isDependencySpec *model.IsDependencySpec) ([]*model.IsDependency, error) {

if isDependencySpec != nil && isDependencySpec.ID != nil {
Expand Down
5 changes: 5 additions & 0 deletions pkg/assembler/backends/arangodb/isOccurrence.go
Expand Up @@ -28,6 +28,11 @@ import (
)

// Query IsOccurrence

func (c *arangoClient) IsOccurrenceList(ctx context.Context, isOccurrenceSpec model.IsOccurrenceSpec, after *string, first *int) (*model.IsOccurrenceConnection, error) {
return nil, fmt.Errorf("not implemented: IsOccurrenceList")
}

func (c *arangoClient) IsOccurrence(ctx context.Context, isOccurrenceSpec *model.IsOccurrenceSpec) ([]*model.IsOccurrence, error) {

if isOccurrenceSpec != nil && isOccurrenceSpec.ID != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/assembler/backends/arangodb/license.go
Expand Up @@ -25,6 +25,10 @@ import (
"github.com/guacsec/guac/pkg/assembler/graphql/model"
)

func (c *arangoClient) LicenseList(ctx context.Context, licenseSpec model.LicenseSpec, after *string, first *int) (*model.LicenseConnection, error) {
return nil, fmt.Errorf("not implemented: LicenseList")
}

func (c *arangoClient) Licenses(ctx context.Context, licenseSpec *model.LicenseSpec) ([]*model.License, error) {
values := map[string]any{}
aqb := setLicenseMatchValues(licenseSpec, values)
Expand Down
4 changes: 4 additions & 0 deletions pkg/assembler/backends/arangodb/path.go
Expand Up @@ -124,6 +124,10 @@ IN 1..@maxLength ANY K_PATHS
return foundNodes, nil
}

func (c *arangoClient) NeighborsList(ctx context.Context, node string, usingOnly []model.Edge, after *string, first *int) (*model.NeighborConnection, error) {
return nil, fmt.Errorf("not implemented: NeighborsList")
}

// TODO (pxp928): investigate if the individual neighbor queries (within nouns and verbs) can be done co-currently
func (c *arangoClient) Neighbors(ctx context.Context, nodeID string, usingOnly []model.Edge) ([]model.Node, error) {
var neighborsID []string
Expand Down
4 changes: 4 additions & 0 deletions pkg/assembler/backends/arangodb/pkg.go
Expand Up @@ -368,6 +368,10 @@ func setPkgVersionMatchValues(pkgSpec *model.PkgSpec, queryValues map[string]any
return arangoQueryBuilder
}

func (c *arangoClient) PackagesList(ctx context.Context, pkgSpec model.PkgSpec, after *string, first *int) (*model.PackageConnection, error) {
return nil, fmt.Errorf("not implemented: PackagesList")
}

func (c *arangoClient) Packages(ctx context.Context, pkgSpec *model.PkgSpec) ([]*model.Package, error) {
if pkgSpec != nil && pkgSpec.ID != nil {
p, err := c.buildPackageResponseFromID(ctx, *pkgSpec.ID, pkgSpec)
Expand Down
4 changes: 4 additions & 0 deletions pkg/assembler/backends/arangodb/pkgEqual.go
Expand Up @@ -28,6 +28,10 @@ import (
purl "github.com/package-url/packageurl-go"
)

func (c *arangoClient) PkgEqualList(ctx context.Context, pkgEqualSpec model.PkgEqualSpec, after *string, first *int) (*model.PkgEqualConnection, error) {
return nil, fmt.Errorf("not implemented: PkgEqualList")
}

func (c *arangoClient) PkgEqual(ctx context.Context, pkgEqualSpec *model.PkgEqualSpec) ([]*model.PkgEqual, error) {

if pkgEqualSpec != nil && pkgEqualSpec.ID != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/assembler/backends/arangodb/pointOfContact.go
Expand Up @@ -33,6 +33,10 @@ const (
sinceStr string = "since"
)

func (c *arangoClient) PointOfContactList(ctx context.Context, pointOfContactSpec model.PointOfContactSpec, after *string, first *int) (*model.PointOfContactConnection, error) {
return nil, fmt.Errorf("not implemented: PointOfContactList")
}

func (c *arangoClient) PointOfContact(ctx context.Context, pointOfContactSpec *model.PointOfContactSpec) ([]*model.PointOfContact, error) {

if pointOfContactSpec != nil && pointOfContactSpec.ID != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/assembler/backends/arangodb/search.go
Expand Up @@ -23,6 +23,10 @@ import (
"github.com/guacsec/guac/pkg/assembler/graphql/model"
)

func (c *arangoClient) FindSoftwareList(ctx context.Context, searchText string, after *string, first *int) (*model.FindSoftwareConnection, error) {
return nil, fmt.Errorf("not implemented: FindSoftwareList")
}

// TODO(lumjjb): add source when it is implemented in arango backend
func (c *arangoClient) FindSoftware(ctx context.Context, searchText string) ([]model.PackageSourceOrArtifact, error) {

Expand Down
4 changes: 4 additions & 0 deletions pkg/assembler/backends/arangodb/src.go
Expand Up @@ -270,6 +270,10 @@ func setSrcMatchValues(srcSpec *model.SourceSpec, queryValues map[string]any) *a
return arangoQueryBuilder
}

func (c *arangoClient) SourcesList(ctx context.Context, sourceSpec model.SourceSpec, after *string, first *int) (*model.SourceConnection, error) {
return nil, fmt.Errorf("not implemented: SourcesList")
}

func (c *arangoClient) Sources(ctx context.Context, sourceSpec *model.SourceSpec) ([]*model.Source, error) {
if sourceSpec != nil && sourceSpec.ID != nil {
p, err := c.buildSourceResponseFromID(ctx, *sourceSpec.ID, sourceSpec)
Expand Down
5 changes: 5 additions & 0 deletions pkg/assembler/backends/arangodb/vulnEqual.go
Expand Up @@ -28,6 +28,11 @@ import (
)

// Query VulnEqual

func (c *arangoClient) VulnEqualList(ctx context.Context, vulnEqualSpec model.VulnEqualSpec, after *string, first *int) (*model.VulnEqualConnection, error) {
return nil, fmt.Errorf("not implemented: VulnEqualList")
}

func (c *arangoClient) VulnEqual(ctx context.Context, vulnEqualSpec *model.VulnEqualSpec) ([]*model.VulnEqual, error) {

if vulnEqualSpec != nil && vulnEqualSpec.ID != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/assembler/backends/arangodb/vulnMetadata.go
Expand Up @@ -33,6 +33,10 @@ const (
timeStampStr string = "timestamp"
)

func (c *arangoClient) VulnerabilityMetadataList(ctx context.Context, vulnerabilityMetadataSpec model.VulnerabilityMetadataSpec, after *string, first *int) (*model.VulnerabilityMetadataConnection, error) {
return nil, fmt.Errorf("not implemented: VulnerabilityMetadataList")
}

func (c *arangoClient) VulnerabilityMetadata(ctx context.Context, vulnerabilityMetadataSpec *model.VulnerabilityMetadataSpec) ([]*model.VulnerabilityMetadata, error) {

if vulnerabilityMetadataSpec != nil && vulnerabilityMetadataSpec.ID != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/assembler/backends/arangodb/vulnerability.go
Expand Up @@ -44,6 +44,10 @@ type dbVulnType struct {
VulnType string `json:"type"`
}

func (c *arangoClient) VulnerabilityList(ctx context.Context, vulnSpec model.VulnerabilitySpec, after *string, first *int) (*model.VulnerabilityConnection, error) {
return nil, fmt.Errorf("not implemented: VulnerabilityList")
}

func (c *arangoClient) Vulnerabilities(ctx context.Context, vulnSpec *model.VulnerabilitySpec) ([]*model.Vulnerability, error) {

if vulnSpec != nil && vulnSpec.NoVuln != nil && *vulnSpec.NoVuln {
Expand Down
28 changes: 28 additions & 0 deletions pkg/assembler/backends/backends.go
Expand Up @@ -33,6 +33,32 @@ type Backend interface {
Sources(ctx context.Context, sourceSpec *model.SourceSpec) ([]*model.Source, error)
Vulnerabilities(ctx context.Context, vulnSpec *model.VulnerabilitySpec) ([]*model.Vulnerability, error)

// Paginated Retrieval read-only queries for software trees
ArtifactsList(ctx context.Context, artifactSpec model.ArtifactSpec, after *string, first *int) (*model.ArtifactConnection, error)
BuildersList(ctx context.Context, builderSpec model.BuilderSpec, after *string, first *int) (*model.BuilderConnection, error)
LicenseList(ctx context.Context, licenseSpec model.LicenseSpec, after *string, first *int) (*model.LicenseConnection, error)
PackagesList(ctx context.Context, pkgSpec model.PkgSpec, after *string, first *int) (*model.PackageConnection, error)
SourcesList(ctx context.Context, sourceSpec model.SourceSpec, after *string, first *int) (*model.SourceConnection, error)
VulnerabilityList(ctx context.Context, vulnSpec model.VulnerabilitySpec, after *string, first *int) (*model.VulnerabilityConnection, error)

CertifyBadList(ctx context.Context, certifyBadSpec model.CertifyBadSpec, after *string, first *int) (*model.CertifyBadConnection, error)
CertifyGoodList(ctx context.Context, certifyGoodSpec model.CertifyGoodSpec, after *string, first *int) (*model.CertifyGoodConnection, error)
CertifyLegalList(ctx context.Context, certifyLegalSpec model.CertifyLegalSpec, after *string, first *int) (*model.CertifyLegalConnection, error)
ScorecardsList(ctx context.Context, scorecardSpec model.CertifyScorecardSpec, after *string, first *int) (*model.CertifyScorecardConnection, error)
CertifyVEXStatementList(ctx context.Context, certifyVEXStatementSpec model.CertifyVEXStatementSpec, after *string, first *int) (*model.VEXConnection, error)
CertifyVulnList(ctx context.Context, certifyVulnSpec model.CertifyVulnSpec, after *string, first *int) (*model.CertifyVulnConnection, error)
PointOfContactList(ctx context.Context, pointOfContactSpec model.PointOfContactSpec, after *string, first *int) (*model.PointOfContactConnection, error)
HashEqualList(ctx context.Context, hashEqualSpec model.HashEqualSpec, after *string, first *int) (*model.HashEqualConnection, error)
HasSBOMList(ctx context.Context, hasSBOMSpec model.HasSBOMSpec, after *string, first *int) (*model.HasSBOMConnection, error)
HasSLSAList(ctx context.Context, hasSLSASpec model.HasSLSASpec, after *string, first *int) (*model.HasSLSAConnection, error)
HasSourceAtList(ctx context.Context, hasSourceAtSpec model.HasSourceAtSpec, after *string, first *int) (*model.HasSourceAtConnection, error)
IsDependencyList(ctx context.Context, isDependencySpec model.IsDependencySpec, after *string, first *int) (*model.IsDependencyConnection, error)
IsOccurrenceList(ctx context.Context, isOccurrenceSpec model.IsOccurrenceSpec, after *string, first *int) (*model.IsOccurrenceConnection, error)
HasMetadataList(ctx context.Context, hasMetadataSpec model.HasMetadataSpec, after *string, first *int) (*model.HasMetadataConnection, error)
PkgEqualList(ctx context.Context, pkgEqualSpec model.PkgEqualSpec, after *string, first *int) (*model.PkgEqualConnection, error)
VulnEqualList(ctx context.Context, vulnEqualSpec model.VulnEqualSpec, after *string, first *int) (*model.VulnEqualConnection, error)
VulnerabilityMetadataList(ctx context.Context, vulnerabilityMetadataSpec model.VulnerabilityMetadataSpec, after *string, first *int) (*model.VulnerabilityMetadataConnection, error)

// Retrieval read-only queries for evidence trees
CertifyBad(ctx context.Context, certifyBadSpec *model.CertifyBadSpec) ([]*model.CertifyBad, error)
CertifyGood(ctx context.Context, certifyGoodSpec *model.CertifyGoodSpec) ([]*model.CertifyGood, error)
Expand Down Expand Up @@ -104,12 +130,14 @@ type Backend interface {

// Topological queries: queries where node connectivity matters more than node type
Neighbors(ctx context.Context, node string, usingOnly []model.Edge) ([]model.Node, error)
NeighborsList(ctx context.Context, node string, usingOnly []model.Edge, after *string, first *int) (*model.NeighborConnection, error)
Node(ctx context.Context, node string) (model.Node, error)
Nodes(ctx context.Context, nodes []string) ([]model.Node, error)
Path(ctx context.Context, subject string, target string, maxPathLength int, usingOnly []model.Edge) ([]model.Node, error)

// Search queries: queries to help find data in GUAC based on text search
FindSoftware(ctx context.Context, searchText string) ([]model.PackageSourceOrArtifact, error)
FindSoftwareList(ctx context.Context, searchText string, after *string, first *int) (*model.FindSoftwareConnection, error)
}

// BackendArgs interface allows each backend to specify the arguments needed to
Expand Down
47 changes: 47 additions & 0 deletions pkg/assembler/backends/ent/backend/artifact.go
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"strings"

"entgo.io/contrib/entgql"
"entgo.io/ent/dialect/sql"
"github.com/google/uuid"
"github.com/guacsec/guac/internal/testing/ptrfrom"
Expand All @@ -34,6 +35,52 @@ import (
"github.com/vektah/gqlparser/v2/gqlerror"
)

func (b *EntBackend) ArtifactsList(ctx context.Context, artifactSpec model.ArtifactSpec, after *string, first *int) (*model.ArtifactConnection, error) {
var afterCursor *entgql.Cursor[uuid.UUID]

if after != nil {
afterUUID, err := uuid.Parse(*after)
if err != nil {
return nil, err
}
afterCursor = &ent.Cursor{ID: afterUUID}
} else {
afterCursor = nil
}

query, err := b.client.Artifact.Query().
Where(artifactQueryPredicates(&artifactSpec)).
Limit(MaxPageSize).
Paginate(ctx, afterCursor, first, nil, nil)

if err != nil {
return nil, err
}

var edges []*model.ArtifactEdge
for _, edge := range query.Edges {
edges = append(edges, &model.ArtifactEdge{
Cursor: edge.Cursor.ID.String(),
Node: toModelArtifact(edge.Node),
})
}

if query.PageInfo.StartCursor != nil {
return &model.ArtifactConnection{
TotalCount: query.TotalCount,
PageInfo: &model.PageInfo{
HasNextPage: query.PageInfo.HasNextPage,
StartCursor: ptrfrom.String(query.PageInfo.StartCursor.ID.String()),
EndCursor: ptrfrom.String(query.PageInfo.EndCursor.ID.String()),
},
Edges: edges,
}, nil
} else {
// if not found return nil
return nil, nil
}
}

func (b *EntBackend) Artifacts(ctx context.Context, artifactSpec *model.ArtifactSpec) ([]*model.Artifact, error) {
if artifactSpec == nil {
artifactSpec = &model.ArtifactSpec{}
Expand Down

0 comments on commit d861241

Please sign in to comment.