summaryrefslogtreecommitdiffstats
path: root/server/lib/external-backends/index.js
blob: f05ba69b6b2eb6f6c0bd8de386e64b12fe1f6b5f (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/* global __appdir */
const fs = require('fs')
const path = require('path')

class ExternalBackends {
  /*
   * Returns a list of all backends which have a .js file.
   */
  getBackends () {
    var files = fs.readdirSync(path.join(__appdir, 'lib', 'external-backends', 'backends'))
    return files
  }

  /*
   * Returns the credential structure / fields, defined in the backends.
   *
   * If type === switch there can be child elements in the elements attribute.
   * Those elements are only shown, if the switch is set to true.
   * [{ type: 'text', id: 1, name: '<NAME>', icon: '<ICON_NAME>' },
   *  { type: 'password', id: 2, name: '<NAME>', icon: '<ICON_NAME>' },
   *  { type: 'switch', id: 3, name: '<NAME>', icon: '<ICON_NAME>' , elements: [ { type: ... } ] },
   *  { type: 'select', id: 4, name: '<NAME>', icon: '<ICON_NAME>' }, ...]
   */
  getCredentials () {
    return { error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have a getCredentials method' }
  }

  /*
   * type: <BACKEND_TYPE>
   *
   * Returns the instance of a given backend type.
   */
  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
  }

  /*
   * Returns an empty array [] if the backends doesn't have the function implemented.
   *
   * return: ['<SYNC_TYPE>', ...]
   */
  getSyncTypes () {
    return []
  }

  /*
   * Get the client from the backend and returns their informationen.
   * credentials: <BACKEND_CREDENTIALS>
   * client: Information about the client (ip, mac, uuid)
   *
   * return:
   */
  async getClient (credentials, client) {
    return { error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have a getClient method' }
  }

  /*
   * credendtials: <BACKEND_CREDENTIALS>
   *
   * Returns a list of all objects in the backend.
   */
  async getObjects (credentials) {
    return { error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have a getObjects method' }
  }

  /*
   * credendtials: <BACKEND_CREDENTIALS>
   * oid: <OBJECT_ID>
   *
   * Call the API of the backend and returns the information to the object including a list of childs.
   */
  async getObject (credentials, oid) {
    return { error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have a getObject method' }
  }

  /*
   * credendtials: <BACKEND_CREDENTIALS>
   * objectIds: [<OBJECT_ID>, <OBJECT_ID>, ...]
   *
   * Deletes the objecs from the backend.
   *
   * if errors occour, they should be returned in the form:
   * [
   *   { error: '', message: '', id: <EXTERNAL_OBJECT_ID> },
   *   ...
   * ]
   */
  async deleteObjects (credentials, objectIds) {
    return { error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have a deleteObject method' }
  }

  /*
   * credentials: <BACKEND_CREDENTIALS>
   * objects: [{ eid: <EXTERNAL_ID>, gid: <GROUP_ID> }, ...]
   * EXTERNAL_ID is the id of the objects in the external backend requestet.
   *
   * return: [{ gid: <GROUP_ID>, childs: [{ id: <EXTERNAL_ID>, }, ...]}, ...]
   */
  async getDataTree (credendtials, objects) {
    return { error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have a getDataTree method' }
  }

  /*
   * Checks the connection of a given backend.
   *
   * return: { success: <boolean>, status: '<STATUS_CODE_IF_ERROR>', error: '<ERROR_MESSAGE>' }
   */
  async checkConnection (backend) {
    return { error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have a checkConnection method' }
  }

  /* Returns an empty array [] if the backends doesn't have such a function.
   *
   * return: [{id: <id>, title: <title>}, ...]
   */
  async getObjectTypes (credentials) {
    return []
  }

  /*
   * Adds the client to the backend.
   *
   * credentials: <BACKEND_CREDENTIALS>
   * The client parameters are all optional. If the client has an id the object is not created but the categories of the object.
   * client: {
   *            id: <CLIENT_ID>, title: <CLIENT_TITLE>, parentId: <PARENT_ID>, uuid: <CLIENT_UUID>,
   *            network: { mac: <MAC_ADDRESS>, ip: <IP_ADDRESS> },
   *            location: { assembly: <Horizontal/Vertical>, insertion: <Back/Front/Front and Back>, position: <RU 1 - 46> },
   *            system: { model: <SYSTEM_MODEL>, manufacturer: <SYSTEM_MANUFACTURER>,  serialnumber: <SYSTEM_SERIALNUMBER> },
   *            formfactor: { formfactor: <e.g. 19">, rackunits: <integer> }
   *         }
   */
  async addClient (credentials, client) {
    return { error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have an addClient method' }
  }

  /*
   * Updates the client in the backend.
   *
   * credentials: <BACKEND_CREDENTIALS>
   * The client parameters are all optional.
   * client: {
   *            id: <CLIENT_ID>, title: <CLIENT_TITLE>, parentId: <PARENT_ID>, uuid: <CLIENT_UUID>, type: <CLIENT/SERVER>
   *            system: { model: <SYSTEM_MODEL>, manufacturer: <SYSTEM_MANUFACTURER>,  serialnumber: <SYSTEM_SERIALNUMBER> },
   *            cpu: { model: <CPU_MODEL>, manufacturer: <CPU_MANUFACTURER>, type: <CPU_TYPE>, frequency: <CPU_FREQUENCY>, cores: <CPU_CORES> },
   *            ram: [{ model: <RAM_MODEL>, manufacturer: <RAM_MANUFACTURER>, type: <RAM_TYPE>,  capacity: <RAM_CAPACITY>, unit: <RAM_UNIT> }, ...],
   *            storage: {},
   *            network: { mac: <MAC_ADDRESS>, ip: <IP_ADDRESS> }
   *         }
   */
  async updateClient (credentials, client) {
    return { error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have an updateClient method' }
  }

  async uploadFiles (credentials, externalId, files) {
    return { error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have an uploadFiles method' }
  }

  async getFileList (credentials, externalId) {
    return { error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have an getFileList method' }
  }
  async getFile (credentials, externalId, filename) {
    return { error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have an getFile method' }
  }
  async checkDomain (credentials) {
    return { error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have a checkDomain method' }
  }
  async checkIp (credentials, ipv4) {
    return { error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have a checkIp method' }
  }
  async setIp (credentials, ipv4, mac) {
    return { error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have a setIp method' }
  }
  /*
   * Only one dhcp backend should be configures or it causes problems in the registration.
   */
  isDhcp () {
    return false
  }
}

module.exports = ExternalBackends