summaryrefslogtreecommitdiffstats
path: root/server/lib/external-backends
diff options
context:
space:
mode:
authorJannik Schönartz2018-07-26 15:09:54 +0200
committerJannik Schönartz2018-07-26 15:09:54 +0200
commitdfbc9e183af3fbd28dc72f386b97f8df7b3de7c1 (patch)
tree95b50a0dec8f5a15bd3f6e124c6b14133590597a /server/lib/external-backends
parent[server/ipxe-loader] Fixed the script for booting a pxe-linux. (diff)
downloadbas-dfbc9e183af3fbd28dc72f386b97f8df7b3de7c1.tar.gz
bas-dfbc9e183af3fbd28dc72f386b97f8df7b3de7c1.tar.xz
bas-dfbc9e183af3fbd28dc72f386b97f8df7b3de7c1.zip
[server/backends] Added iDoII Backend. Implemented a checkConnection method for each individual backend. Switches in backends can now have recursive elements. They are only shown if the switch is set to true.
Diffstat (limited to 'server/lib/external-backends')
-rw-r--r--server/lib/external-backends/backends/another-backend.js4
-rw-r--r--server/lib/external-backends/backends/dummy-backend.js4
-rw-r--r--server/lib/external-backends/backends/idoit-backend.js27
-rw-r--r--server/lib/external-backends/backends/template-backend.js14
-rw-r--r--server/lib/external-backends/external-backends.js8
5 files changed, 56 insertions, 1 deletions
diff --git a/server/lib/external-backends/backends/another-backend.js b/server/lib/external-backends/backends/another-backend.js
index eb329ae..90b8f8b 100644
--- a/server/lib/external-backends/backends/another-backend.js
+++ b/server/lib/external-backends/backends/another-backend.js
@@ -4,6 +4,10 @@ class AnotherBackend extends ExternalBackends {
getCredentials () {
return [{ type: 'text', id: 1, name: 'text 1' }, { type: 'text', id: 2, name: 'text 2' }, { type: 'password', id: 3, name: 'password 1', show: false }, { type: 'password', id: 4, name: 'password 2', show: true }, { type: 'password', id: 5, name: 'password 3', show: false }]
}
+
+ async checkConnection () {
+ return { success: true }
+ }
}
module.exports = AnotherBackend
diff --git a/server/lib/external-backends/backends/dummy-backend.js b/server/lib/external-backends/backends/dummy-backend.js
index 6052953..99d27c1 100644
--- a/server/lib/external-backends/backends/dummy-backend.js
+++ b/server/lib/external-backends/backends/dummy-backend.js
@@ -4,6 +4,10 @@ class DummyBackend extends ExternalBackends {
getCredentials () {
return [{ type: 'switch', id: 1, name: 'switch 1', value: false }, { type: 'switch', id: 2, name: 'switch 2', value: false }, { type: 'switch', id: 3, name: 'switch 3', value: true }, { type: 'select', id: 4, name: 'selection 1', items: ['wasd', 'asdf', 'qwertz'] }, { type: 'select', id: 5, name: 'selection 2', items: ['1', '2', '3'] }]
}
+
+ async checkConnection () {
+ return { success: false, msg: 'This is a test where success was intentionally set to false!' }
+ }
}
module.exports = DummyBackend
diff --git a/server/lib/external-backends/backends/idoit-backend.js b/server/lib/external-backends/backends/idoit-backend.js
new file mode 100644
index 0000000..2520b07
--- /dev/null
+++ b/server/lib/external-backends/backends/idoit-backend.js
@@ -0,0 +1,27 @@
+var ExternalBackends = require('../external-backends.js')
+
+class IdoitBackend extends ExternalBackends {
+ getCredentials () {
+ // I do it only needs the API-key.
+ return [
+ { type: 'text', id: 1, name: 'API url', icon: 'link' },
+ { type: 'password', id: 2, name: 'API token', icon: 'vpn_key', show: false },
+ { type: 'switch',
+ id: 3,
+ name: 'Login',
+ icon: 'lock_open',
+ elements: [
+ { type: 'text', id: 4, name: 'username', icon: 'person_outline' },
+ { type: 'password', id: 5, name: 'password', icon: 'lock', show: false }
+ ]
+ }
+ ]
+ }
+
+ async checkConnection () {
+ // Make a simple login and check if the connection works.
+ return { success: false, msg: 'TODO: IMPLEMENT' }
+ }
+}
+
+module.exports = IdoitBackend
diff --git a/server/lib/external-backends/backends/template-backend.js b/server/lib/external-backends/backends/template-backend.js
index 19f1d76..ceab46a 100644
--- a/server/lib/external-backends/backends/template-backend.js
+++ b/server/lib/external-backends/backends/template-backend.js
@@ -4,6 +4,20 @@ class TemplateBackend extends ExternalBackends {
getCredentials () {
return [{ type: 'text', id: 1, name: 'text test', icon: 'bug_report' }, { type: 'password', id: 2, name: 'password test', show: true }, { type: 'password', id: 3, name: 'password test nr2', show: false }, { type: 'switch', id: 4, name: 'bool test', value: false }, { type: 'select', id: 5, name: 'selection test', items: ['wasd', 'asdf', 'qwertz'] }]
}
+
+ async checkConnection () {
+ var result = await x()
+ console.log(result)
+ return result
+ }
+}
+
+function x () {
+ return new Promise(resolve => {
+ setTimeout(() => {
+ resolve({ success: true })
+ }, 5000)
+ })
}
module.exports = TemplateBackend
diff --git a/server/lib/external-backends/external-backends.js b/server/lib/external-backends/external-backends.js
index 0bf891e..a1264a0 100644
--- a/server/lib/external-backends/external-backends.js
+++ b/server/lib/external-backends/external-backends.js
@@ -9,7 +9,8 @@ class ExternalBackends {
}
getCredentials () {
- return 'If this method gets called the backend class has NOT IMPLEMENTED the getCredentials method!'
+ console.log('If this method gets called the backend class has NOT IMPLEMENTED the getCredentials method!')
+ return null
}
getInstance (type) {
@@ -25,6 +26,11 @@ class ExternalBackends {
const backend = new (require(path.join(__appdir, 'lib', 'external-backends', 'backends', bType)))()
return backend
}
+
+ async checkConnection () {
+ console.log('If this method gets called the backend class has NOT IMPLEMENTED the checkConnection method!')
+ return null
+ }
}
module.exports = ExternalBackends