From 6b922818b89b58f7a8dcffbedda0d30e574bec6d Mon Sep 17 00:00:00 2001 From: Doctor Vince Date: Thu, 17 Oct 2024 11:41:52 -0400 Subject: [PATCH] add firmware validation client function (#271) * add firmware validation client function * Update push-pr-lint.yaml --- .github/workflows/push-pr-lint.yaml | 2 +- .golangci.yml | 3 +-- pkg/api/v1/conditions/client/client.go | 5 +++++ .../routes/firmware_validation_handlers.go | 15 ++------------- .../routes/firmware_validation_handlers_test.go | 9 +++++---- pkg/api/v1/conditions/types/types.go | 9 +++++++++ 6 files changed, 23 insertions(+), 20 deletions(-) diff --git a/.github/workflows/push-pr-lint.yaml b/.github/workflows/push-pr-lint.yaml index 7fb35cfe..95ef3d8e 100644 --- a/.github/workflows/push-pr-lint.yaml +++ b/.github/workflows/push-pr-lint.yaml @@ -17,7 +17,7 @@ jobs: uses: golangci/golangci-lint-action@v6 with: args: --config .golangci.yml --timeout 2m - version: v1.57.1 + version: v1.61.0 skip-cache: true - name: Test diff --git a/.golangci.yml b/.golangci.yml index 7fd35c62..a3e86f06 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -65,7 +65,7 @@ linters: # additional linters - bodyclose - gocritic - - goerr113 + - err113 - goimports - revive - misspell @@ -80,7 +80,6 @@ linters: - nilerr - reassign - whitespace - - exportloopref enable-all: false disable-all: true diff --git a/pkg/api/v1/conditions/client/client.go b/pkg/api/v1/conditions/client/client.go index 332bad56..8a6c925b 100644 --- a/pkg/api/v1/conditions/client/client.go +++ b/pkg/api/v1/conditions/client/client.go @@ -92,6 +92,11 @@ func (c *Client) ServerBiosControl(ctx context.Context, return c.post(ctx, path, params) } +func (c *Client) ValidateFirmwareSet(ctx context.Context, + params *v1types.FirmwareValidationRequest) (*v1types.ServerResponse, error) { + return c.post(ctx, "validateFirmware", params) +} + func (c *Client) ServerConditionCreate(ctx context.Context, serverID uuid.UUID, conditionKind rctypes.Kind, conditionCreate v1types.ConditionCreate) (*v1types.ServerResponse, error) { path := fmt.Sprintf("servers/%s/condition/%s", serverID.String(), conditionKind) diff --git a/pkg/api/v1/conditions/routes/firmware_validation_handlers.go b/pkg/api/v1/conditions/routes/firmware_validation_handlers.go index 8942c5ea..930f1e9e 100644 --- a/pkg/api/v1/conditions/routes/firmware_validation_handlers.go +++ b/pkg/api/v1/conditions/routes/firmware_validation_handlers.go @@ -1,12 +1,10 @@ package routes import ( - "encoding/json" "net/http" "time" "github.com/gin-gonic/gin" - "github.com/google/uuid" rctypes "github.com/metal-toolbox/rivets/condition" "github.com/pkg/errors" "github.com/prometheus/client_golang/prometheus" @@ -18,17 +16,8 @@ import ( v1types "github.com/metal-toolbox/conditionorc/pkg/api/v1/conditions/types" ) -type FirmwareValidationRequest struct { - ServerID uuid.UUID `json:"server_id" binding:"required,uuid4_rfc4122"` - FirmwareSetID uuid.UUID `json:"firmware_set_id" binding:"required,uuid4_rfc4122"` -} - -func (fvr FirmwareValidationRequest) AsJSON() (json.RawMessage, error) { - return json.Marshal(fvr) -} - // this is where we compose all conditions to be executed during the firmware validation task -func firmwareValidationConditions(fvr FirmwareValidationRequest) *rctypes.ServerConditions { +func firmwareValidationConditions(fvr *v1types.FirmwareValidationRequest) *rctypes.ServerConditions { createTime := time.Now() fwParams := &rctypes.FirmwareInstallTaskParameters{ @@ -88,7 +77,7 @@ func (r *Routes) validateFirmware(c *gin.Context) (int, *v1types.ServerResponse) otelCtx, span := otel.Tracer(pkgName).Start(c.Request.Context(), "Routes.validateFirmware") defer span.End() - var fvr FirmwareValidationRequest + fvr := &v1types.FirmwareValidationRequest{} if err := c.ShouldBindJSON(&fvr); err != nil { r.logger.WithError(err).Warn("unmarshal firmware validation payload") diff --git a/pkg/api/v1/conditions/routes/firmware_validation_handlers_test.go b/pkg/api/v1/conditions/routes/firmware_validation_handlers_test.go index e0257031..af46fd8d 100644 --- a/pkg/api/v1/conditions/routes/firmware_validation_handlers_test.go +++ b/pkg/api/v1/conditions/routes/firmware_validation_handlers_test.go @@ -10,6 +10,7 @@ import ( "github.com/google/uuid" "github.com/metal-toolbox/conditionorc/internal/model" "github.com/metal-toolbox/conditionorc/internal/store" + v1types "github.com/metal-toolbox/conditionorc/pkg/api/v1/conditions/types" "github.com/pkg/errors" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" @@ -40,7 +41,7 @@ func TestValidateFirmware(t *testing.T) { _, fleetdb, _, server, err := setupTestServer(t) require.NoError(t, err, "prerequisite setup") - fvr, err := FirmwareValidationRequest{ + fvr, err := v1types.FirmwareValidationRequest{ ServerID: uuid.New(), FirmwareSetID: uuid.New(), }.AsJSON() @@ -65,7 +66,7 @@ func TestValidateFirmware(t *testing.T) { FacilityCode: "fc13", } - fvr, err := FirmwareValidationRequest{ + fvr, err := v1types.FirmwareValidationRequest{ ServerID: srv.ID, FirmwareSetID: uuid.New(), }.AsJSON() @@ -101,7 +102,7 @@ func TestValidateFirmware(t *testing.T) { FacilityCode: "fc13", } - fvr, err := FirmwareValidationRequest{ + fvr, err := v1types.FirmwareValidationRequest{ ServerID: srv.ID, FirmwareSetID: uuid.New(), }.AsJSON() @@ -133,7 +134,7 @@ func TestValidateFirmware(t *testing.T) { FacilityCode: "fc13", } - fvr, err := FirmwareValidationRequest{ + fvr, err := v1types.FirmwareValidationRequest{ ServerID: srv.ID, FirmwareSetID: uuid.New(), }.AsJSON() diff --git a/pkg/api/v1/conditions/types/types.go b/pkg/api/v1/conditions/types/types.go index 861425f1..6cc3e9b3 100644 --- a/pkg/api/v1/conditions/types/types.go +++ b/pkg/api/v1/conditions/types/types.go @@ -184,3 +184,12 @@ type ServerProvisionRequest struct { NetworkConfiguration string `json:"NetworkConfiguration,omitempty"` Tags []string `json:"Tags,omitempty"` } + +type FirmwareValidationRequest struct { + ServerID uuid.UUID `json:"server_id" binding:"required,uuid4_rfc4122"` + FirmwareSetID uuid.UUID `json:"firmware_set_id" binding:"required,uuid4_rfc4122"` +} + +func (fvr FirmwareValidationRequest) AsJSON() (json.RawMessage, error) { + return json.Marshal(fvr) +}