summaryrefslogtreecommitdiffstats
path: root/server/lib/external-backends/external-backends.js
blob: 20f8ce630b9289487ee7cbef08a400c7ea89091b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* global __appdir */
const fs = require('fs')
const path = require('path')

class ExternalBackends {
  getBackends () {
    var files = fs.readdirSync(path.join(__appdir, 'lib', 'external-backends', 'backends'))
    return files
  }

  getCredentials () {
    console.log('If this method gets called the backend class has NOT IMPLEMENTED the getCredentials method!')
    return null
  }

  getInstance (type) {
    const bList = this.getBackends()
    const bType = type + '-backend.js'

    // Check if it's a valid backend type.
    if (bList.indexOf(bType) === -1) {
      console.log(bType + ' is not a valid backend type.')
      return null
    }

    const backend = new (require(path.join(__appdir, 'lib', 'external-backends', 'backends', bType)))()
    return backend
  }

  async checkConnection (backend) {
    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