From c8c104ea0cb0e7b7091cd889bd5c42b29abaa131 Mon Sep 17 00:00:00 2001 From: Alvaro Vega Date: Mon, 26 Feb 2024 10:22:06 +0100 Subject: [PATCH] fix access to logger --- lib/iotagent-manager.js | 9 ++++++++- lib/model/dbConn.js | 2 +- lib/services/configurationData.js | 14 +++++++------- lib/services/configurations.js | 1 - lib/services/protocolData.js | 2 +- lib/utils/constants.js | 6 +++++- test/unit/configuration-retrieval-test.js | 6 +++--- 7 files changed, 25 insertions(+), 15 deletions(-) diff --git a/lib/iotagent-manager.js b/lib/iotagent-manager.js index 853920b..fec1dfe 100644 --- a/lib/iotagent-manager.js +++ b/lib/iotagent-manager.js @@ -139,7 +139,14 @@ function startServer(newConfig, callback) { function start(newConfig, callback) { config.setConfig(newConfig); - async.series([apply(startServer, newConfig), apply(dbConn.configureDb, logger)], callback); + async.series( + [ + apply(startServer, newConfig), + //dbConn.configureDb], + apply(dbConn.configureDb, logger) + ], + callback + ); } /** diff --git a/lib/model/dbConn.js b/lib/model/dbConn.js index 9ee7b40..84713cf 100644 --- a/lib/model/dbConn.js +++ b/lib/model/dbConn.js @@ -29,7 +29,7 @@ const mongoose = require('mongoose'); const config = require('../utils/commonConfig'); const constants = require('../utils/constants'); -//const logger = require('logops'); +const logger = require('logops'); const async = require('async'); const errors = require('../errors'); let defaultDb; diff --git a/lib/services/configurationData.js b/lib/services/configurationData.js index 1a95793..0b899b0 100644 --- a/lib/services/configurationData.js +++ b/lib/services/configurationData.js @@ -26,7 +26,7 @@ const Configuration = require('../model/Configuration'); const iotagentLib = require('iotagent-node-lib'); const errors = require('../errors'); -//const logger = require('logops'); +const logger = require('logops'); const async = require('async'); // const context = { // op: 'IoTAManager.ConfigurationDB' @@ -44,7 +44,7 @@ const provisioningAPITranslation = { payloadType: 'payloadType' }; -function createGetWithFields(logger, fields) { +function createGetWithFields(fields) { return function () { const queryObj = {}; let i = 0; @@ -98,7 +98,7 @@ function createGetWithFields(logger, fields) { }; } -function save(logger, protocol, description, iotagent, resource, configuration, oldConfiguration, callback) { +function save(theLogger, protocol, description, iotagent, resource, configuration, oldConfiguration, callback) { /* eslint-disable-next-line new-cap */ const configurationObj = oldConfiguration || new Configuration.model(); const attributeList = [ @@ -125,7 +125,7 @@ function save(logger, protocol, description, iotagent, resource, configuration, 'payloadType' ]; - logger.debug('Saving Configuration [%s][%s][%s]', protocol, iotagent, resource); + theLogger.debug('Saving Configuration [%s][%s][%s]', protocol, iotagent, resource); configurationObj.protocol = protocol; configurationObj.description = description; @@ -142,18 +142,18 @@ function save(logger, protocol, description, iotagent, resource, configuration, configurationObj[provisioningAPITranslation[attributeList[i]] || attributeList[i]] = description; } } - logger.debug('Saving Configuration %j translated to %j ', configuration, configurationObj); + theLogger.debug('Saving Configuration %j translated to %j ', configuration, configurationObj); configurationObj.save(callback); } exports.get = iotagentLib.alarms.intercept( iotagentLib.constants.MONGO_ALARM, - createGetWithFields(['logger', 'apikey', 'resource', 'protocol', 'type']) + createGetWithFields(['apikey', 'resource', 'protocol', 'type']) ); exports.save = iotagentLib.alarms.intercept(iotagentLib.constants.MONGO_ALARM, save); exports.list = iotagentLib.alarms.intercept( iotagentLib.constants.MONGO_ALARM, - createGetWithFields(['logger', 'service', 'subservice', 'protocol', 'apikey', 'type', 'limit', 'offset']) + createGetWithFields(['service', 'subservice', 'protocol', 'apikey', 'type', 'limit', 'offset']) ); diff --git a/lib/services/configurations.js b/lib/services/configurations.js index a4003cc..aaee8f2 100644 --- a/lib/services/configurations.js +++ b/lib/services/configurations.js @@ -111,7 +111,6 @@ function translateToApi(logger, configurations) { function handleListRequest(req, res, next) { const logger = req.logger; configurationData.list( - logger, req.headers['fiware-service'], req.headers['fiware-servicepath'], req.query.protocol, diff --git a/lib/services/protocolData.js b/lib/services/protocolData.js index e9a5246..edbf04d 100644 --- a/lib/services/protocolData.js +++ b/lib/services/protocolData.js @@ -34,7 +34,7 @@ const apply = async.apply; // }; function processConfiguration(logger, protocol, description, iotagent, resource, configuration, callback) { - configurations.get(logger, configuration.apikey, resource, protocol, function (error, oldConfiguration) { + configurations.get(configuration.apikey, resource, protocol, function (error, oldConfiguration) { if (error) { callback(error); } else if (oldConfiguration.services.length === 0) { diff --git a/lib/utils/constants.js b/lib/utils/constants.js index a2b2c54..9ced005 100644 --- a/lib/utils/constants.js +++ b/lib/utils/constants.js @@ -35,5 +35,9 @@ module.exports = { DEFAULT_RESOURCE: '/iot/d', DEFAULT_MONGODB_RETRIES: 5, - DEFAULT_MONGODB_RETRY_TIME: 5 + DEFAULT_MONGODB_RETRY_TIME: 5, + + FORWARDED_HEADER: 'forwarded', + X_REAL_IP_HEADER: 'x-real-ip', + CORRELATOR_HEADER: 'fiware-correlator' }; diff --git a/test/unit/configuration-retrieval-test.js b/test/unit/configuration-retrieval-test.js index 2ee1b48..da97485 100644 --- a/test/unit/configuration-retrieval-test.js +++ b/test/unit/configuration-retrieval-test.js @@ -160,7 +160,7 @@ describe('Configuration list', function () { }); }); - describe('When a configuration list request with a limit 3 arrives to the IoTAM', function () { + describe('When a configuration list request with a limit 2 arrives to the IoTAM', function () { const options = { url: 'http://localhost:' + iotConfig.server.port + '/iot/services', headers: { @@ -168,14 +168,14 @@ describe('Configuration list', function () { 'fiware-servicepath': '/gardens' }, qs: { - limit: 3 + limit: 2 }, method: 'GET' }; it('should return just 3 results', function (done) { request(options, function (error, response, body) { - body.services.length.should.equal(3); + body.services.length.should.equal(2); done(); }); });