fix(striker-ui-api): add bad SSH keys to /command/inquire-host

main
Tsu-ba-me 2 years ago
parent 5424fc3858
commit 7033b64bb3
  1. 1
      striker-ui-api/src/lib/consts/HOST_KEY_CHANGED_PREFIX.ts
  2. 36
      striker-ui-api/src/lib/request_handlers/command/getHostSSH.ts
  3. 2
      striker-ui-api/src/lib/request_handlers/ssh-key/deleteSSHKeyConflict.ts
  4. 4
      striker-ui-api/src/lib/request_handlers/ssh-key/getSSHKeyConflict.ts
  5. 2
      striker-ui-api/src/routes/command.ts
  6. 1
      striker-ui-api/src/types/DeleteSSHKeyConflictRequestBody.d.ts

@ -0,0 +1 @@
export const HOST_KEY_CHANGED_PREFIX = 'host_key_changed::';

@ -1,11 +1,15 @@
import { RequestHandler } from 'express';
import { sub } from '../../accessModule';
import { HOST_KEY_CHANGED_PREFIX } from '../../consts/HOST_KEY_CHANGED_PREFIX';
import { dbQuery, getLocalHostUUID, sub } from '../../accessModule';
import { sanitizeSQLParam } from '../../sanitizeSQLParam';
import { stderr } from '../../shell';
export const getHostSSH: RequestHandler<
unknown,
{
badSSHKeys?: DeleteSSHKeyConflictRequestBody;
hostName: string;
hostOS: string;
hostUUID: string;
@ -29,6 +33,8 @@ export const getHostSSH: RequestHandler<
rawIsInetConnected: string,
rawIsOSRegistered: string;
const localHostUUID = getLocalHostUUID();
try {
({
host_name: hostName,
@ -54,11 +60,37 @@ export const getHostSSH: RequestHandler<
return;
}
const isConnected: boolean = hostName.length > 0;
let badSSHKeys: DeleteSSHKeyConflictRequestBody | undefined;
if (!isConnected) {
const rows = dbQuery(`
SELECT sta.state_note, sta.state_uuid
FROM states AS sta
WHERE sta.state_host_uuid = '${localHostUUID}'
AND sta.state_name = '${HOST_KEY_CHANGED_PREFIX}${sanitizeSQLParam(
target,
)}';`).stdout as [stateNote: string, stateUUID: string][];
if (rows.length > 0) {
badSSHKeys = rows.reduce<DeleteSSHKeyConflictRequestBody>(
(previous, [, stateUUID]) => {
previous[localHostUUID].push(stateUUID);
return previous;
},
{ [localHostUUID]: [] },
);
}
}
response.status(200).send({
badSSHKeys,
hostName,
hostOS,
hostUUID,
isConnected: hostName.length > 0,
isConnected,
isInetConnected: rawIsInetConnected === '1',
isOSRegistered: rawIsOSRegistered === 'yes',
});

@ -8,7 +8,7 @@ import { stderr } from '../../shell';
export const deleteSSHKeyConflict: RequestHandler<
unknown,
undefined,
{ [hostUUID: string]: string[] }
DeleteSSHKeyConflictRequestBody
> = (request, response) => {
const { body } = request;
const hostUUIDs = Object.keys(body);

@ -1,11 +1,11 @@
import { HOST_KEY_CHANGED_PREFIX } from '../../consts/HOST_KEY_CHANGED_PREFIX';
import { getLocalHostUUID } from '../../accessModule';
import buildGetRequestHandler from '../buildGetRequestHandler';
import { buildQueryResultReducer } from '../../buildQueryResultModifier';
import { toLocal } from '../../convertHostUUID';
import { match } from '../../match';
const HOST_KEY_CHANGED_PREFIX = 'host_key_changed::';
export const getSSHKeyConflict = buildGetRequestHandler(
(request, buildQueryOptions) => {
const localHostUUID: string = getLocalHostUUID();

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

@ -0,0 +1 @@
type DeleteSSHKeyConflictRequestBody = { [hostUUID: string]: string[] };
Loading…
Cancel
Save