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'; import { stdout } from '../../shell';
const CVAR_PREFIX = 'form::config_step'; const CVAR_PREFIX = 'form::config_step';
const CVAR_PREFIX_PATTERN = `^${CVAR_PREFIX}\\d+::`;
const MAP_TO_EXTRACTOR: Record<string, (parts: string[]) => string[]> = { const MAP_TO_EXTRACTOR: Record<string, (parts: string[]) => string[]> = {
form: ([, part2]) => { form: ([, part2]) => {
@ -53,11 +54,22 @@ export const buildQueryHostDetail: BuildQueryDetailFunction = ({
a.variable_name, a.variable_name,
a.variable_value, a.variable_value,
SUBSTRING( SUBSTRING(
a.variable_name, '^${CVAR_PREFIX}\\d+::([^:]+)' a.variable_name, '${CVAR_PREFIX_PATTERN}([^:]+)'
) as cvar_name ) 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 FROM variables AS a
JOIN hosts AS b JOIN hosts AS b
ON a.variable_source_uuid = b.host_uuid 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 ( WHERE (
variable_name LIKE '${CVAR_PREFIX}%' variable_name LIKE '${CVAR_PREFIX}%'
OR variable_name = 'install-target::enabled' OR variable_name = 'install-target::enabled'
@ -79,13 +91,36 @@ export const buildQueryHostDetail: BuildQueryDetailFunction = ({
shortHostName: string; shortHostName: string;
} & Tree } & Tree
>( >(
(previous, [, , , variableName, variableValue]) => { (
previous,
[
,
,
,
variableName,
variableValue,
,
networkType,
networkLink,
networkInterfaceUuid,
],
) => {
const [variablePrefix, ...restVariableParts] = const [variablePrefix, ...restVariableParts] =
variableName.split('::'); variableName.split('::');
const keychain = MAP_TO_EXTRACTOR[variablePrefix](restVariableParts); const keychain = MAP_TO_EXTRACTOR[variablePrefix](restVariableParts);
setCvar(keychain, variableValue, previous); 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; return previous;
}, },
{ hostName, hostType, hostUUID, shortHostName }, { hostName, hostType, hostUUID, shortHostName },

Loading…
Cancel
Save