From f3a2a9355ee008083c0aa1d88799425fce41d395 Mon Sep 17 00:00:00 2001 From: Tsu-ba-me Date: Tue, 28 Feb 2023 16:42:09 -0500 Subject: [PATCH] feat(striker-ui-api): add /ups --- .../request_handlers/ups/getUPSTemplate.ts | 23 +++++++++++++++++++ .../src/lib/request_handlers/ups/index.ts | 1 + striker-ui-api/src/routes/index.ts | 2 ++ striker-ui-api/src/routes/ups.ts | 9 ++++++++ 4 files changed, 35 insertions(+) create mode 100644 striker-ui-api/src/lib/request_handlers/ups/getUPSTemplate.ts create mode 100644 striker-ui-api/src/lib/request_handlers/ups/index.ts create mode 100644 striker-ui-api/src/routes/ups.ts diff --git a/striker-ui-api/src/lib/request_handlers/ups/getUPSTemplate.ts b/striker-ui-api/src/lib/request_handlers/ups/getUPSTemplate.ts new file mode 100644 index 00000000..b966f806 --- /dev/null +++ b/striker-ui-api/src/lib/request_handlers/ups/getUPSTemplate.ts @@ -0,0 +1,23 @@ +import { RequestHandler } from 'express'; + +import { getAnvilData } from '../../accessModule'; +import { stderr } from '../../shell'; + +export const getUPSTemplate: RequestHandler = (request, response) => { + let rawUPSData; + + try { + ({ ups_data: rawUPSData } = getAnvilData<{ ups_data: AnvilDataUPSHash }>( + { ups_data: true }, + { predata: [['Striker->get_ups_data']] }, + )); + } catch (subError) { + stderr(`Failed to get ups template; CAUSE: ${subError}`); + + response.status(500).send(); + + return; + } + + response.status(200).send(rawUPSData); +}; diff --git a/striker-ui-api/src/lib/request_handlers/ups/index.ts b/striker-ui-api/src/lib/request_handlers/ups/index.ts new file mode 100644 index 00000000..969616cb --- /dev/null +++ b/striker-ui-api/src/lib/request_handlers/ups/index.ts @@ -0,0 +1 @@ +export * from './getUPSTemplate'; diff --git a/striker-ui-api/src/routes/index.ts b/striker-ui-api/src/routes/index.ts index e37e78f8..618e952c 100644 --- a/striker-ui-api/src/routes/index.ts +++ b/striker-ui-api/src/routes/index.ts @@ -10,6 +10,7 @@ import jobRouter from './job'; import networkInterfaceRouter from './network-interface'; import serverRouter from './server'; import sshKeyRouter from './ssh-key'; +import upsRouter from './ups'; import userRouter from './user'; const routes: Readonly> = { @@ -23,6 +24,7 @@ const routes: Readonly> = { 'network-interface': networkInterfaceRouter, server: serverRouter, 'ssh-key': sshKeyRouter, + ups: upsRouter, user: userRouter, }; diff --git a/striker-ui-api/src/routes/ups.ts b/striker-ui-api/src/routes/ups.ts new file mode 100644 index 00000000..1d19b86f --- /dev/null +++ b/striker-ui-api/src/routes/ups.ts @@ -0,0 +1,9 @@ +import express from 'express'; + +import { getUPSTemplate } from '../lib/request_handlers/ups'; + +const router = express.Router(); + +router.get('/template', getUPSTemplate); + +export default router;