fix(striker-ui-api): check bad keys regardless of peer conn success

main^2
Tsu-ba-me 7 months ago
parent ce0c36af33
commit 7b1ea9c56c
  1. 73
      striker-ui-api/src/lib/request_handlers/command/getHostSSH.ts
  2. 2
      striker-ui-api/src/middlewares/proxyServerVnc.ts
  3. 2
      striker-ui-api/src/types/ApiCommand.d.ts
  4. 2
      striker-ui-api/src/types/ApiSshKey.d.ts
  5. 5
      striker-ui-api/src/types/ErrorResponse.d.ts

@ -7,13 +7,13 @@ import {
REP_PEACEFUL_STRING,
} from '../../consts';
import { getLocalHostUUID, getPeerData, query } from '../../accessModule';
import { getPeerData, query } from '../../accessModule';
import { sanitize } from '../../sanitize';
import { perr } from '../../shell';
export const getHostSSH: RequestHandler<
unknown,
GetHostSshResponseBody,
GetHostSshResponseBody | ErrorResponseBody,
GetHostSshRequestBody
> = async (request, response) => {
const {
@ -45,35 +45,60 @@ export const getHostSSH: RequestHandler<
return response.status(400).send();
}
const localHostUUID = getLocalHostUUID();
let rsbody: GetHostSshResponseBody;
try {
rsbody = await getPeerData(target, { password, port });
} catch (subError) {
perr(`Failed to get peer data; CAUSE: ${subError}`);
} catch (error) {
const emsg = `Failed to get peer data; CAUSE: ${error}`;
perr(emsg);
const rserror: ErrorResponseBody = {
code: 'fe14fb1',
message: emsg,
name: 'AccessError',
};
return response.status(500).send(rserror);
}
let states: [string, string][];
return response.status(500).send();
try {
states = await query<[stateUuid: string, hostUuid: string][]>(`
SELECT a.state_uuid, a.state_host_uuid
FROM states AS a
WHERE a.state_name = '${HOST_KEY_CHANGED_PREFIX}${target}';`);
} catch (error) {
const emsg = `Failed to list SSH key conflicts; CAUSE: ${error}`;
perr(emsg);
const rserror: ErrorResponseBody = {
code: 'd5a2acf',
message: emsg,
name: 'AccessError',
};
return response.status(500).send(rserror);
}
if (!rsbody.isConnected) {
const rows: [stateNote: string, stateUUID: string][] = await query(`
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}${target}';`);
if (rows.length > 0) {
rsbody.badSSHKeys = rows.reduce<DeleteSshKeyConflictRequestBody>(
(previous, [, stateUUID]) => {
previous[localHostUUID].push(stateUUID);
return previous;
},
{ [localHostUUID]: [] },
);
}
if (states.length > 0) {
rsbody.badSshKeys = states.reduce<DeleteSshKeyConflictRequestBody>(
(previous, state) => {
const [stateUuid, hostUuid] = state;
const { [hostUuid]: list = [] } = previous;
list.push(stateUuid);
previous[hostUuid] = list;
return previous;
},
{},
);
}
response.status(200).send(rsbody);

@ -49,7 +49,7 @@ export const proxyServerVnc = createProxyMiddleware({
const serverUuid = getServerUuid(request.url);
const errapiName = cname(`vncerror.${serverUuid}`);
const errapiObj = {
const errapiObj: ErrorResponseBody = {
code: '72c969b',
message: error.message,
name: error.name,

@ -5,7 +5,7 @@ type GetHostSshRequestBody = {
};
type GetHostSshResponseBody = {
badSSHKeys?: DeleteSshKeyConflictRequestBody;
badSshKeys?: DeleteSshKeyConflictRequestBody;
hostName: string;
hostOS: string;
hostUUID: string;

@ -9,4 +9,4 @@ type SshKeyConflict = {
};
};
type DeleteSshKeyConflictRequestBody = { [hostUUID: string]: string[] };
type DeleteSshKeyConflictRequestBody = Record<string, string[]>;

@ -0,0 +1,5 @@
type ErrorResponseBody = {
code: string;
message: string;
name: string;
};
Loading…
Cancel
Save