fix(striker-ui-api): add set host config::map_network variable command endpoint

main
Tsu-ba-me 2 years ago
parent 322f1c4607
commit f56f931599
  1. 1
      striker-ui-api/src/lib/request_handlers/command/index.ts
  2. 70
      striker-ui-api/src/lib/request_handlers/command/setMapNetwork.ts
  3. 2
      striker-ui-api/src/routes/command.ts
  4. 4
      striker-ui-api/src/types/ApiCommand.d.ts
  5. 6
      striker-ui-api/src/types/InsertOrUpdateVariableFunction.d.ts

@ -4,6 +4,7 @@ export * from './leaveAn';
export * from './poweroffStriker'; export * from './poweroffStriker';
export * from './rebootStriker'; export * from './rebootStriker';
export * from './runManifest'; export * from './runManifest';
export * from './setMapNetwork';
export * from './startAn'; export * from './startAn';
export * from './startSubnode'; export * from './startSubnode';
export * from './stopAn'; export * from './stopAn';

@ -0,0 +1,70 @@
import assert from 'assert';
import { RequestHandler } from 'express';
import { LOCAL, REP_UUID } from '../../consts';
import { variable } from '../../accessModule';
import { toHostUUID } from '../../convertHostUUID';
import { sanitize } from '../../sanitize';
import { stderr, stdoutVar } from '../../shell';
export const setMapNetwork: RequestHandler<
{ uuid: string },
undefined,
SetMapNetworkRequestBody
> = async (request, response) => {
const {
body: { value: rValue } = {},
params: { uuid: rHostUuid },
} = request;
const value = sanitize(rValue, 'number');
let hostUuid = sanitize(rHostUuid, 'string', { fallback: LOCAL });
hostUuid = toHostUUID(hostUuid);
stdoutVar({ hostUuid, value }, `Set map network variable with: `);
try {
assert(
value in [0, 1],
`Variable value must be a number boolean (0 or 1); got [${value}]`,
);
assert(
REP_UUID.test(hostUuid),
`Host UUID must be a valid UUIDv4; got [${hostUuid}]`,
);
} catch (error) {
stderr(`Assert failed when set map network variable; CAUSE: ${error}`);
return response.status(400).send();
}
try {
const result = await variable({
file: __filename,
variable_default: 0,
varaible_description: 'striker_0202',
variable_name: 'config::map_network',
variable_section: 'config',
variable_source_table: 'hosts',
variable_source_uuid: hostUuid,
variable_value: value,
});
assert(
REP_UUID.test(result),
`Result must be UUID of modified record; got: [${result}]`,
);
} catch (error) {
stderr(
`Failed to set map network variable for host ${hostUuid}; CAUSE: ${error}`,
);
return response.status(500).send();
}
return response.status(204).send();
};

@ -7,6 +7,7 @@ import {
poweroffStriker, poweroffStriker,
rebootStriker, rebootStriker,
runManifest, runManifest,
setMapNetwork,
startAn, startAn,
startSubnode, startSubnode,
stopAn, stopAn,
@ -23,6 +24,7 @@ router
.put('/poweroff-host', poweroffStriker) .put('/poweroff-host', poweroffStriker)
.put('/reboot-host', rebootStriker) .put('/reboot-host', rebootStriker)
.put('/run-manifest/:manifestUuid', runManifest) .put('/run-manifest/:manifestUuid', runManifest)
.put('/set-map-network/:uuid', setMapNetwork)
.put('/start-an/:uuid', startAn) .put('/start-an/:uuid', startAn)
.put('/start-subnode/:uuid', startSubnode) .put('/start-subnode/:uuid', startSubnode)
.put('/stop-an/:uuid', stopAn) .put('/stop-an/:uuid', stopAn)

@ -13,3 +13,7 @@ type GetHostSshResponseBody = {
isInetConnected: boolean; isInetConnected: boolean;
isOSRegistered: boolean; isOSRegistered: boolean;
}; };
type SetMapNetworkRequestBody = {
value: number;
};

@ -1,13 +1,15 @@
type VariableValue = number | string;
type VariableParams = InsertOrUpdateFunctionCommonParams & { type VariableParams = InsertOrUpdateFunctionCommonParams & {
update_value_only?: NumberBoolean; update_value_only?: NumberBoolean;
variable_default?: string; variable_default?: VariableValue;
varaible_description?: string; varaible_description?: string;
variable_name?: string; variable_name?: string;
variable_section?: string; variable_section?: string;
variable_source_table?: string; variable_source_table?: string;
variable_source_uuid?: string; variable_source_uuid?: string;
variable_uuid?: string; variable_uuid?: string;
variable_value?: number | string; variable_value?: VariableValue;
}; };
type InsertOrUpdateVariableFunction = ( type InsertOrUpdateVariableFunction = (

Loading…
Cancel
Save