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. 48
      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] = {
hostUUID,
ipAddress,
ipAddressUUID,
networkLinkNumber: Number(rawNetworkLinkNumber),
networkNumber: Number(rawNetworkNumber),
networkType,
};
},
);
result = connections;
}
return result; const [, networkType, rNetworkNumber, rNetworkLinkNumber] = match(
}; ifaceId,
/^(.*n)(\d+)_link(\d+)$/,
);
const connectionKey = getConnectionKey(hostUuid);
connections[connectionKey].inbound.ipAddress[ip] = {
hostUUID: hostUuid,
ipAddress: ip,
ipAddressUUID: ipUuid,
networkLinkNumber: Number(rNetworkLinkNumber),
networkNumber: Number(rNetworkNumber),
networkType,
};
return previous;
},
connections,
);
} }
return `SELECT return `SELECT

Loading…
Cancel
Save