parent
72e070bc38
commit
e31d4564ee
6 changed files with 108 additions and 39 deletions
@ -0,0 +1,41 @@ |
||||
import { buildKnownIDCondition } from '../../buildCondition'; |
||||
import { buildQueryResultModifier } from '../../buildQueryResultModifier'; |
||||
import { stdout } from '../../shell'; |
||||
|
||||
export const buildQueryHostDetail: BuildQueryDetailFunction = ({ |
||||
keys: hostUUIDs = '*', |
||||
} = {}) => { |
||||
const condHostUUIDs = buildKnownIDCondition(hostUUIDs, 'AND hos.host_uuid'); |
||||
|
||||
stdout(`condHostUUIDs=[${condHostUUIDs}]`); |
||||
|
||||
const query = ` |
||||
SELECT |
||||
hos.host_name, |
||||
hos.host_uuid, |
||||
var.variable_name, |
||||
var.variable_value |
||||
FROM variables AS var |
||||
JOIN hosts AS hos |
||||
ON var.variable_source_uuid = hos.host_uuid |
||||
WHERE variable_name LIKE 'form::config_%' |
||||
${condHostUUIDs};`;
|
||||
|
||||
const afterQueryReturn: QueryResultModifierFunction = |
||||
buildQueryResultModifier((output) => { |
||||
const [hostName, hostUUID] = output[0]; |
||||
|
||||
return output.reduce< |
||||
{ hostName: string; hostUUID: string } & Record<string, string> |
||||
>( |
||||
(previous, [, variableName, variableValue]) => { |
||||
previous[variableName] = variableValue; |
||||
|
||||
return previous; |
||||
}, |
||||
{ hostName, hostUUID }, |
||||
); |
||||
}); |
||||
|
||||
return { query, afterQueryReturn }; |
||||
}; |
@ -0,0 +1,17 @@ |
||||
import buildGetRequestHandler from '../buildGetRequestHandler'; |
||||
import { buildQueryHostDetail } from './buildQueryHostDetail'; |
||||
import { sanitizeSQLParam } from '../../sanitizeSQLParam'; |
||||
|
||||
export const getHostDetail = buildGetRequestHandler( |
||||
({ params: { hostUUID } }, buildQueryOptions) => { |
||||
const { afterQueryReturn, query } = buildQueryHostDetail({ |
||||
keys: [sanitizeSQLParam(hostUUID)], |
||||
}); |
||||
|
||||
if (buildQueryOptions) { |
||||
buildQueryOptions.afterQueryReturn = afterQueryReturn; |
||||
} |
||||
|
||||
return query; |
||||
}, |
||||
); |
@ -1,3 +1,4 @@ |
||||
export * from './createHost'; |
||||
export * from './getHost'; |
||||
export * from './getHostConnection'; |
||||
export * from './getHostDetail'; |
||||
|
Loading…
Reference in new issue