From 0aec411e1abab12b64386e1a8c17f1c6b89321d9 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Tue, 8 Nov 2022 18:32:44 -0500 Subject: [PATCH] feat(striker-ui-api): add GET /ssh-key --- .../lib/request_handlers/ssh-key/getSSHKey.ts | 19 +++++++++++++------ .../src/lib/request_handlers/ssh-key/index.ts | 1 + striker-ui-api/src/routes/index.ts | 2 ++ striker-ui-api/src/routes/ssh-key.ts | 9 +++++++++ 4 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 striker-ui-api/src/lib/request_handlers/ssh-key/index.ts create mode 100644 striker-ui-api/src/routes/ssh-key.ts diff --git a/striker-ui-api/src/lib/request_handlers/ssh-key/getSSHKey.ts b/striker-ui-api/src/lib/request_handlers/ssh-key/getSSHKey.ts index b951c1c8..a9e65604 100644 --- a/striker-ui-api/src/lib/request_handlers/ssh-key/getSSHKey.ts +++ b/striker-ui-api/src/lib/request_handlers/ssh-key/getSSHKey.ts @@ -1,6 +1,7 @@ import { getLocalHostUUID } from '../../accessModule'; -import { buildQueryResultReducer } from '../../buildQueryResultModifier'; import buildGetRequestHandler from '../buildGetRequestHandler'; +import { buildQueryResultReducer } from '../../buildQueryResultModifier'; +import { match } from '../../match'; import { sanitizeQS } from '../../sanitizeQS'; type BuildQuerySubFunction = (result: Parameters[0]) => { @@ -18,11 +19,11 @@ const MAP_TO_HANDLER: Record = { afterQueryReturn: buildQueryResultReducer<{ [hostUUID: string]: { [stateUUID: string]: { + badFile: string; + badLine: number; hostName: string; hostUUID: string; ipAddress: string; - stateName: string; - stateNote: string; stateUUID: string; }; }; @@ -33,12 +34,18 @@ const MAP_TO_HANDLER: Record = { previous[hostUUIDKey] = {}; } + const ipAddress = stateName.slice(HOST_KEY_CHANGED_PREFIX.length); + const [, badFile, badLine = '0'] = match( + stateNote, + /file=([^\s]+),line=(\d+)/, + ); + previous[hostUUIDKey][stateUUID] = { + badFile, + badLine: parseInt(badLine), hostName, hostUUID, - ipAddress: stateName.slice(HOST_KEY_CHANGED_PREFIX.length), - stateName, - stateNote, + ipAddress, stateUUID, }; diff --git a/striker-ui-api/src/lib/request_handlers/ssh-key/index.ts b/striker-ui-api/src/lib/request_handlers/ssh-key/index.ts new file mode 100644 index 00000000..feebf33a --- /dev/null +++ b/striker-ui-api/src/lib/request_handlers/ssh-key/index.ts @@ -0,0 +1 @@ +export * from './getSSHKey'; diff --git a/striker-ui-api/src/routes/index.ts b/striker-ui-api/src/routes/index.ts index 03d8ebc1..a7c9147c 100644 --- a/striker-ui-api/src/routes/index.ts +++ b/striker-ui-api/src/routes/index.ts @@ -8,6 +8,7 @@ import hostRouter from './host'; import jobRouter from './job'; import networkInterfaceRouter from './network-interface'; import serverRouter from './server'; +import sshKeyRouter from './ssh-key'; import userRouter from './user'; const routes: Readonly> = { @@ -19,6 +20,7 @@ const routes: Readonly> = { job: jobRouter, 'network-interface': networkInterfaceRouter, server: serverRouter, + 'ssh-key': sshKeyRouter, user: userRouter, }; diff --git a/striker-ui-api/src/routes/ssh-key.ts b/striker-ui-api/src/routes/ssh-key.ts new file mode 100644 index 00000000..4fc8b8da --- /dev/null +++ b/striker-ui-api/src/routes/ssh-key.ts @@ -0,0 +1,9 @@ +import express from 'express'; + +import { getSSHKey } from '../lib/request_handlers/ssh-key'; + +const router = express.Router(); + +router.get('/', getSSHKey); + +export default router;