From ce66bde29e066fe6fbc7500fd080e213d9312d3c Mon Sep 17 00:00:00 2001 From: Doctor Vince Date: Fri, 30 Aug 2024 11:03:51 -0400 Subject: [PATCH] update fleetdb when a validation is successful --- internal/flipflop/handler.go | 7 ++++++- internal/store/fleetdb/client.go | 4 ++-- internal/store/fleetdb/fleetdb.go | 6 ++++++ internal/store/store.go | 4 ++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/internal/flipflop/handler.go b/internal/flipflop/handler.go index e12becb..fc1d527 100644 --- a/internal/flipflop/handler.go +++ b/internal/flipflop/handler.go @@ -262,7 +262,12 @@ func (cth *ConditionTaskHandler) validateFirmware(ctx context.Context) error { return cth.failedWithError(ctx, "failed to retrieve host boot status", err) } if booted { - // TODO: record successful result in fleetdb before returning + done := time.Now() + srvID := cth.task.Parameters.AssetID + fwID := cth.task.Parameters.ValidateFirmwareID + if dbErr := cth.store.ValidateFirmwareSet(ctx, srvID, fwID, done); dbErr != nil { + return cth.failedWithError(ctx, "marking firmware set validated", dbErr) + } return nil } } diff --git a/internal/store/fleetdb/client.go b/internal/store/fleetdb/client.go index edab13f..3e15ffd 100644 --- a/internal/store/fleetdb/client.go +++ b/internal/store/fleetdb/client.go @@ -85,8 +85,8 @@ func newFleetDBClientWithOAuthOtel(ctx context.Context, cfg *Config, logger *log return nil, err } - // clientID defaults to 'alloy' - clientID := "alloy" + // clientID defaults to 'flipflop' + clientID := "flipflop" if cfg.OidcClientID != "" { clientID = cfg.OidcClientID diff --git a/internal/store/fleetdb/fleetdb.go b/internal/store/fleetdb/fleetdb.go index 73bfce5..292cd8c 100644 --- a/internal/store/fleetdb/fleetdb.go +++ b/internal/store/fleetdb/fleetdb.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "net" + "time" "github.com/google/uuid" "github.com/metal-toolbox/flipflop/internal/model" @@ -180,3 +181,8 @@ func serverAttributes(attributes []fleetdbapi.Attributes) (map[string]string, er return sAttributes, nil } + +// ValidateFirmwareSet reaches out to FleetDB to record that this firmware set has been successfully tested. +func (s *Store) ValidateFirmwareSet(ctx context.Context, srvID, fwID uuid.UUID, done time.Time) error { + return s.api.ValidateFirmwareSet(ctx, srvID, fwID, done) +} diff --git a/internal/store/store.go b/internal/store/store.go index 6b239ac..93f782e 100644 --- a/internal/store/store.go +++ b/internal/store/store.go @@ -2,7 +2,9 @@ package store import ( "context" + "time" + "github.com/google/uuid" "github.com/metal-toolbox/flipflop/internal/model" "github.com/metal-toolbox/flipflop/internal/store/fleetdb" "github.com/pkg/errors" @@ -12,6 +14,8 @@ import ( type Repository interface { // AssetByID returns asset based on the identifier. AssetByID(ctx context.Context, assetID string) (*model.Asset, error) + // ValidateFirmwareSet marks the set as successfully tested + ValidateFirmwareSet(context.Context, uuid.UUID, uuid.UUID, time.Time) error } func NewRepository(ctx context.Context, storeKind model.StoreKind, cfg *fleetdb.Config, logger *logrus.Logger) (Repository, error) {