Skip to content

Commit

Permalink
Fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtesseract committed Aug 5, 2022
1 parent 436d1af commit 6ea0646
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
2 changes: 1 addition & 1 deletion e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ var _ = Describe("Central", func() {

var createdCentral *public.CentralRequest
var namespaceName string
It("created a central with custom resource configuration", func() {
It("should create central with custom resource configuration", func() {
createdCentral, err = adminClient.CreateCentral(request)
Expect(err).To(BeNil())
namespaceName, err = services.FormatNamespace(createdCentral.Id)
Expand Down
48 changes: 27 additions & 21 deletions internal/dinosaur/pkg/handlers/dinosaur.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"net/http"

"github.com/golang/glog"
"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/api/dbapi"

"github.com/stackrox/acs-fleet-manager/internal/dinosaur/pkg/api/public"
Expand Down Expand Up @@ -34,33 +35,38 @@ func NewDinosaurHandler(service services.DinosaurService, providerConfig *config
}
}

func validateResourcesUnspecified(ctx context.Context, component string, dinosaurRequest *public.CentralRequestPayload) handlers.Validate {
fields := map[string]string{
"resources.requests.cpu": dinosaurRequest.Central.Resources.Requests.Cpu,
"resources.requests.memory": dinosaurRequest.Central.Resources.Requests.Memory,
"resources.limits.cpu": dinosaurRequest.Central.Resources.Limits.Cpu,
"resources.limits.memory": dinosaurRequest.Central.Resources.Limits.Memory,
}

validateFunc := func() *errors.ServiceError {
for k, v := range fields {
if v != "" {
return errors.Forbidden("not allowed to specify %s resources (%s)", component, k)
}
func validateCentralResourcesUnspecified(ctx context.Context, dinosaurRequest *public.CentralRequestPayload) handlers.Validate {
return func() *errors.ServiceError {
glog.Errorf("[validateCentralResourcesUnspecified] req = %v\n", dinosaurRequest)

if dinosaurRequest.Central.Resources.Limits.Cpu != "" ||
dinosaurRequest.Central.Resources.Limits.Memory != "" ||
dinosaurRequest.Central.Resources.Requests.Cpu != "" ||
dinosaurRequest.Central.Resources.Requests.Memory != "" {
return errors.Forbidden("not allowed to specify central resources")
}
return nil
}

return validateFunc

}

func validateCentralResourcesUnspecified(ctx context.Context, dinosaurRequest *public.CentralRequestPayload) handlers.Validate {
return validateResourcesUnspecified(ctx, "central", dinosaurRequest)
}

func validateScannerResourcesUnspecified(ctx context.Context, dinosaurRequest *public.CentralRequestPayload) handlers.Validate {
return validateResourcesUnspecified(ctx, "scanner", dinosaurRequest)
return func() *errors.ServiceError {
glog.Errorf("[validateScannerResourcesUnspecified] req = %v\n", dinosaurRequest)

if dinosaurRequest.Scanner.Analyzer.Resources.Limits.Cpu != "" ||
dinosaurRequest.Scanner.Analyzer.Resources.Limits.Memory != "" ||
dinosaurRequest.Scanner.Analyzer.Resources.Requests.Cpu != "" ||
dinosaurRequest.Scanner.Analyzer.Resources.Requests.Memory != "" {
return errors.Forbidden("not allowed to specify scanner analyzer resources")
}
if dinosaurRequest.Scanner.Db.Resources.Limits.Cpu != "" ||
dinosaurRequest.Scanner.Db.Resources.Limits.Memory != "" ||
dinosaurRequest.Scanner.Db.Resources.Requests.Cpu != "" ||
dinosaurRequest.Scanner.Db.Resources.Requests.Memory != "" {
return errors.Forbidden("not allowed to specify scanner db resources")
}
return nil
}
}

// Create ...
Expand Down
2 changes: 1 addition & 1 deletion internal/dinosaur/pkg/routes/route_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func (s *options) buildAPIBaseRouter(mainRouter *mux.Router, basePath string, op
Methods(http.MethodPatch)

adminCreateRouter := adminDinosaursRouter.NewRoute().Subrouter()
adminCreateRouter.HandleFunc("", dinosaurHandler.Create).Methods(http.MethodPost)
adminCreateRouter.HandleFunc("", adminDinosaurHandler.Create).Methods(http.MethodPost)

return nil
}

0 comments on commit 6ea0646

Please sign in to comment.