summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJannik Schönartz2018-08-02 23:17:50 +0200
committerJannik Schönartz2018-08-02 23:17:50 +0200
commitcee3b5539762d12ad8b22e90404b76219886af44 (patch)
tree5cf0633c8f7016e39f5539b0d7fe3de0302c1907
parent[groups] bugfix + add doubleclick to enter group/client + small design change (diff)
downloadbas-cee3b5539762d12ad8b22e90404b76219886af44.tar.gz
bas-cee3b5539762d12ad8b22e90404b76219886af44.tar.xz
bas-cee3b5539762d12ad8b22e90404b76219886af44.zip
[server/external-backends] Added sync settings for the backends. Method for getting the backend oject types and the client / group mapping saved in the db.
-rw-r--r--server/api/backends.js34
-rw-r--r--server/lib/external-backends/backends/idoit-backend.js32
-rw-r--r--server/lib/external-backends/external-backends.js5
-rw-r--r--server/migrations/20180715193710-create-backend.js17
-rw-r--r--server/models/backend.js19
5 files changed, 102 insertions, 5 deletions
diff --git a/server/api/backends.js b/server/api/backends.js
index 3d7c36e..2b82cab 100644
--- a/server/api/backends.js
+++ b/server/api/backends.js
@@ -58,6 +58,28 @@ module.exports.get = {
res.status(200).send(result)
})
})
+ },
+
+ getObjectTypes: function (req, res) {
+ const id = req.query.id
+ db.backend.findOne({ where: { id: id } }).then(backend => {
+ const ba = new ExternalBackends()
+ const instance = ba.getInstance(backend.type)
+ console.log(backend.type)
+ instance.getObjectTypes(backend.credentials).then(result => {
+ res.status(200).send(result)
+ })
+ })
+ },
+
+ getObjectTypesById: function (req, res) {
+ const id = req.query.id
+ var types = {}
+ db.backend.findOne({ where: { id: id } }).then(backend => {
+ types.groups = JSON.parse(backend.groups)
+ types.clients = JSON.parse(backend.clients)
+ res.status(200).send(types)
+ })
}
}
@@ -105,5 +127,17 @@ module.exports.post = {
res.status(200).send({ success: connection.success, msg: connection.msg })
})
})
+ },
+
+ // Saves the group / clients assigned object types in the database.
+ saveObjectTypes: function (req, res) {
+ const id = req.body.id
+ const groups = JSON.stringify(req.body.groups)
+ const clients = JSON.stringify(req.body.clients)
+ db.backend.findOne({ where: { id: id } }).then(backend => {
+ db.backend.update({ groups: groups, clients: clients }, { where: { id: id } }).then(() => {
+ res.status(200).send()
+ })
+ })
}
}
diff --git a/server/lib/external-backends/backends/idoit-backend.js b/server/lib/external-backends/backends/idoit-backend.js
index cdd4dde..de41481 100644
--- a/server/lib/external-backends/backends/idoit-backend.js
+++ b/server/lib/external-backends/backends/idoit-backend.js
@@ -26,6 +26,35 @@ class IdoitBackend extends ExternalBackends {
return this.getSession(c)
}
+ // Return the list of object types created in iDoIT.
+ async getObjectTypes (credentials) {
+ var c = this.mapCredentials(credentials)
+ var login = await this.getSession(c)
+ var sid = login.data.result['session-id']
+
+ // Headers
+ var headers = {
+ 'X-RPC-Auth-Session': sid
+ }
+
+ // Params
+ var params = {
+ 'apikey': c.apikey,
+ 'language': 'en'
+ }
+
+ var result = {}
+ result.types = await this.axiosRequest(c.url, 'cmdb.object_types', params, headers)
+ result.types = result.types.data.result
+
+ var types = []
+ result.types.forEach(type => {
+ types.push({ id: type.id, title: type.title })
+ })
+
+ return types
+ }
+
// Optional functions e.g. helperfunctions or testing stuff.
// Helper function, to map the array of credential objects into a single js object.
@@ -68,9 +97,6 @@ class IdoitBackend extends ExternalBackends {
result.object = result.object.data.result
result.childs = result.childs.data.result
- console.log(result)
- // Make an request to read the object
- //return this.axiosRequest(c.url, 'cmdb.location_tree', params, headers)
return result
}
diff --git a/server/lib/external-backends/external-backends.js b/server/lib/external-backends/external-backends.js
index 7d306b3..20f8ce6 100644
--- a/server/lib/external-backends/external-backends.js
+++ b/server/lib/external-backends/external-backends.js
@@ -31,6 +31,11 @@ class ExternalBackends {
console.log('If this method gets called the backend class has NOT IMPLEMENTED the checkConnection method!')
return null
}
+
+ // Return an empty array [] if the backends doesn't have such a function.
+ async getObjectTypes (credentials) {
+ return []
+ }
}
module.exports = ExternalBackends
diff --git a/server/migrations/20180715193710-create-backend.js b/server/migrations/20180715193710-create-backend.js
index e89362e..98f5476 100644
--- a/server/migrations/20180715193710-create-backend.js
+++ b/server/migrations/20180715193710-create-backend.js
@@ -15,7 +15,22 @@ module.exports = {
type: Sequelize.STRING
},
credentials: {
- type: Sequelize.STRING(2048)
+ allowNull: false,
+ type: Sequelize.STRING(2048),
+ defaultValue: '[]'
+ },
+ groups: {
+ allowNull: false,
+ type: Sequelize.STRING(4096),
+ defaultValue: '[]'
+ },
+ clients: {
+ allowNull: false,
+ type: Sequelize.STRING(4096),
+ defaultValue: '[]'
+ },
+ sync: {
+ type: Sequelize.STRING(1024)
}
})
},
diff --git a/server/models/backend.js b/server/models/backend.js
index 4ed5fce..62b936a 100644
--- a/server/models/backend.js
+++ b/server/models/backend.js
@@ -9,7 +9,24 @@ module.exports = (sequelize, DataTypes) => {
},
name: DataTypes.STRING,
type: DataTypes.STRING,
- credentials: DataTypes.STRING(2048)
+ credentials: {
+ allowNull: false,
+ type: DataTypes.STRING(2048),
+ defaultValue: '[]'
+ },
+ groups: {
+ allowNull: false,
+ type: DataTypes.STRING(4096),
+ defaultValue: '[]'
+ },
+ clients: {
+ allowNull: false,
+ type: DataTypes.STRING(4096),
+ defaultValue: '[]'
+ },
+ sync: {
+ type: DataTypes.STRING(1024)
+ }
}, {
timestamps: false
})