feat(striker-ui-api): add GET /ssh-key

main
Tsu-ba-me 2 years ago
parent c023c08310
commit 0aec411e1a
  1. 19
      striker-ui-api/src/lib/request_handlers/ssh-key/getSSHKey.ts
  2. 1
      striker-ui-api/src/lib/request_handlers/ssh-key/index.ts
  3. 2
      striker-ui-api/src/routes/index.ts
  4. 9
      striker-ui-api/src/routes/ssh-key.ts

@ -1,6 +1,7 @@
import { getLocalHostUUID } from '../../accessModule'; import { getLocalHostUUID } from '../../accessModule';
import { buildQueryResultReducer } from '../../buildQueryResultModifier';
import buildGetRequestHandler from '../buildGetRequestHandler'; import buildGetRequestHandler from '../buildGetRequestHandler';
import { buildQueryResultReducer } from '../../buildQueryResultModifier';
import { match } from '../../match';
import { sanitizeQS } from '../../sanitizeQS'; import { sanitizeQS } from '../../sanitizeQS';
type BuildQuerySubFunction = (result: Parameters<BuildQueryFunction>[0]) => { type BuildQuerySubFunction = (result: Parameters<BuildQueryFunction>[0]) => {
@ -18,11 +19,11 @@ const MAP_TO_HANDLER: Record<string, BuildQuerySubFunction> = {
afterQueryReturn: buildQueryResultReducer<{ afterQueryReturn: buildQueryResultReducer<{
[hostUUID: string]: { [hostUUID: string]: {
[stateUUID: string]: { [stateUUID: string]: {
badFile: string;
badLine: number;
hostName: string; hostName: string;
hostUUID: string; hostUUID: string;
ipAddress: string; ipAddress: string;
stateName: string;
stateNote: string;
stateUUID: string; stateUUID: string;
}; };
}; };
@ -33,12 +34,18 @@ const MAP_TO_HANDLER: Record<string, BuildQuerySubFunction> = {
previous[hostUUIDKey] = {}; previous[hostUUIDKey] = {};
} }
const ipAddress = stateName.slice(HOST_KEY_CHANGED_PREFIX.length);
const [, badFile, badLine = '0'] = match(
stateNote,
/file=([^\s]+),line=(\d+)/,
);
previous[hostUUIDKey][stateUUID] = { previous[hostUUIDKey][stateUUID] = {
badFile,
badLine: parseInt(badLine),
hostName, hostName,
hostUUID, hostUUID,
ipAddress: stateName.slice(HOST_KEY_CHANGED_PREFIX.length), ipAddress,
stateName,
stateNote,
stateUUID, stateUUID,
}; };

@ -8,6 +8,7 @@ import hostRouter from './host';
import jobRouter from './job'; import jobRouter from './job';
import networkInterfaceRouter from './network-interface'; import networkInterfaceRouter from './network-interface';
import serverRouter from './server'; import serverRouter from './server';
import sshKeyRouter from './ssh-key';
import userRouter from './user'; import userRouter from './user';
const routes: Readonly<Record<string, Router>> = { const routes: Readonly<Record<string, Router>> = {
@ -19,6 +20,7 @@ const routes: Readonly<Record<string, Router>> = {
job: jobRouter, job: jobRouter,
'network-interface': networkInterfaceRouter, 'network-interface': networkInterfaceRouter,
server: serverRouter, server: serverRouter,
'ssh-key': sshKeyRouter,
user: userRouter, user: userRouter,
}; };

@ -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;
Loading…
Cancel
Save