Skip to content

Commit

Permalink
Merge adbd29c into c13930c
Browse files Browse the repository at this point in the history
  • Loading branch information
matthyx committed Apr 17, 2023
2 parents c13930c + adbd29c commit 8153053
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 26 deletions.
33 changes: 11 additions & 22 deletions adapters/mockplatform.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package adapters

import (
"context"
"errors"

"github.com/kubescape/go-logger"
"github.com/kubescape/go-logger/helpers"
"github.com/kubescape/kubevuln/core/domain"
"github.com/kubescape/kubevuln/core/ports"
"go.opentelemetry.io/otel"
)

// MockPlatform implements a mocked Platform to be used for tests
Expand All @@ -18,37 +17,27 @@ var _ ports.Platform = (*MockPlatform)(nil)

// NewMockPlatform initializes the MockPlatform struct
func NewMockPlatform() *MockPlatform {
logger.L().Info("NewMockPlatform")
logger.L().Info("keepLocal config is true, statuses and scan reports won't be sent to Armo cloud")
return &MockPlatform{}
}

// GetCVEExceptions returns an empty CVEExceptions
func (m MockPlatform) GetCVEExceptions(_ context.Context) (domain.CVEExceptions, error) {
logger.L().Info("GetCVEExceptions")
func (m MockPlatform) GetCVEExceptions(ctx context.Context) (domain.CVEExceptions, error) {
_, span := otel.Tracer("").Start(ctx, "MockPlatform.GetCVEExceptions")
defer span.End()
return domain.CVEExceptions{}, nil
}

// SendStatus logs the given status and details
func (m MockPlatform) SendStatus(ctx context.Context, step int) error {
// retrieve workload from context
workload, ok := ctx.Value(domain.WorkloadKey{}).(domain.ScanCommand)
if !ok {
return errors.New("no workload found in context")
}

logger.L().Info(
"SendStatus",
helpers.String("wlid", workload.Wlid),
helpers.Int("step", step),
)
func (m MockPlatform) SendStatus(ctx context.Context, _ int) error {
_, span := otel.Tracer("").Start(ctx, "MockPlatform.SendStatus")
defer span.End()
return nil
}

// SubmitCVE logs the given ID for CVE calculation
func (m MockPlatform) SubmitCVE(_ context.Context, cve domain.CVEManifest, _ domain.CVEManifest) error {
logger.L().Info(
"SubmitCVE",
helpers.String("ID", cve.ID),
)
func (m MockPlatform) SubmitCVE(ctx context.Context, _ domain.CVEManifest, _ domain.CVEManifest) error {
_, span := otel.Tracer("").Start(ctx, "MockPlatform.SubmitCVE")
defer span.End()
return nil
}
4 changes: 1 addition & 3 deletions adapters/mockplatform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ func TestMockPlatform_GetCVEExceptions(t *testing.T) {
func TestMockPlatform_SendStatus(t *testing.T) {
m := NewMockPlatform()
ctx := context.TODO()
err := m.SendStatus(ctx, domain.Done)
assert.Assert(t, err != nil)
ctx = context.WithValue(ctx, domain.WorkloadKey{}, domain.ScanCommand{})
err = m.SendStatus(ctx, domain.Done)
err := m.SendStatus(ctx, domain.Done)
assert.Assert(t, err == nil)
}

Expand Down
9 changes: 8 additions & 1 deletion cmd/http/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import (
"github.com/gin-gonic/gin"
"github.com/kubescape/go-logger"
"github.com/kubescape/go-logger/helpers"
"github.com/kubescape/kubevuln/adapters"
"github.com/kubescape/kubevuln/adapters/v1"
"github.com/kubescape/kubevuln/config"
"github.com/kubescape/kubevuln/controllers"
"github.com/kubescape/kubevuln/core/ports"
"github.com/kubescape/kubevuln/core/services"
"github.com/kubescape/kubevuln/repositories"
"go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin"
Expand Down Expand Up @@ -52,7 +54,12 @@ func main() {
}
sbomAdapter := v1.NewSyftAdapter(c.ScanTimeout, c.MaxImageSize)
cveAdapter := v1.NewGrypeAdapter()
platform := v1.NewArmoAdapter(c.AccountID, c.BackendOpenAPI, c.EventReceiverRestURL)
var platform ports.Platform
if c.KeepLocal {
platform = adapters.NewMockPlatform()
} else {
platform = v1.NewArmoAdapter(c.AccountID, c.BackendOpenAPI, c.EventReceiverRestURL)
}
service := services.NewScanService(sbomAdapter, storage, cveAdapter, storage, platform, c.Storage)
controller := controllers.NewHTTPController(service, c.ScanConcurrency)

Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Config struct {
BackendOpenAPI string `mapstructure:"backendOpenAPI"`
ClusterName string `mapstructure:"clusterName"`
EventReceiverRestURL string `mapstructure:"eventReceiverRestURL"`
KeepLocal bool `mapstructure:"keepLocal"`
MaxImageSize int64 `mapstructure:"maxImageSize"`
ScanConcurrency int `mapstructure:"scanConcurrency"`
ScanTimeout time.Duration `mapstructure:"scanTimeout"`
Expand Down

0 comments on commit 8153053

Please sign in to comment.