fix(striker-ui-api): make required endpoints public when striker is not configured

main
Tsu-ba-me 2 years ago
parent 5067ca04da
commit c33a7e27b6
  1. 9
      striker-ui-api/src/lib/request_handlers/host/createHost.ts
  2. 1
      striker-ui-api/src/lib/request_handlers/host/index.ts
  3. 4
      striker-ui-api/src/lib/request_handlers/host/updateHost.ts
  4. 2
      striker-ui-api/src/routes/index.ts
  5. 50
      striker-ui-api/src/routes/init.ts

@ -1,8 +1,5 @@
import { RequestHandler } from 'express';
import { buildBranchRequestHandler } from '../buildBranchRequestHandler';
import { configStriker } from './configStriker';
export const createHost: RequestHandler = buildBranchRequestHandler({
striker: configStriker,
});
export const createHost: RequestHandler = (request, response) => {
return response.status(204).send();
};

@ -1,3 +1,4 @@
export * from './configStriker';
export * from './createHost';
export * from './createHostConnection';
export * from './deleteHostConnection';

@ -1,8 +1,10 @@
import { RequestHandler } from 'express';
import { buildBranchRequestHandler } from '../buildBranchRequestHandler';
import { configStriker } from './configStriker';
import { setHostInstallTarget } from './setHostInstallTarget';
export const updateHost: RequestHandler = buildBranchRequestHandler({
'install-target': setHostInstallTarget,
'install-target': setHostInstallTarget as RequestHandler,
striker: configStriker,
});

@ -5,6 +5,7 @@ import echoRouter from './echo';
import fenceRouter from './fence';
import fileRouter from './file';
import hostRouter from './host';
import initRouter from './init';
import jobRouter from './job';
import manifestRouter from './manifest';
import networkInterfaceRouter from './network-interface';
@ -32,6 +33,7 @@ const routes = {
public: {
auth: authRouter,
echo: echoRouter,
init: initRouter,
},
static: staticRouter,
};

@ -0,0 +1,50 @@
import express from 'express';
import { getLocalHostUUID, query } from '../lib/accessModule';
import { stderr, stdoutVar } from '../lib/shell';
import { setMapNetwork } from '../lib/request_handlers/command';
import { configStriker } from '../lib/request_handlers/host';
import { getNetworkInterface } from '../lib/request_handlers/network-interface';
const router = express.Router();
router.use(async (request, response, next) => {
const localHostUuid = getLocalHostUUID();
let rows: [[string]];
try {
rows = await query(
`SELECT variable_value
FROM variables
WHERE variable_name = 'system::configured'
AND variable_source_table = 'hosts'
AND variable_source_uuid = '${localHostUuid}'
LIMIT 1;`,
);
} catch (error) {
stderr(`Failed to get system configured flag; CAUSE: ${error}`);
return response.status(500).send();
}
stdoutVar(rows, `system::configured=`);
if (rows.length === 1 && rows[0][0] === '1') {
stderr(
`The init endpoints cannot be used after initializing the local striker`,
);
return response.status(401).send();
}
return next();
});
router
.get('/network-interface', getNetworkInterface)
.post('/', configStriker)
.put('/set-map-network', setMapNetwork);
export default router;
Loading…
Cancel
Save