Special case host_name on the backend to enable frontend consistency (#318)

See #317 for followup to this.
This commit is contained in:
Zach Wasserman 2021-02-15 11:58:05 -08:00 committed by GitHub
parent 8107128320
commit b83fbf0ec9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 3 deletions

View file

@ -17,7 +17,7 @@ export default (client) => {
},
loadAll: (page = 1, perPage = 100, selected = '') => {
const { HOSTS, LABEL_HOSTS } = endpoints;
const pagination = `page=${page - 1}&per_page=${perPage}&order_key=host_name`;
const pagination = `page=${page - 1}&per_page=${perPage}&order_key=hostname`;
let endpoint = '';
const labelPrefix = 'labels/';

View file

@ -41,7 +41,7 @@ describe('Kolide - API client (hosts)', () => {
it('calls the label endpoint when used with label filter', () => {
const request = createRequestMock({
bearerToken,
endpoint: '/api/v1/fleet/labels/6/hosts?page=1&per_page=50&order_key=host_name',
endpoint: '/api/v1/fleet/labels/6/hosts?page=1&per_page=50&order_key=hostname',
method: 'get',
response: { hosts: [] },
});

View file

@ -15,7 +15,7 @@ export default {
valid: (bearerToken) => {
return createRequestMock({
bearerToken,
endpoint: '/api/v1/fleet/hosts?page=0&per_page=100&order_key=host_name',
endpoint: '/api/v1/fleet/hosts?page=0&per_page=100&order_key=hostname',
method: 'get',
response: { hosts: [] },
});

View file

@ -121,6 +121,11 @@ 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