Skip to content

Commit

Permalink
add client API in fleedb for CIS to call
Browse files Browse the repository at this point in the history
  • Loading branch information
Alva8756 committed Apr 18, 2024
1 parent 6cbaf7b commit b5cf710
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions pkg/api/v1/server_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"path"

"github.com/google/uuid"

"github.com/metal-toolbox/fleetdb/internal/inventory"
)

const (
Expand All @@ -22,6 +24,7 @@ const (
uploadFileEndpoint = "batch-upload"
bomByMacAOCAddressEndpoint = "aoc-mac-address"
bomByMacBMCAddressEndpoint = "bmc-mac-address"
inventoryEndpoint = "inventory"
)

// ClientInterface provides an interface for the expected calls to interact with a fleetdb api
Expand Down Expand Up @@ -61,6 +64,27 @@ type ClientInterface interface {
BillOfMaterialsBatchUpload(context.Context, []Bom) (*ServerResponse, error)
GetBomInfoByAOCMacAddr(context.Context, string) (*Bom, *ServerResponse, error)
GetBomInfoByBMCMacAddr(context.Context, string) (*Bom, *ServerResponse, error)
GetInventory(context.Context, uuid.UUID, bool) (*ServerResponse, error)
SetInventory(context.Context, uuid.UUID, string, inventory.DeviceView) (*ServerResponse, error)
}

// GetInventory will get server's inventory info according to server UUID and mod ("inband" or "outofband")
func (c *Client) GetInventory(ctx context.Context, srvUUID uuid.UUID, mod string) (*ServerResponse, error) {
m := &map[string]string{}
r := ServerResponse{Record: m}

path := fmt.Sprintf("%s/%s/%s", inventoryEndpoint, srvUUID, mod)
if err := c.get(ctx, path, &r); err != nil {
return nil, err
}

return &r, nil
}

// GetInventory will get server's inventory info according to server UUID and mod ("inband" or "outofband")

Check failure on line 84 in pkg/api/v1/server_service.go

View workflow job for this annotation

GitHub Actions / lint-and-test

ST1020: comment on exported method SetInventory should be of the form "SetInventory ..." (stylecheck)
func (c *Client) SetInventory(ctx context.Context, srvUUID uuid.UUID, mod string, view inventory.DeviceView) (*ServerResponse, error) {
path := fmt.Sprintf("%s/%s/%s", inventoryEndpoint, srvUUID, mod)
return c.put(ctx, path, view)
}

// Create will attempt to create a server in Hollow and return the new server's UUID
Expand Down

0 comments on commit b5cf710

Please sign in to comment.