From f0808189575e7024d0ad100dfb71b18810ec79de Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Sun, 14 Apr 2019 02:46:53 +0000 Subject: [server/external-backends] Add delete method for the infoblox backend & add infoblox client mappings method --- server/api/backends.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'server/api/backends.js') diff --git a/server/api/backends.js b/server/api/backends.js index e92999a..f3de01f 100644 --- a/server/api/backends.js +++ b/server/api/backends.js @@ -301,6 +301,27 @@ router.get('/:id/import', (req, res) => { }) }) +/* + * Adds the client mapping from the backend to the client with the same mac address. + */ +router.getAsync('/:id/mapping', async (req, res) => { + const id = req.params.id + const backend = await db.backend.findOne({ where: { id: id } }) + + if (backend) { + const b = new ExternalBackends() + const instance = b.getInstance(backend.type) + const objects = await instance.getObjects(backend.credentials) + + for (let index in objects) { + const object = objects[index] + const client = await db.client.findOne({ where: { mac: object.mac } }) + await backend.addMappedClients(client, { through: { externalId: object.id } }) + } + return res.status(200).send() + } else return res.status(500).send() +}) + // No auth router for now but those client based methods should better be in the clients api. // TODO: Move to clients? // TODO: receive files should be authenticated! -- cgit v1.2.3-55-g7522