summaryrefslogtreecommitdiffstats
path: root/server/lib/external-backends/backends/infoblox-backend.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/external-backends/backends/infoblox-backend.js')
-rw-r--r--server/lib/external-backends/backends/infoblox-backend.js95
1 files changed, 95 insertions, 0 deletions
diff --git a/server/lib/external-backends/backends/infoblox-backend.js b/server/lib/external-backends/backends/infoblox-backend.js
new file mode 100644
index 0000000..f980b8b
--- /dev/null
+++ b/server/lib/external-backends/backends/infoblox-backend.js
@@ -0,0 +1,95 @@
+/* global __appdir */
+const path = require('path')
+const ExternalBackends = require(path.join(__appdir, 'lib', 'external-backends'))
+const Infoblox = require('infoblox')
+
+class InfobloxBackend extends ExternalBackends {
+ // ############################################################################
+ // ######################## needed functions #################################
+
+ /*
+ * Returns the credential structure / fields, defined in the backends.
+ */
+ getCredentials () {
+ return [
+ { type: 'text', id: 1, name: 'API url', icon: 'link' },
+ { type: 'text', id: 2, name: 'API version', icon: 'info' },
+ { type: 'text', id: 3, name: 'Username', icon: 'person_outline' },
+ { type: 'password', id: 4, name: 'Password', icon: 'vpn_key', show: false }
+ ]
+ }
+
+ /*
+ * Checks the connection of a given backend.
+ * infoblox: If we can login the connection to the server and also the login is successfull.
+ *
+ * return: { success: <boolean>, status: '<STATUS_CODE_IF_ERROR>', error: '<ERROR_MESSAGE>' }
+ */
+ async checkConnection (credentials) {
+ var c = this.mapCredentials(credentials)
+
+ var ipam = new Infoblox({
+ ip: c.url,
+ apiVersion: c.version
+ })
+ return ipam.login(c.username, c.password).then(response => {
+ if (response) {
+ console.log('wefkin')
+ return { success: true }
+ } else {
+ return { success: false, error: 'TEST' }
+ }
+ })
+ }
+ // ############################################################################
+ // ####################### helper/optional functions #########################
+ // Helper function, to map the array of credential objects into a single js object.
+ mapCredentials (credentials) {
+ const c = JSON.parse(credentials)
+ var mapped = {
+ url: c.find(x => x.id === 1).value,
+ version: c.find(x => x.id === 2).value,
+ username: c.find(x => x.id === 3).value,
+ password: c.find(x => x.id === 4).value
+ }
+
+ return mapped
+ }
+
+ // #### TEST FUNCTIONS ###
+ test (credentials) {
+ var c = this.mapCredentials(credentials)
+
+ var ipam = new Infoblox({
+ ip: c.url,
+ apiVersion: c.version
+ })
+
+ var promise = new Promise((resolve, reject) => {
+ ipam.login(c.username, c.password).then(response => {
+ if (response) {
+ // ipam.create('record:host?_return_fields%2B=na13me,ipv4addrs&_return_as_object=1', {'name': 'wapiTest.lp.privat', 'ipv4addrs': [{'ipv4addr': '10.21.9.141', 'mac': 'aa:bb:cc:11:22:21'}]}).then(function (response) {
+ // return response
+ // })
+ // Get the network from the ip.
+ // ipam.getHost('10.21.9.78').then(function (response) {
+ ipam.getNetworkFromIp('10.21.9.78').then(response => {
+ // ipam.getIpsFromSubnet('10.21.9.0/24').then(function (response) {
+ // ipam.list('record:host').then(function (response) {
+ // ipam.getDomain().then(function (response) {
+ response = JSON.parse(response)
+ // ipam.getNext(response[0]._ref, 1).then(r => {
+ resolve(response)
+ // })
+ // res.send(JSON.parse(response))
+ })
+ } else {
+ return { success: false, error: 'TEST' }
+ }
+ })
+ })
+ return promise
+ }
+}
+
+module.exports = InfobloxBackend