fix(striker-ui-api): include network type, link uuid in host detail response

main
Tsu-ba-me 1 year ago
parent c1589eba3c
commit 6874218e3c
  1. 41
      striker-ui-api/src/lib/request_handlers/host/buildQueryHostDetail.ts

@ -5,6 +5,7 @@ import { getShortHostName } from '../../disassembleHostName';
import { stdout } from '../../shell';
const CVAR_PREFIX = 'form::config_step';
const CVAR_PREFIX_PATTERN = `^${CVAR_PREFIX}\\d+::`;
const MAP_TO_EXTRACTOR: Record<string, (parts: string[]) => string[]> = {
form: ([, part2]) => {
@ -53,11 +54,22 @@ export const buildQueryHostDetail: BuildQueryDetailFunction = ({
a.variable_name,
a.variable_value,
SUBSTRING(
a.variable_name, '^${CVAR_PREFIX}\\d+::([^:]+)'
) as cvar_name
a.variable_name, '${CVAR_PREFIX_PATTERN}([^:]+)'
) as cvar_name,
SUBSTRING(
a.variable_name, '${CVAR_PREFIX_PATTERN}([a-z]{2,3})\\d+'
) AS network_type,
SUBSTRING(
a.variable_name, '${CVAR_PREFIX_PATTERN}[a-z]{2,3}\\d+_(link\\d+)'
) AS network_link,
c.network_interface_uuid
FROM variables AS a
JOIN hosts AS b
ON a.variable_source_uuid = b.host_uuid
LEFT JOIN network_interfaces AS c
ON a.variable_name LIKE '%link%_mac%'
AND a.variable_value = c.network_interface_mac_address
AND b.host_uuid = c.network_interface_host_uuid
WHERE (
variable_name LIKE '${CVAR_PREFIX}%'
OR variable_name = 'install-target::enabled'
@ -79,13 +91,36 @@ export const buildQueryHostDetail: BuildQueryDetailFunction = ({
shortHostName: string;
} & Tree
>(
(previous, [, , , variableName, variableValue]) => {
(
previous,
[
,
,
,
variableName,
variableValue,
,
networkType,
networkLink,
networkInterfaceUuid,
],
) => {
const [variablePrefix, ...restVariableParts] =
variableName.split('::');
const keychain = MAP_TO_EXTRACTOR[variablePrefix](restVariableParts);
setCvar(keychain, variableValue, previous);
if (networkLink) {
keychain[keychain.length - 1] = `${networkLink}Uuid`;
setCvar(keychain, networkInterfaceUuid, previous);
} else if (networkType) {
keychain[keychain.length - 1] = 'type';
setCvar(keychain, networkType, previous);
}
return previous;
},
{ hostName, hostType, hostUUID, shortHostName },

Loading…
Cancel
Save