parent
5067ca04da
commit
c33a7e27b6
5 changed files with 59 additions and 7 deletions
@ -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,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, |
||||
}); |
||||
|
@ -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…
Reference in new issue