|
|
@ -1,4 +1,5 @@ |
|
|
|
import { getLocalHostUUID } from '../../accessModule'; |
|
|
|
import { getLocalHostUUID } from '../../accessModule'; |
|
|
|
|
|
|
|
import { buildUnknownIDCondition } from '../../buildCondition'; |
|
|
|
import buildGetRequestHandler from '../buildGetRequestHandler'; |
|
|
|
import buildGetRequestHandler from '../buildGetRequestHandler'; |
|
|
|
import { buildQueryHostDetail } from './buildQueryHostDetail'; |
|
|
|
import { buildQueryHostDetail } from './buildQueryHostDetail'; |
|
|
|
import { buildQueryResultReducer } from '../../buildQueryResultModifier'; |
|
|
|
import { buildQueryResultReducer } from '../../buildQueryResultModifier'; |
|
|
@ -7,22 +8,36 @@ import { getShortHostName } from '../../getShortHostName'; |
|
|
|
import { sanitize } from '../../sanitize'; |
|
|
|
import { sanitize } from '../../sanitize'; |
|
|
|
|
|
|
|
|
|
|
|
export const getHost = buildGetRequestHandler((request, buildQueryOptions) => { |
|
|
|
export const getHost = buildGetRequestHandler((request, buildQueryOptions) => { |
|
|
|
const { hostUUIDs } = request.query; |
|
|
|
const { hostUUIDs, types: hostTypes } = request.query; |
|
|
|
|
|
|
|
|
|
|
|
const localHostUUID: string = getLocalHostUUID(); |
|
|
|
const localHostUUID: string = getLocalHostUUID(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { after: typeCondition } = buildUnknownIDCondition( |
|
|
|
|
|
|
|
hostTypes, |
|
|
|
|
|
|
|
'hos.host_type', |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let condition = ''; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (typeCondition.length > 0) { |
|
|
|
|
|
|
|
condition += `WHERE ${typeCondition}`; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let query = ` |
|
|
|
let query = ` |
|
|
|
SELECT |
|
|
|
SELECT |
|
|
|
hos.host_name, |
|
|
|
hos.host_name, |
|
|
|
|
|
|
|
hos.host_type, |
|
|
|
hos.host_uuid |
|
|
|
hos.host_uuid |
|
|
|
FROM hosts AS hos;`;
|
|
|
|
FROM hosts AS hos |
|
|
|
|
|
|
|
${condition};`;
|
|
|
|
let afterQueryReturn: QueryResultModifierFunction | undefined = |
|
|
|
let afterQueryReturn: QueryResultModifierFunction | undefined = |
|
|
|
buildQueryResultReducer<{ [hostUUID: string]: HostOverview }>( |
|
|
|
buildQueryResultReducer<{ [hostUUID: string]: HostOverview }>( |
|
|
|
(previous, [hostName, hostUUID]) => { |
|
|
|
(previous, [hostName, hostType, hostUUID]) => { |
|
|
|
const key = toLocal(hostUUID, localHostUUID); |
|
|
|
const key = toLocal(hostUUID, localHostUUID); |
|
|
|
|
|
|
|
|
|
|
|
previous[key] = { |
|
|
|
previous[key] = { |
|
|
|
hostName, |
|
|
|
hostName, |
|
|
|
|
|
|
|
hostType, |
|
|
|
hostUUID, |
|
|
|
hostUUID, |
|
|
|
shortHostName: getShortHostName(hostName), |
|
|
|
shortHostName: getShortHostName(hostName), |
|
|
|
}; |
|
|
|
}; |
|
|
|