fix(striker-ui-api): add short host name to GET /host

main
Tsu-ba-me 2 years ago
parent 3a79010af0
commit 81974ef626
  1. 2
      striker-ui-api/src/lib/getShortHostName.ts
  2. 37
      striker-ui-api/src/lib/request_handlers/host/getHost.ts
  3. 1
      striker-ui-api/src/types/HostOverview.d.ts

@ -0,0 +1,2 @@
export const getShortHostName = (hostName: string) =>
hostName.replace(/[.].*$/, '');

@ -1,7 +1,9 @@
import { getLocalHostUUID } from '../../accessModule'; import { getLocalHostUUID } from '../../accessModule';
import buildGetRequestHandler from '../buildGetRequestHandler'; import buildGetRequestHandler from '../buildGetRequestHandler';
import { buildQueryHostDetail } from './buildQueryHostDetail'; import { buildQueryHostDetail } from './buildQueryHostDetail';
import { buildQueryResultReducer } from '../../buildQueryResultModifier';
import { toLocal } from '../../convertHostUUID'; import { toLocal } from '../../convertHostUUID';
import { getShortHostName } from '../../getShortHostName';
import { sanitize } from '../../sanitize'; import { sanitize } from '../../sanitize';
export const getHost = buildGetRequestHandler((request, buildQueryOptions) => { export const getHost = buildGetRequestHandler((request, buildQueryOptions) => {
@ -14,26 +16,21 @@ export const getHost = buildGetRequestHandler((request, buildQueryOptions) => {
hos.host_name, hos.host_name,
hos.host_uuid hos.host_uuid
FROM hosts AS hos;`; FROM hosts AS hos;`;
let afterQueryReturn: QueryResultModifierFunction | undefined = ( let afterQueryReturn: QueryResultModifierFunction | undefined =
output: unknown, buildQueryResultReducer<{ [hostUUID: string]: HostOverview }>(
) => { (previous, [hostName, hostUUID]) => {
let result = output; const key = toLocal(hostUUID, localHostUUID);
if (output instanceof Array) { previous[key] = {
result = output.reduce<Record<string, HostOverview>>( hostName,
(previous, [hostName, hostUUID]) => { hostUUID,
const key = toLocal(hostUUID, localHostUUID); shortHostName: getShortHostName(hostName),
};
previous[key] = { hostName, hostUUID };
return previous;
return previous; },
}, {},
{}, );
);
}
return result;
};
if (hostUUIDs) { if (hostUUIDs) {
({ query, afterQueryReturn } = buildQueryHostDetail({ ({ query, afterQueryReturn } = buildQueryHostDetail({

@ -1,4 +1,5 @@
type HostOverview = { type HostOverview = {
hostName: string; hostName: string;
hostUUID: string; hostUUID: string;
shortHostName: string;
}; };

Loading…
Cancel
Save