Skip to content

Commit

Permalink
fix access to logger
Browse files Browse the repository at this point in the history
  • Loading branch information
AlvaroVega committed Feb 26, 2024
1 parent 897d791 commit c8c104e
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 15 deletions.
9 changes: 8 additions & 1 deletion lib/iotagent-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/model/dbConn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Check failure on line 32 in lib/model/dbConn.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript

'logger' is assigned a value but never used
const async = require('async');
const errors = require('../errors');
let defaultDb;
Expand Down
14 changes: 7 additions & 7 deletions lib/services/configurationData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -44,7 +44,7 @@ const provisioningAPITranslation = {
payloadType: 'payloadType'
};

function createGetWithFields(logger, fields) {
function createGetWithFields(fields) {
return function () {
const queryObj = {};
let i = 0;
Expand Down Expand Up @@ -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 = [
Expand All @@ -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;
Expand All @@ -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'])
);
1 change: 0 additions & 1 deletion lib/services/configurations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/services/protocolData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion lib/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
};
6 changes: 3 additions & 3 deletions test/unit/configuration-retrieval-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,22 +160,22 @@ 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: {
'fiware-service': 'smartGondor',
'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();
});
});
Expand Down

0 comments on commit c8c104e

Please sign in to comment.