Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Commit

Permalink
cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
Alva8756 committed Apr 24, 2024
1 parent d7ccd88 commit 55c6e92
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/equinix-labs/otel-init-go v0.0.9
github.com/gin-gonic/gin v1.9.1
github.com/google/uuid v1.6.0
github.com/metal-toolbox/alloy v0.3.3-0.20240320183632-05dfbd5e9110
github.com/metal-toolbox/alloy v0.3.3-0.20240415055734-d09250fed38a
github.com/metal-toolbox/fleetdb v0.17.2-0.20240419204835-60c421433f0a
github.com/metal-toolbox/rivets v1.0.3
github.com/pkg/errors v0.9.1
Expand Down
7 changes: 3 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -500,12 +500,11 @@ github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-sqlite3 v1.14.14 h1:qZgc/Rwetq+MtyE18WhzjokPD93dNqLGNT3QJuLvBGw=
github.com/mattn/go-sqlite3 v1.14.14/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-sqlite3 v2.0.1+incompatible h1:xQ15muvnzGBHpIpdrNi1DA5x0+TcBZzsIDwmw9uTHzw=
github.com/mattn/go-sqlite3 v2.0.1+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/metal-toolbox/alloy v0.3.3-0.20240320183632-05dfbd5e9110 h1:v3PTHUK9KIF/mEmctQ5mgsBtG8dtdfboHI/7QQg/Ft0=
github.com/metal-toolbox/alloy v0.3.3-0.20240320183632-05dfbd5e9110/go.mod h1:NcVZtbVhBCcpyTHew0TJ8yzon69vMf+rGMLoGb9jTa0=
github.com/metal-toolbox/alloy v0.3.3-0.20240415055734-d09250fed38a h1:w6uita6zAXZoGn75vcnEDW2Y6K1rYeLWnv7EXAemByE=
github.com/metal-toolbox/alloy v0.3.3-0.20240415055734-d09250fed38a/go.mod h1:Sv+oD+xnACNV3E7r9kmtgUi1LGKQumTv7mpWOe8a2VU=
github.com/metal-toolbox/fleetdb v0.17.2-0.20240419204835-60c421433f0a h1:Jrjbk0M8EiljlgxeLso232AizQzuaQ4Bnqf8L9ITkug=
github.com/metal-toolbox/fleetdb v0.17.2-0.20240419204835-60c421433f0a/go.mod h1:U9YArAdibILSBJzNbmtJAz6m+Cljce6a7pL0JkOckqQ=
github.com/metal-toolbox/rivets v1.0.3 h1:ZW9q8V3vz6VxAczC4eR1YJdl+kapHF3ebVc+4r3NmR8=
Expand Down
12 changes: 7 additions & 5 deletions internal/fleetdb/fleetdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ func NewFleetDBClient(ctx context.Context, cfg *app.Configuration) (Client, erro
}

type fleetDBClient struct {
client *fleetdb.Client
// We may want to support slug refresh.
client *fleetdb.Client
slugs map[string]*fleetdb.ServerComponentType
inventoryConverterInstance *inventoryconverter.InventoryConverter
}
Expand All @@ -60,13 +59,16 @@ func (fc fleetDBClient) GetComponents(ctx context.Context, id uuid.UUID, params
return fc.client.GetComponents(ctx, id, params)
}

func (fc fleetDBClient) UpdateServerInventory(ctx context.Context, server *fleetdb.Server, dev *types.InventoryDevice, _ *zap.Logger, inband bool) error {
typeServer, err := fc.inventoryConverterInstance.ToRivetsServer(server.UUID.String(), server.FacilityCode, dev.Inv, *dev.BiosCfg)
func (fc fleetDBClient) UpdateServerInventory(ctx context.Context, server *fleetdb.Server, dev *types.InventoryDevice, log *zap.Logger, inband bool) error {
log.Info("update server inventory", zap.String("server", server.Name))
rivetsServer, err := fc.inventoryConverterInstance.ToRivetsServer(server.UUID.String(), server.FacilityCode, dev.Inv, dev.BiosCfg)
if err != nil {
log.Error("convert inventory fail", zap.String("server", server.Name), zap.String("err", err.Error()))
return err
}
_, err = fc.client.SetServerInventory(ctx, server.UUID, typeServer, inband)
_, err = fc.client.SetServerInventory(ctx, server.UUID, rivetsServer, inband)
if err != nil {
log.Error("set inventory fail", zap.String("server", server.Name), zap.String("err", err.Error()))
return err
}
return nil
Expand Down
1 change: 1 addition & 0 deletions pkg/api/routes/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func processInband(ctx context.Context, c internalfleetdb.Client, server *fleetd
func processOutofband(ctx context.Context, c internalfleetdb.Client, server *fleetdb.Server, dev *types.InventoryDevice, log *zap.Logger) error { //nolint
log.Info("processing", zap.String("server", server.Name), zap.String("device", dev.Inv.Serial))
if err := verifyComponent(c, server, dev, log); err != nil {
log.Error("verify component", zap.String("server", server.Name), zap.String("err", err.Error()))
return err
}
return c.UpdateServerInventory(ctx, server, dev, log, false)
Expand Down
5 changes: 5 additions & 0 deletions pkg/api/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ func composeInventoryHandler(theApp *app.App, fn inventoryHandler) gin.HandlerFu
return
}

if dev.Inv == nil {
reject(ctx, http.StatusBadRequest, "empty inventory")

Check failure on line 228 in pkg/api/routes/routes.go

View workflow job for this annotation

GitHub Actions / lint-test

not enough arguments in call to reject

Check failure on line 228 in pkg/api/routes/routes.go

View workflow job for this annotation

GitHub Actions / lint-test

not enough arguments in call to reject

Check failure on line 228 in pkg/api/routes/routes.go

View workflow job for this annotation

GitHub Actions / lint-test

not enough arguments in call to reject

Check failure on line 228 in pkg/api/routes/routes.go

View workflow job for this annotation

GitHub Actions / lint-test

not enough arguments in call to reject
return
}

fleetDBClient, err := internalfleetdb.NewFleetDBClient(ctx, theApp.Cfg)
if err != nil {
ctx.JSON(http.StatusInternalServerError, map[string]any{
Expand Down

0 comments on commit 55c6e92

Please sign in to comment.