feat(striker-ui-api): add /command/inquire-peer

main
Tsu-ba-me 2 years ago
parent e67e732fd8
commit 5424fc3858
  1. 65
      striker-ui-api/src/lib/request_handlers/command/getHostSSH.ts
  2. 1
      striker-ui-api/src/lib/request_handlers/command/index.ts
  3. 2
      striker-ui-api/src/routes/command.ts

@ -0,0 +1,65 @@
import { RequestHandler } from 'express';
import { sub } from '../../accessModule';
import { stderr } from '../../shell';
export const getHostSSH: RequestHandler<
unknown,
{
hostName: string;
hostOS: string;
hostUUID: string;
isConnected: boolean;
isInetConnected: boolean;
isOSRegistered: boolean;
},
{
password: string;
port?: number;
ipAddress: string;
}
> = (request, response) => {
const {
body: { password, port = 22, ipAddress: target },
} = request;
let hostName: string,
hostOS: string,
hostUUID: string,
rawIsInetConnected: string,
rawIsOSRegistered: string;
try {
({
host_name: hostName,
host_os: hostOS,
host_uuid: hostUUID,
internet: rawIsInetConnected,
os_registered: rawIsOSRegistered,
} = sub('get_peer_data', {
subModuleName: 'Striker',
subParams: { password, port, target },
}).stdout as {
host_name: string;
host_os: string;
host_uuid: string;
internet: string;
os_registered: string;
});
} catch (subError) {
stderr(`Failed to get peer data; CAUSE: ${subError}`);
response.status(500).send();
return;
}
response.status(200).send({
hostName,
hostOS,
hostUUID,
isConnected: hostName.length > 0,
isInetConnected: rawIsInetConnected === '1',
isOSRegistered: rawIsOSRegistered === 'yes',
});
};

@ -1,3 +1,4 @@
export * from './getHostSSH';
export * from './poweroffHost'; export * from './poweroffHost';
export * from './rebootHost'; export * from './rebootHost';
export * from './updateSystem'; export * from './updateSystem';

@ -1,6 +1,7 @@
import express from 'express'; import express from 'express';
import { import {
getHostSSH,
poweroffHost, poweroffHost,
rebootHost, rebootHost,
updateSystem, updateSystem,
@ -9,6 +10,7 @@ import {
const router = express.Router(); const router = express.Router();
router router
.put('/inquire-peer', getHostSSH)
.put('/poweroff-host', poweroffHost) .put('/poweroff-host', poweroffHost)
.put('/reboot-host', rebootHost) .put('/reboot-host', rebootHost)
.put('/update-system', updateSystem); .put('/update-system', updateSystem);

Loading…
Cancel
Save