From 7a07412a7096f39f155c76cd1bb6cd47dc00a61a Mon Sep 17 00:00:00 2001 From: pedromiguelmiranda <32689555+pedromiguelmiranda@users.noreply.github.com> Date: Sat, 13 Oct 2018 16:12:12 +0100 Subject: [PATCH] Identify machine name on logging upon clock skew error (#188) --- lib/pairing.js | 11 +++++++++-- lib/routes.js | 6 ++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/pairing.js b/lib/pairing.js index 2eec688c..bc2d4ccc 100644 --- a/lib/pairing.js +++ b/lib/pairing.js @@ -71,10 +71,17 @@ function authorizeCaDownload (caToken) { } function isPaired (deviceId) { - const sql = 'select device_id from devices where device_id=$1 and paired=TRUE' + const sql = 'select device_id, name from devices where device_id=$1 and paired=TRUE' return db.oneOrNone(sql, [deviceId]) - .then(row => row && row.device_id === deviceId) + .then(row => { + const deviceName = row.name + const isDevicePaired = row && row.device_id === deviceId + return { + deviceName: deviceName, + isDevicePaired: isDevicePaired + } + }) } module.exports = {pair, unpair, authorizeCaDownload, isPaired} diff --git a/lib/routes.js b/lib/routes.js index 914b848b..10c7af87 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -299,7 +299,8 @@ function filterOldRequests (req, res, next) { const delta = Date.now() - Date.parse(deviceTime) if (delta > CLOCK_SKEW) { - logger.error('Clock skew with lamassu-machine too high [%ss], adjust lamassu-machine clock', (delta / 1000).toFixed(2)) + logger.error('Clock skew with lamassu-machine[%s] too high [%ss], adjust lamassu-machine clock', + req.deviceName, (delta / 1000).toFixed(2)) } if (delta > REQUEST_TTL) return res.status(408).json({error: 'stale'}) @@ -311,8 +312,9 @@ function authorize (req, res, next) { return pairing.isPaired(deviceId) .then(r => { - if (r) { + if (r.isDevicePaired) { req.deviceId = deviceId + req.deviceName = r.deviceName return next() }