summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJannik Schönartz2022-02-01 18:46:17 +0100
committerJannik Schönartz2022-02-01 18:46:17 +0100
commitffa250b2dad3fdc142cfb9ee47daa4ccd60d6276 (patch)
tree2b603d1c25961dc185589a502647791b7e9acaf0
parent[server/registration] Accepting bas ids as location for clients instead of on... (diff)
downloadbas-ffa250b2dad3fdc142cfb9ee47daa4ccd60d6276.tar.gz
bas-ffa250b2dad3fdc142cfb9ee47daa4ccd60d6276.tar.xz
bas-ffa250b2dad3fdc142cfb9ee47daa4ccd60d6276.zip
[server/backends] Add method for importing only a specific backend type
-rw-r--r--server/api/backends.js41
-rw-r--r--server/lib/external-backends/backends/idoit-backend.js4
2 files changed, 43 insertions, 2 deletions
diff --git a/server/api/backends.js b/server/api/backends.js
index 63b4cb9..deee32f 100644
--- a/server/api/backends.js
+++ b/server/api/backends.js
@@ -329,6 +329,47 @@ router.get('/:id/import', (req, res) => {
})
})
+// Import objects of a specific type only e.g. Racks for the idoit backend
+router.getAsync('/:id/import/:type', async (req, res) => {
+ const id = req.params.id
+ const type = req.params.type
+
+ // Get the backend where the objects are importet from.
+ const backend = await db.backend.findOne({ where: { id: id } })
+
+ if (backend) {
+ const ba = new ExternalBackends()
+ const instance = ba.getInstance(backend.type)
+ const groups = JSON.parse(backend.groupTypes).filter(typ => typ.title === type).map(x => parseInt(x.id))
+ const clients = JSON.parse(backend.clientTypes).filter(typ => typ.title === type).map(x => parseInt(x.id))
+
+ // Get a list with all objects in the backend.
+ const objects = await instance.getObjects(backend.credentials)
+
+ // Filter those objects in groups / clients
+ var groupObjects = []
+ var clientObjects = []
+ objects.filter(obj => {
+ if (groups.find(x => x === obj.type)) groupObjects.push({ id: obj.id, name: obj.title, type: obj.type, typeName: obj.type_title, sysid: obj.sysid })
+ else if (clients.find(y => y === obj.type)) clientObjects.push({ id: obj.id, name: obj.title, type: obj.type, typeName: obj.type_title, sysid: obj.sysid })
+ })
+
+ // Add all groups in the database.
+ for (const group of groupObjects) {
+ const g = await db.group.create({ name: group.name, description: group.typeName })
+ await backend.addMappedGroups(g, { through: { externalId: group.id, externalType: group.type } })
+ }
+
+ // Add all clients in the databse.
+ for (const client of clientObjects) {
+ const c = await db.client.create({ name: client.name, description: client.typeName })
+ await backend.addMappedClients(c, { through: { externalId: client.id, externalType: client.type } })
+ }
+
+ return res.status(200).send({ status: 'SUCCESS' })
+ } else res.status(500).send({ error: 'INVALID_BACKEND_ID', message: 'The provided backend id is invalid.' })
+})
+
/*
* Adds the client mapping from the backend to the client with the same mac address.
*/
diff --git a/server/lib/external-backends/backends/idoit-backend.js b/server/lib/external-backends/backends/idoit-backend.js
index 7f99138..864959d 100644
--- a/server/lib/external-backends/backends/idoit-backend.js
+++ b/server/lib/external-backends/backends/idoit-backend.js
@@ -64,7 +64,7 @@ class IdoitBackend extends ExternalBackends {
}
getSyncTypes () {
- return ['None', 'Two-Way', 'Upload Only', 'Upload Then Delete', 'Upload Mirror', 'Download Only', 'Download Then Delete', 'Download Mirror']
+ return ['None'] // ['None', 'Two-Way', 'Upload Only', 'Upload Then Delete', 'Upload Mirror', 'Download Only', 'Download Then Delete', 'Download Mirror']
}
/*
@@ -921,7 +921,7 @@ class IdoitBackend extends ExternalBackends {
const rackObjects = rackRequest[0]
const rack = rackRequest[1]
- if (!rackObjects.result || !rack.result) return undefined
+ if (!rackObjects.result || rackObjects.result.length === 0 || !rack.result || rack.result.length === 0) return undefined
// Check if the parent object is a rack else return this function (Type C__OBJTYPE__ENCLOSURE)
if (rack.result[0].type.const !== 'C__OBJTYPE__ENCLOSURE' || rack.result[0].type.title !== 'Rack') return undefined