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

Refactor to use google/wire instead of fx #133

Merged
merged 7 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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: 4 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ jobs:
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v2
with:
go-version: '1.22.5'
- name: Install Wire
run: |
go install github.com/google/wire/cmd/wire@latest
echo "$HOME/go/bin" >> $GITHUB_PATH
naveensrinivasan marked this conversation as resolved.
Show resolved Hide resolved
- name: Build
run: make build && make git-porcelain

Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.DEFAULT_GOAL := all

# Build target
build:
build: wire
go build -o bin/minefield main.go

# Test target
Expand Down Expand Up @@ -40,6 +40,9 @@ go-mod-tidy:
git-porcelain:
git status --porcelain

all: build test docker-build go-mod-tidy git-porcelain
wire:
cd cmd/server && wire

all: build test docker-build go-mod-tidy git-porcelain wire
naveensrinivasan marked this conversation as resolved.
Show resolved Hide resolved

.PHONY: test test-e2e build clean clean-redis docker-up docker-down docker-logs docker-build all buf-generate install-buf
naveensrinivasan marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion api/v1/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestGetNodesByGlob(t *testing.T) {
func TestQueriesIngestAndCache(t *testing.T) {
s := setupService()

result, err := ingest.LoadDataFromPath(s.storage, "../../testdata/osv-sboms/google_agi.sbom.json")
result, err := ingest.LoadDataFromPath("../../testdata/osv-sboms/google_agi.sbom.json")
require.NoError(t, err)
for _, data := range result {
sbomReq := connect.NewRequest(&service.IngestSBOMRequest{
Expand Down
9 changes: 4 additions & 5 deletions cmd/ingest/ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"github.com/bitbomdev/minefield/cmd/ingest/osv"
"github.com/bitbomdev/minefield/cmd/ingest/sbom"
"github.com/bitbomdev/minefield/cmd/ingest/scorecard"
"github.com/bitbomdev/minefield/pkg/graph"
"github.com/spf13/cobra"
)

Expand All @@ -13,16 +12,16 @@
func (o *options) AddFlags(_ *cobra.Command) {
}

func New(storage graph.Storage) *cobra.Command {
func New() *cobra.Command {

Check warning on line 15 in cmd/ingest/ingest.go

View check run for this annotation

Codecov / codecov/patch

cmd/ingest/ingest.go#L15

Added line #L15 was not covered by tests
cmd := &cobra.Command{
Use: "ingest",
Short: "ingest metadata into the graph",
SilenceUsage: true,
DisableAutoGenTag: true,
}

cmd.AddCommand(osv.New(storage))
cmd.AddCommand(sbom.New(storage))
cmd.AddCommand(scorecard.New(storage))
cmd.AddCommand(osv.New())
cmd.AddCommand(sbom.New())
cmd.AddCommand(scorecard.New())

Check warning on line 25 in cmd/ingest/ingest.go

View check run for this annotation

Codecov / codecov/patch

cmd/ingest/ingest.go#L23-L25

Added lines #L23 - L25 were not covered by tests
naveensrinivasan marked this conversation as resolved.
Show resolved Hide resolved
return cmd
}
12 changes: 4 additions & 8 deletions cmd/ingest/osv/osv.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
"connectrpc.com/connect"
apiv1 "github.com/bitbomdev/minefield/gen/api/v1"
"github.com/bitbomdev/minefield/gen/api/v1/apiv1connect"
"github.com/bitbomdev/minefield/pkg/graph"
"github.com/bitbomdev/minefield/pkg/tools"
"github.com/bitbomdev/minefield/pkg/tools/ingest"
"github.com/spf13/cobra"
)

type options struct {
storage graph.Storage
addr string // Address of the minefield server
addr string // Address of the minefield server

ingestServiceClient apiv1connect.IngestServiceClient
}
Expand All @@ -37,7 +35,7 @@
}
vulnsPath := args[0]
// Ingest vulnerabilities
result, err := ingest.LoadDataFromPath(o.storage, vulnsPath)
result, err := ingest.LoadDataFromPath(vulnsPath)

Check warning on line 38 in cmd/ingest/osv/osv.go

View check run for this annotation

Codecov / codecov/patch

cmd/ingest/osv/osv.go#L38

Added line #L38 was not covered by tests
naveensrinivasan marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return fmt.Errorf("failed to load vulnerabilities: %w", err)
}
Expand All @@ -56,10 +54,8 @@
return nil
}

func New(storage graph.Storage) *cobra.Command {
o := &options{
storage: storage,
}
func New() *cobra.Command {
o := &options{}

Check warning on line 58 in cmd/ingest/osv/osv.go

View check run for this annotation

Codecov / codecov/patch

cmd/ingest/osv/osv.go#L57-L58

Added lines #L57 - L58 were not covered by tests
cmd := &cobra.Command{
Use: "osv [path to vulnerability file/dir]",
Short: "Graph vulnerability data into the graph, and connect it to existing library nodes",
Expand Down
12 changes: 4 additions & 8 deletions cmd/ingest/sbom/sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
"connectrpc.com/connect"
apiv1 "github.com/bitbomdev/minefield/gen/api/v1"
"github.com/bitbomdev/minefield/gen/api/v1/apiv1connect"
"github.com/bitbomdev/minefield/pkg/graph"
"github.com/bitbomdev/minefield/pkg/tools"
"github.com/bitbomdev/minefield/pkg/tools/ingest"
"github.com/spf13/cobra"
)

type options struct {
storage graph.Storage
addr string // Address of the minefield server
addr string // Address of the minefield server

ingestServiceClient apiv1connect.IngestServiceClient
}
Expand All @@ -38,7 +36,7 @@
}
sbomPath := args[0]
// Ingest SBOM
result, err := ingest.LoadDataFromPath(o.storage, sbomPath)
result, err := ingest.LoadDataFromPath(sbomPath)

Check warning on line 39 in cmd/ingest/sbom/sbom.go

View check run for this annotation

Codecov / codecov/patch

cmd/ingest/sbom/sbom.go#L39

Added line #L39 was not covered by tests
if err != nil {
return fmt.Errorf("failed to ingest SBOM: %w", err)
}
Expand All @@ -59,10 +57,8 @@
return nil
}

func New(storage graph.Storage) *cobra.Command {
o := &options{
storage: storage,
}
func New() *cobra.Command {
o := &options{}

Check warning on line 61 in cmd/ingest/sbom/sbom.go

View check run for this annotation

Codecov / codecov/patch

cmd/ingest/sbom/sbom.go#L60-L61

Added lines #L60 - L61 were not covered by tests
naveensrinivasan marked this conversation as resolved.
Show resolved Hide resolved
cmd := &cobra.Command{
Use: "sbom [path to sbom file/dir]",
Short: "Ingest an sbom into the graph ",
Expand Down
14 changes: 5 additions & 9 deletions cmd/ingest/scorecard/scorecard.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@
"net/http"

"connectrpc.com/connect"
"github.com/bitbomdev/minefield/gen/api/v1"
apiv1 "github.com/bitbomdev/minefield/gen/api/v1"
"github.com/bitbomdev/minefield/gen/api/v1/apiv1connect"
"github.com/bitbomdev/minefield/pkg/graph"
"github.com/bitbomdev/minefield/pkg/tools"
"github.com/bitbomdev/minefield/pkg/tools/ingest"
"github.com/spf13/cobra"
)

type options struct {
storage graph.Storage
addr string // Address of the minefield server
addr string // Address of the minefield server

ingestServiceClient apiv1connect.IngestServiceClient
}
Expand All @@ -38,7 +36,7 @@
}
scorecardPath := args[0]

result, err := ingest.LoadDataFromPath(o.storage, scorecardPath)
result, err := ingest.LoadDataFromPath(scorecardPath)

Check warning on line 39 in cmd/ingest/scorecard/scorecard.go

View check run for this annotation

Codecov / codecov/patch

cmd/ingest/scorecard/scorecard.go#L39

Added line #L39 was not covered by tests
if err != nil {
return fmt.Errorf("failed to ingest SBOM: %w", err)
}
Expand All @@ -59,10 +57,8 @@
return nil
}

func New(storage graph.Storage) *cobra.Command {
o := &options{
storage: storage,
}
func New() *cobra.Command {
o := &options{}

Check warning on line 61 in cmd/ingest/scorecard/scorecard.go

View check run for this annotation

Codecov / codecov/patch

cmd/ingest/scorecard/scorecard.go#L60-L61

Added lines #L60 - L61 were not covered by tests
cmd := &cobra.Command{
Use: "scorecard [path to scorecard file/dir]",
Short: "Graph scorecard data into the graph, and connect it to existing library nodes",
Expand Down
3 changes: 1 addition & 2 deletions cmd/leaderboard/leaderboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import (
"github.com/bitbomdev/minefield/cmd/leaderboard/custom"
"github.com/bitbomdev/minefield/cmd/leaderboard/keys"
"github.com/bitbomdev/minefield/pkg/graph"
"github.com/spf13/cobra"
)

type options struct{}

func (o *options) AddFlags(_ *cobra.Command) {}

func New(storage graph.Storage) *cobra.Command {
func New() *cobra.Command {

Check warning on line 13 in cmd/leaderboard/leaderboard.go

View check run for this annotation

Codecov / codecov/patch

cmd/leaderboard/leaderboard.go#L13

Added line #L13 was not covered by tests
naveensrinivasan marked this conversation as resolved.
Show resolved Hide resolved
o := &options{}
cmd := &cobra.Command{
Use: "leaderboard",
Expand Down
Loading
Loading