Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Included a Handler for CycloneDX Version Ranges #1789

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/testing/cmd/ingest/cmd/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type options struct {
graphqlEndpoint string
}

func ingestExample(cmd *cobra.Command, args []string) {
func ingestExample(cmd *cobra.Command, args []string, gqlClient graphql.Client) {
ctx := logging.WithLogger(context.Background())
logger := logging.FromContext(ctx)

Expand All @@ -59,7 +59,7 @@ func ingestExample(cmd *cobra.Command, args []string) {
var inputs []assembler.IngestPredicates
for _, doc := range docs {
// This is a test example, so we will ignore calling out to a collectsub service
input, _, err := parser.ParseDocumentTree(ctx, doc)
input, _, err := parser.ParseDocumentTree(ctx, doc, gqlClient)
if err != nil {
logger.Fatalf("unable to parse document: %v", err)
}
Expand Down
6 changes: 5 additions & 1 deletion internal/testing/cmd/ingest/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package cmd
import (
"context"
"fmt"
"github.com/Khan/genqlient/graphql"
"net/http"
"os"
"strings"

Expand Down Expand Up @@ -85,7 +87,9 @@ var rootCmd = &cobra.Command{
Use: "ingest",
Short: "example ingestor for ingesting a set of example documents and populating a graph for GUAC",
Run: func(cmd *cobra.Command, args []string) {
ingestExample(cmd, args)
httpClient := http.Client{}
Copy link
Collaborator

@pxp928 pxp928 Jun 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we will need to refactor this. We don't want to be querying graphQL on ingestion. Will need to re-work this after some thought.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will make it an issue to discuss during the next maintainer meeting.

gqlClient := graphql.NewClient(flags.graphqlEndpoint, &httpClient)
ingestExample(cmd, args, gqlClient)
},
}

Expand Down
17 changes: 17 additions & 0 deletions pkg/assembler/clients/generated/operations.go

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

1 change: 1 addition & 0 deletions pkg/assembler/clients/operations/trees.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ fragment AllPkgTree on Package {
name
versions {
id
purl
version
qualifiers {
key
Expand Down
14 changes: 10 additions & 4 deletions pkg/ingestor/ingestor.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ func Ingest(
transport http.RoundTripper,
csubClient csub_client.Client,
) error {
httpClient := http.Client{}
gqlclient := graphql.NewClient(graphqlEndpoint, &httpClient)

logger := d.ChildLogger
// Get pipeline of components
processorFunc := GetProcessor(ctx)
ingestorFunc := GetIngestor(ctx)
ingestorFunc := GetIngestor(ctx, gqlclient)
collectSubEmitFunc := GetCollectSubEmit(ctx, csubClient)
assemblerFunc := GetAssembler(ctx, d.ChildLogger, graphqlEndpoint, transport)

Expand Down Expand Up @@ -83,10 +86,13 @@ func MergedIngest(
transport http.RoundTripper,
csubClient csub_client.Client,
) error {
httpClient := http.Client{}
gqlclient := graphql.NewClient(graphqlEndpoint, &httpClient)

logger := logging.FromContext(ctx)
// Get pipeline of components
processorFunc := GetProcessor(ctx)
ingestorFunc := GetIngestor(ctx)
ingestorFunc := GetIngestor(ctx, gqlclient)
collectSubEmitFunc := GetCollectSubEmit(ctx, csubClient)
assemblerFunc := GetAssembler(ctx, logger, graphqlEndpoint, transport)

Expand Down Expand Up @@ -159,9 +165,9 @@ func GetProcessor(ctx context.Context) func(*processor.Document) (processor.Docu
}
}

func GetIngestor(ctx context.Context) func(processor.DocumentTree) ([]assembler.IngestPredicates, []*parser_common.IdentifierStrings, error) {
func GetIngestor(ctx context.Context, gqlClient graphql.Client) func(processor.DocumentTree) ([]assembler.IngestPredicates, []*parser_common.IdentifierStrings, error) {
return func(doc processor.DocumentTree) ([]assembler.IngestPredicates, []*parser_common.IdentifierStrings, error) {
return parser.ParseDocumentTree(ctx, doc)
return parser.ParseDocumentTree(ctx, doc, gqlClient)
}
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/ingestor/parser/csaf/parser_csaf.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package csaf
import (
"context"
"fmt"
"github.com/Khan/genqlient/graphql"
"strconv"

jsoniter "github.com/json-iterator/go"
Expand Down Expand Up @@ -68,7 +69,7 @@ type visitedProductRef struct {
category string
}

func NewCsafParser() common.DocumentParser {
func NewCsafParser(gqlClient graphql.Client) common.DocumentParser {
return &csafParser{
identifierStrings: &common.IdentifierStrings{},
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/ingestor/parser/csaf/parser_csaf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func Test_csafParser(t *testing.T) {
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := NewCsafParser()
s := NewCsafParser(nil)
err := s.Parse(ctx, tt.doc)
if (err != nil) != tt.wantErr {
t.Errorf("csafParse.Parse() error = %v, wantErr %v", err, tt.wantErr)
Expand Down Expand Up @@ -295,7 +295,7 @@ func Test_csafParser_GetIdentifiers(t *testing.T) {
},
}

c := NewCsafParser()
c := NewCsafParser(nil)

err := c.Parse(test.ctx, test.fields.doc)
if err != nil {
Expand Down
Loading
Loading