From 07639fbbc1440d8224365a5c0b0ae697989cd0fb Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Fri, 15 Mar 2019 14:59:52 +0000 Subject: [server/registration] Add log to the first registration. --- server/.eslintignore | 25 ++++++++++++++++++++++ server/api/registration.js | 6 +++++- server/lib/external-backends/backendhelper.js | 4 +++- .../external-backends/backends/idoit-backend.js | 4 ++-- server/lib/external-backends/index.js | 12 +++++------ server/lib/log.js | 8 +++---- 6 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 server/.eslintignore (limited to 'server') diff --git a/server/.eslintignore b/server/.eslintignore new file mode 100644 index 0000000..66af4f4 --- /dev/null +++ b/server/.eslintignore @@ -0,0 +1,25 @@ +/bin/fullchain.pem +/bin/privkey.pem + +/config/* +!/config/*.template.json + +/ipxe/ipxe_* +/ipxe/log_* + +.DS_Store +node_modules/ +/public/ +/tftp/ +/ipxe/ipxe/ +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Editor directories and files +.idea +.vscode +*.suo +*.ntvs* +*.njsproj +*.sln \ No newline at end of file diff --git a/server/api/registration.js b/server/api/registration.js index 3eb36e0..63a3915 100644 --- a/server/api/registration.js +++ b/server/api/registration.js @@ -9,6 +9,7 @@ const backendHelper = require(path.join(__appdir, 'lib', 'external-backends', 'b const ipHelper = require(path.join(__appdir, 'lib', 'iphelper')) const config = require(path.join(__appdir, 'config', 'config')) const url = config.https.host + ':' + config.https.port +const log = require(path.join(__appdir, 'lib', 'log')) // GET requests. @@ -137,12 +138,15 @@ noAuthRouter.postAsync('/add', async (req, res) => { parentIds.forEach(pid => { newClient.addGroup(pid) }) // TODO: check if there are multiple groups which are mapped to a backend if so --> merge conflict } + log({ category: 'CLIENT_REGISTRATION', description: 'Client added successfully.', clientId: newClient.id }) // Add the client to the backends. var c = { id: newClient.id, title: name, uuid: uuid, network: { mac: mac, ip: ip } } if (parentIds.length > 0) c.parents = parentIds if (purpose) c.purpose = purpose - const result = await backendHelper.addClient(c) + + var result = await backendHelper.addClient(c) + if (feedback) res.send(result) else res.send(`#!ipxe\nchain https://` + url + `/api/configloader/\${uuid}`) }) diff --git a/server/lib/external-backends/backendhelper.js b/server/lib/external-backends/backendhelper.js index bb95844..be41ebc 100644 --- a/server/lib/external-backends/backendhelper.js +++ b/server/lib/external-backends/backendhelper.js @@ -1,7 +1,8 @@ /* global __appdir */ const path = require('path') const ExternalBackends = require(path.join(__appdir, 'lib', 'external-backends')) -var db = require(path.join(__appdir, 'lib', 'sequelize')) +const db = require(path.join(__appdir, 'lib', 'sequelize')) +const log = require(path.join(__appdir, 'lib', 'log')) module.exports = { addClient: async function (client) { @@ -41,6 +42,7 @@ module.exports = { const clientDb = await db.client.findOne({ where: { id: client.id } }) backend.addMappedClients(clientDb, { through: { externalId: addClient.id, externalType: addClient.type } }) } + if (addClient.error && addClient.error !== 'NOT_IMPLEMENTED_EXCEPTION') log({ category: 'BACKEND_ERROR', description: `[${addClient.backendId}] ${addClient.error}: ${addClient.message}`, clientId: client.id }) result.push(addClient) } return result diff --git a/server/lib/external-backends/backends/idoit-backend.js b/server/lib/external-backends/backends/idoit-backend.js index 9325ad5..1fe7b5f 100644 --- a/server/lib/external-backends/backends/idoit-backend.js +++ b/server/lib/external-backends/backends/idoit-backend.js @@ -199,12 +199,12 @@ class IdoitBackend extends ExternalBackends { // Send the create request. const body = this.getBody('cmdb.object.create', params, 'client_create') const requestCreate = await this.axiosRequest(c.url, [body], headers) - + if (requestCreate.error) return { error: requestCreate.errno, message: 'Connection was refused.' } // Purpose for Clients: // 1 = Production | 5 = PVS // 2 = Test | 7 = Pool PC // 3 = Quality Assurance | 8 = Mitarbeiter Arbeitsplatz - return { succes: true, id: requestCreate[0].result.id, type: params.type, message: requestCreate[0].result.message } + return { id: requestCreate[0].result.id, type: params.type, message: requestCreate[0].result.message } } /* diff --git a/server/lib/external-backends/index.js b/server/lib/external-backends/index.js index 755cef4..af7c2a1 100644 --- a/server/lib/external-backends/index.js +++ b/server/lib/external-backends/index.js @@ -110,7 +110,7 @@ class ExternalBackends { * return: { success: , status: '', error: '' } */ async checkConnection (backend) { - return { success: false, error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have a checkConnection method' } + 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. @@ -132,7 +132,7 @@ class ExternalBackends { * } */ async addClient (credentials, client) { - return { success: false, error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have an addClient method' } + return { error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have an addClient method' } } /* @@ -158,18 +158,18 @@ class ExternalBackends { * } */ async updateClient (credentials, client) { - return { success: false, error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have an updateClient method' } + return { error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have an updateClient method' } } async uploadFiles (credentials, externalId, files) { - return { success: false, error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have an uploadFiles method' } + return { error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have an uploadFiles method' } } async getFileList (credentials, externalId) { - return { success: false, error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have an getFileList method' } + return { error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have an getFileList method' } } async getFile (credentials, externalId, filename) { - return { success: false, error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have an getFile method' } + return { error: 'NOT_IMPLEMENTED_EXCEPTION', message: 'The provided backend does not have an getFile method' } } } diff --git a/server/lib/log.js b/server/lib/log.js index 22ce264..1f214c5 100644 --- a/server/lib/log.js +++ b/server/lib/log.js @@ -11,11 +11,11 @@ async function log ({ category, description, groupId, clientId, userId }) { clientId, userId }) - if (groupId) entry.groupSnapshot = await db.group.findOne({ where: { id: groupId }}) - if (clientId) entry.clientSnapshot = await db.client.findOne({ where: { id: clientId }}) - if (userId) entry.userSnapshot = await db.user.findOne({ where: { id: userId }}) + if (groupId) entry.groupSnapshot = await db.group.findOne({ where: { id: groupId } }) + if (clientId) entry.clientSnapshot = await db.client.findOne({ where: { id: clientId } }) + if (userId) entry.userSnapshot = await db.user.findOne({ where: { id: userId } }) await entry.save() return entry } -module.exports = log \ No newline at end of file +module.exports = log -- cgit v1.2.3-55-g7522