summaryrefslogtreecommitdiffstats
path: root/server/lib/external-backends
diff options
context:
space:
mode:
authorJannik Schönartz2018-09-17 17:39:01 +0200
committerJannik Schönartz2018-09-17 17:39:01 +0200
commitcfa4dabd5e2aba66c6a8c0dfc3f43404fdbad3ec (patch)
treedfff7919e7674b5941e28a5bb31f4ad553e7f69e /server/lib/external-backends
parent[registration] Add parent tree view in the manual registration (diff)
downloadbas-cfa4dabd5e2aba66c6a8c0dfc3f43404fdbad3ec.tar.gz
bas-cfa4dabd5e2aba66c6a8c0dfc3f43404fdbad3ec.tar.xz
bas-cfa4dabd5e2aba66c6a8c0dfc3f43404fdbad3ec.zip
[external-backends/idoit] Rework getDataTree from promises to async / await
Diffstat (limited to 'server/lib/external-backends')
-rw-r--r--server/lib/external-backends/backends/idoit-backend.js64
-rw-r--r--server/lib/external-backends/index.js2
2 files changed, 36 insertions, 30 deletions
diff --git a/server/lib/external-backends/backends/idoit-backend.js b/server/lib/external-backends/backends/idoit-backend.js
index 7db2bf2..a48c740 100644
--- a/server/lib/external-backends/backends/idoit-backend.js
+++ b/server/lib/external-backends/backends/idoit-backend.js
@@ -185,7 +185,7 @@ class IdoitBackend extends ExternalBackends {
}
// Function to use the same session for multiple requests
- getDataTree (credentials, array) {
+ async getDataTree (credentials, array) {
var c = this.mapCredentials(credentials)
// LOGIN
@@ -209,36 +209,42 @@ class IdoitBackend extends ExternalBackends {
}
var config = {
- timeout: 90000,
+ timeout: 180000,
headers: headers
}
+
// Make a login request and see if we are authenticated.
- return axios.post(c.url, body, config).then(log => {
- var sid = log.data.result['session-id']
- // Headers
- config.headers = { 'X-RPC-Auth-Session': sid, 'Content-Type': 'application/json' }
- body.method = 'cmdb.location_tree'
- var promises = []
-
- array.forEach(element => {
- const bod = {
- 'version': '2.0',
- 'method': 'cmdb.location_tree',
- 'params': {
- 'id': element.eid,
- 'apikey': c.apikey,
- 'language': 'en'
- },
- 'id': 1
- }
- promises.push(axios.post(c.url, bod, config).then(result => {
- return { gid: element.gid, childs: result.data.result }
- }))
- })
- return Promise.all(promises).then(ret => {
- return ret
- })
- })
+ var log = await axios.post(c.url, body, config)
+ log = log.data.result
+ var sid = log['session-id']
+
+ // Headers
+ config.headers = { 'X-RPC-Auth-Session': sid, 'Content-Type': 'application/json' }
+ body.method = 'cmdb.location_tree'
+
+ // Go through the objects and get all the childs.
+ var promises = []
+ var e
+ for (e in array) {
+ var element = array[e]
+ const bod = {
+ 'version': '2.0',
+ 'method': 'cmdb.location_tree',
+ 'params': {
+ 'id': element.eid,
+ 'apikey': c.apikey,
+ 'language': 'en'
+ },
+ 'id': 1
+ }
+
+ var tmp = await axios.post(c.url, bod, config)
+ promises.push({ gid: element.gid, childs: tmp.data.result })
+
+ // Add a delay, so that idoit can handle it.
+ // await new Promise(resolve => { setTimeout(() => { resolve() }, 500) })
+ }
+ return promises
}
// ############################################################################
@@ -291,7 +297,7 @@ class IdoitBackend extends ExternalBackends {
}
var config = {
- timeout: 90000,
+ timeout: 180000,
headers: headers
}
config.headers['Content-Type'] = 'application/json'
diff --git a/server/lib/external-backends/index.js b/server/lib/external-backends/index.js
index 40e462d..9f99153 100644
--- a/server/lib/external-backends/index.js
+++ b/server/lib/external-backends/index.js
@@ -90,7 +90,7 @@ class ExternalBackends {
*
* return: [{ gid: <GROUP_ID>, childs: [{ id: <EXTERNAL_ID>, }, ...]}, ...]
*/
- getDataTree (credendtials, objects) {
+ async getDataTree (credendtials, objects) {
return { status: 'NOT_IMPLEMENTED_EXCEPTION', error: 'The provided backend does not have a getDataTree method' }
}