From 78b75c649a46898f438759d2c91944aba66730f2 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Mon, 16 Oct 2023 05:50:36 -0400 Subject: [PATCH] fix(striker-ui-api): correct ID condition in query host detail --- striker-ui-api/src/lib/buildCondition.ts | 7 +++++-- .../src/lib/request_handlers/host/buildQueryHostDetail.ts | 4 ++-- striker-ui-api/src/lib/request_handlers/host/getHost.ts | 3 +++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/striker-ui-api/src/lib/buildCondition.ts b/striker-ui-api/src/lib/buildCondition.ts index b128322e..cdd7a99e 100644 --- a/striker-ui-api/src/lib/buildCondition.ts +++ b/striker-ui-api/src/lib/buildCondition.ts @@ -33,6 +33,9 @@ export const buildUnknownIDCondition = ( }; export const buildKnownIDCondition = ( - keys: string[] | '*' = '*', + keys: string[] | 'all' | '*' = 'all', conditionPrefix: string, -) => (keys[0] === '*' ? '' : buildIDCondition(keys, conditionPrefix)); +) => + !(keys instanceof Array) || keys.some((v) => ['all', '*'].includes(v)) + ? '' + : buildIDCondition(keys, conditionPrefix); diff --git a/striker-ui-api/src/lib/request_handlers/host/buildQueryHostDetail.ts b/striker-ui-api/src/lib/request_handlers/host/buildQueryHostDetail.ts index e0eb7855..5d6a33e2 100644 --- a/striker-ui-api/src/lib/request_handlers/host/buildQueryHostDetail.ts +++ b/striker-ui-api/src/lib/request_handlers/host/buildQueryHostDetail.ts @@ -42,7 +42,7 @@ const setCvar = ( export const buildQueryHostDetail: BuildQueryDetailFunction = ({ keys: hostUUIDs = '*', } = {}) => { - const condHostUUIDs = buildKnownIDCondition(hostUUIDs, 'a.host_uuid'); + const condHostUUIDs = buildKnownIDCondition(hostUUIDs, 'WHERE a.host_uuid'); stdout(`condHostUUIDs=[${condHostUUIDs}]`); @@ -74,7 +74,7 @@ export const buildQueryHostDetail: BuildQueryDetailFunction = ({ ON b.variable_name LIKE '%link%_mac%' AND b.variable_value = c.network_interface_mac_address AND a.host_uuid = c.network_interface_host_uuid - WHERE ${condHostUUIDs} + ${condHostUUIDs} ORDER BY a.host_name ASC, cvar_name ASC, b.variable_name ASC;`; diff --git a/striker-ui-api/src/lib/request_handlers/host/getHost.ts b/striker-ui-api/src/lib/request_handlers/host/getHost.ts index e6071d62..49d54391 100644 --- a/striker-ui-api/src/lib/request_handlers/host/getHost.ts +++ b/striker-ui-api/src/lib/request_handlers/host/getHost.ts @@ -49,6 +49,9 @@ export const getHost = buildGetRequestHandler((request, buildQueryOptions) => { ); if (hostUUIDs) { + // TODO: the output of host detail is designed to only contain one + // host, correct it to support multiple hosts to allow selecting + // multiple hosts' detail. ({ query, afterQueryReturn } = buildQueryHostDetail({ keys: sanitize(hostUUIDs, 'string[]', { modifierType: 'sql',