summaryrefslogtreecommitdiffstats
path: root/server/api
diff options
context:
space:
mode:
authorJannik Schönartz2018-11-12 08:26:40 +0100
committerJannik Schönartz2018-11-12 08:26:40 +0100
commitb25692fdd948d25b2dcf39bd775d50849014c180 (patch)
tree45d76aa1ca78ea5dcf4937895b8d1a74934afa41 /server/api
parent[registration] add configurator for registration hooks (diff)
downloadbas-b25692fdd948d25b2dcf39bd775d50849014c180.tar.gz
bas-b25692fdd948d25b2dcf39bd775d50849014c180.tar.xz
bas-b25692fdd948d25b2dcf39bd775d50849014c180.zip
[idoit] Clients are now added to the idoit backend
Delete client in the backends if client is deleted in the bas. Add method for creating the client in the backends Add method for adding additional information to the client in the backend Add backend helper for calling all backends with the matching external id Add idoit mehtod for creating and updating a client
Diffstat (limited to 'server/api')
-rw-r--r--server/api/clients.js2
-rw-r--r--server/api/registrations.js38
2 files changed, 37 insertions, 3 deletions
diff --git a/server/api/clients.js b/server/api/clients.js
index 3e257e2..0fbb7af 100644
--- a/server/api/clients.js
+++ b/server/api/clients.js
@@ -1,6 +1,7 @@
/* global __appdir */
var path = require('path')
var db = require(path.join(__appdir, 'lib', 'sequelize'))
+const backendHelper = require(path.join(__appdir, 'lib', 'external-backends', 'backendhelper'))
// GET Requests
module.exports.get = {
@@ -42,5 +43,6 @@ module.exports.post = {
// delete clients
delete: function (req, res) {
db.client.destroy({ where: { id: req.body.ids } }).then(count => { res.send({ count }) })
+ backendHelper.deleteClients(req.body.ids)
}
}
diff --git a/server/api/registrations.js b/server/api/registrations.js
index 928ee94..f6a8f87 100644
--- a/server/api/registrations.js
+++ b/server/api/registrations.js
@@ -5,6 +5,7 @@ var router = express.Router()
var noAuthRouter = express.Router()
var db = require(path.join(__appdir, 'lib', 'sequelize'))
const ExternalBackends = require(path.join(__appdir, 'lib', 'external-backends'))
+const backendHelper = require(path.join(__appdir, 'lib', 'external-backends', 'backendhelper'))
// GET requests.
@@ -115,7 +116,7 @@ noAuthRouter.post('/group', (req, res) => {
})
/*
- * Adds the client in the database and set parents if a parent was selected.
+ * Adds the client to the database and set parents if a parent was selected. Calls addClient for all external-backends.
*/
noAuthRouter.post('/add', (req, res) => {
const mac = req.body.mac
@@ -129,10 +130,27 @@ noAuthRouter.post('/add', (req, res) => {
var groupids = []
if (parentId) groupids = [parentId]
getNextHookScript(groupids, 0).then(resId => {
- db.client.create({ name: name, ip: ip, mac: mac, uuid: uuid, registrationState: resId }).then(client => {
+ db.client.create({ name: name, ip: ip, mac: mac, uuid: uuid, registrationState: resId }).then(newClient => {
if (parentId) {
- client.addGroup(parentId)
+ newClient.addGroup(parentId)
}
+
+ // Add the client to the backends.
+ const c = { network: { mac: mac, ip: ip } }
+ if (parentId) c.parentId = parentId
+ if (name) c.title = name
+ else c.title = 'Client_' + uuid
+ backendHelper.addClient(c).then(result => {
+ result.forEach(response => {
+ // If the object was created we need to make the objectid / external id mapping.
+ if (response.success && response.create) {
+ db.backend.findOne({ where: { id: response.backendId }, include: ['mappedClients'] }).then(backend => {
+ backend.addMappedClients(newClient, { through: { externalId: response.id, externalType: response.type } })
+ })
+ }
+ })
+ })
+
res.send('#!ipxe\r\nreboot')
})
})
@@ -141,6 +159,20 @@ noAuthRouter.post('/add', (req, res) => {
})
/*
+ * Adds additional information for the backends of the client in the firstregistration.
+ */
+noAuthRouter.post('/addInfo', (req, res) => {
+ const id = req.body.id
+ const systemModel = req.body.sysmodel
+ const systemManufacturer = req.body.sysmanu
+ const systemSerial = req.body.sysserial
+
+ // Add the client to the backends.
+ backendHelper.addClient({ id: id, system: { model: systemModel, manufacturer: systemManufacturer, serialnumber: systemSerial } })
+ res.send({ status: 'success' })
+})
+
+/*
* Open api method for setting the registration state of a given uuid.
*/
noAuthRouter.post('/:uuid/success', (req, res) => {