fix(striker-ui-api): simplify query result handling in GET host connection

main^2
Tsu-ba-me 7 months ago
parent aaa0a9cfea
commit 4dd1733200
  1. 40
      striker-ui-api/src/lib/request_handlers/host/getHostConnection.ts

@ -1,6 +1,7 @@
import { getDatabaseConfigData, getLocalHostUUID } from '../../accessModule'; import { getDatabaseConfigData, getLocalHostUUID } from '../../accessModule';
import { buildUnknownIDCondition } from '../../buildCondition'; import { buildUnknownIDCondition } from '../../buildCondition';
import buildGetRequestHandler from '../buildGetRequestHandler'; import buildGetRequestHandler from '../buildGetRequestHandler';
import { buildQueryResultReducer } from '../../buildQueryResultModifier';
import { toLocal } from '../../convertHostUUID'; import { toLocal } from '../../convertHostUUID';
import { match } from '../../match'; import { match } from '../../match';
import { pout, poutvar } from '../../shell'; import { pout, poutvar } from '../../shell';
@ -88,32 +89,29 @@ export const getHostConnection = buildGetRequestHandler(
poutvar(connections, 'connections='); poutvar(connections, 'connections=');
if (buildQueryOptions) { if (buildQueryOptions) {
buildQueryOptions.afterQueryReturn = (queryStdout) => { buildQueryOptions.afterQueryReturn = buildQueryResultReducer(
let result = queryStdout; (previous, row) => {
const [ipUuid, hostUuid, ip, ifaceId] = row;
if (queryStdout instanceof Array) {
queryStdout.forEach(
([ipAddressUUID, hostUUID, ipAddress, network]) => {
const [, networkType, rawNetworkNumber, rawNetworkLinkNumber] =
match(network, /^([^\s]+)(\d+)_[^\s]+(\d+)$/);
const connectionKey = getConnectionKey(hostUUID);
connections[connectionKey].inbound.ipAddress[ipAddress] = { const [, networkType, rNetworkNumber, rNetworkLinkNumber] = match(
hostUUID, ifaceId,
ipAddress, /^(.*n)(\d+)_link(\d+)$/,
ipAddressUUID, );
networkLinkNumber: Number(rawNetworkLinkNumber), const connectionKey = getConnectionKey(hostUuid);
networkNumber: Number(rawNetworkNumber),
connections[connectionKey].inbound.ipAddress[ip] = {
hostUUID: hostUuid,
ipAddress: ip,
ipAddressUUID: ipUuid,
networkLinkNumber: Number(rNetworkLinkNumber),
networkNumber: Number(rNetworkNumber),
networkType, networkType,
}; };
return previous;
}, },
connections,
); );
result = connections;
}
return result;
};
} }
return `SELECT return `SELECT

Loading…
Cancel
Save