Add aliases for order keys in API (#329)

Aliases `hostname` (`host_name`) and `memory` (`physical_memory`) when
used as keys for ordering in the API this allows for better consistency
on the frontend.

To be cleaned up further in #317
This commit is contained in:
Zach Wasserman 2021-02-16 15:25:34 -08:00 committed by GitHub
parent 8438278ba3
commit 6b5019d65e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View file

@ -121,11 +121,6 @@ func (r listHostsResponse) error() error { return r.Err }
func makeListHostsEndpoint(svc kolide.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
req := request.(listHostsRequest)
// Special case this key so that the frontend can migrate to using only "hostname"
// TODO #317 remove special cases for host_name by standardizing on hostname
if req.ListOptions.OrderKey == "hostname" {
req.ListOptions.OrderKey = "host_name"
}
hosts, err := svc.ListHosts(ctx, req.ListOptions)
if err != nil {
return listHostsResponse{Err: err}, nil

View file

@ -8,8 +8,8 @@ import (
"net/url"
"strconv"
"github.com/gorilla/mux"
"github.com/fleetdm/fleet/server/kolide"
"github.com/gorilla/mux"
"github.com/pkg/errors"
)
@ -144,6 +144,15 @@ func listOptionsFromRequest(r *http.Request) (kolide.ListOptions, error) {
}
// Special some keys so that the frontend can use consistent names.
// TODO #317 remove special cases
switch orderKey {
case "hostname":
orderKey = "host_name"
case "memory":
orderKey = "physical_memory"
}
return kolide.ListOptions{
Page: uint(page),
PerPage: uint(perPage),