From 1e413a9332436c644ea33715c01c44b0f59e523f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Thu, 26 Dec 2019 18:28:01 +0100 Subject: [PATCH] Eslint errors --- lib/api/middlewares/params.js | 2 +- lib/api/middlewares/socket-timeout.js | 2 +- lib/api/sql/job-controller.js | 8 +++---- lib/auth/oauth.js | 32 +++++++++++++-------------- lib/batch/batch-logger.js | 4 ---- lib/batch/batch.js | 10 ++++----- lib/batch/job-backend.js | 22 +++++++++--------- lib/batch/job-canceller.js | 8 +++---- lib/batch/job-runner.js | 8 +++++-- lib/batch/job-service.js | 14 ++++++------ 10 files changed, 55 insertions(+), 55 deletions(-) diff --git a/lib/api/middlewares/params.js b/lib/api/middlewares/params.js index 2304858a..9fe8f912 100644 --- a/lib/api/middlewares/params.js +++ b/lib/api/middlewares/params.js @@ -52,7 +52,7 @@ function queryParamsStrategy (input) { params.format = parseFormat(input.format); - if (!formats.hasOwnProperty(params.format)) { + if (!Object.prototype.hasOwnProperty.call(formats, params.format)) { throw new Error(`Invalid format: ${params.format}`); } diff --git a/lib/api/middlewares/socket-timeout.js b/lib/api/middlewares/socket-timeout.js index ff39f1dd..cd968766 100644 --- a/lib/api/middlewares/socket-timeout.js +++ b/lib/api/middlewares/socket-timeout.js @@ -1,7 +1,7 @@ 'use strict'; module.exports = function socketTimeout () { - if (!global.settings.hasOwnProperty('node_socket_timeout')) { + if (!Object.prototype.hasOwnProperty.call(global.settings, 'node_socket_timeout')) { return function dummySocketTimeoutMiddleware (req, res, next) { next(); }; diff --git a/lib/api/sql/job-controller.js b/lib/api/sql/job-controller.js index a52801b2..4b5f1081 100644 --- a/lib/api/sql/job-controller.js +++ b/lib/api/sql/job-controller.js @@ -73,9 +73,9 @@ function composeJobMiddlewares (metadataBackend, userDatabaseService, jobService function cancelJob (jobService) { return function cancelJobMiddleware (req, res, next) { - const { job_id } = req.params; + const { job_id: jobId } = req.params; - jobService.cancel(job_id, (err, job) => { + jobService.cancel(jobId, (err, job) => { if (req.profiler) { req.profiler.done('cancelJob'); } @@ -93,9 +93,9 @@ function cancelJob (jobService) { function getJob (jobService) { return function getJobMiddleware (req, res, next) { - const { job_id } = req.params; + const { job_id: jobId } = req.params; - jobService.get(job_id, (err, job) => { + jobService.get(jobId, (err, job) => { if (req.profiler) { req.profiler.done('getJob'); } diff --git a/lib/auth/oauth.js b/lib/auth/oauth.js index e7c64668..90a1512b 100644 --- a/lib/auth/oauth.js +++ b/lib/auth/oauth.js @@ -18,9 +18,9 @@ var oAuth = (function () { // * in GET request // * in header me.parseTokens = function (req) { - var query_oauth = _.clone(req.method === 'POST' ? req.body : req.query); - var header_oauth = {}; - var oauth_variables = ['oauth_body_hash', + var queryOauth = _.clone(req.method === 'POST' ? req.body : req.query); + var headerOauth = {}; + var oauthVariables = ['oauth_body_hash', 'oauth_consumer_key', 'oauth_token', 'oauth_signature_method', @@ -30,22 +30,22 @@ var oAuth = (function () { 'oauth_version']; // pull only oauth tokens out of query - var non_oauth = _.difference(_.keys(query_oauth), oauth_variables); - _.each(non_oauth, function (key) { delete query_oauth[key]; }); + var nonOauth = _.difference(_.keys(queryOauth), oauthVariables); + _.each(nonOauth, function (key) { delete queryOauth[key]; }); // pull oauth tokens out of header - var header_string = req.headers.authorization; - if (!_.isUndefined(header_string)) { - _.each(oauth_variables, function (oauth_key) { - var matched_string = header_string.match(new RegExp(oauth_key + '=\"([^\"]+)\"')); - if (!_.isNull(matched_string)) { - header_oauth[oauth_key] = decodeURIComponent(matched_string[1]); + var headerString = req.headers.authorization; + if (!_.isUndefined(headerString)) { + _.each(oauthVariables, function (oauthKey) { + var matchedString = headerString.match(new RegExp(oauthKey + '="([^"]+)"')); + if (!_.isNull(matchedString)) { + headerOauth[oauthKey] = decodeURIComponent(matchedString[1]); } }); } // merge header and query oauth tokens. preference given to header oauth - return _.defaults(header_oauth, query_oauth); + return _.defaults(headerOauth, queryOauth); }; // remove oauthy tokens from an object @@ -112,8 +112,8 @@ var oAuth = (function () { } var consumer = OAuthUtil.createConsumer(oAuthHash.consumer_key, oAuthHash.consumer_secret); - var access_token = OAuthUtil.createToken(oAuthHash.access_token_token, oAuthHash.access_token_secret); - var signer = OAuthUtil.createHmac(consumer, access_token); + var accessToken = OAuthUtil.createToken(oAuthHash.access_token_token, oAuthHash.access_token_secret); + var signer = OAuthUtil.createHmac(consumer, accessToken); var method = req.method; var hostsToValidate = {}; @@ -180,8 +180,8 @@ OAuthAuth.prototype.getCredentials = function () { OAuthAuth.prototype.hasCredentials = function () { if (this.isOAuthRequest === null) { - var passed_tokens = oAuth.parseTokens(this.req); - this.isOAuthRequest = !_.isEmpty(passed_tokens); + var passedTokens = oAuth.parseTokens(this.req); + this.isOAuthRequest = !_.isEmpty(passedTokens); } return this.isOAuthRequest; diff --git a/lib/batch/batch-logger.js b/lib/batch/batch-logger.js index 91b6b35e..a0d944ce 100644 --- a/lib/batch/batch-logger.js +++ b/lib/batch/batch-logger.js @@ -3,10 +3,6 @@ const Logger = require('../services/logger'); class BatchLogger extends Logger { - constructor (path, name) { - super(path, name); - } - log (job) { return job.log(this.logger); } diff --git a/lib/batch/batch.js b/lib/batch/batch.js index 3e99695c..832ed910 100644 --- a/lib/batch/batch.js +++ b/lib/batch/batch.js @@ -172,15 +172,15 @@ Batch.prototype.drain = function (callback) { Batch.prototype._drainJob = function (user, callback) { var self = this; - var job_id = this.getWorkInProgressJob(user); + var jobId = this.getWorkInProgressJob(user); - if (!job_id) { + if (!jobId) { return process.nextTick(function () { return callback(); }); } - this.jobService.drain(job_id, function (err) { + this.jobService.drain(jobId, function (err) { if (err && err.name === 'CancelNotAllowedError') { return callback(); } @@ -189,12 +189,12 @@ Batch.prototype._drainJob = function (user, callback) { return callback(err); } - self.clearWorkInProgressJob(user, job_id, function (err) { + self.clearWorkInProgressJob(user, jobId, function (err) { if (err) { self.logger.debug(new Error('Could not clear job from work-in-progress list. Reason: ' + err.message)); } - self.jobQueue.enqueueFirst(user, job_id, callback); + self.jobQueue.enqueueFirst(user, jobId, callback); }); }); }; diff --git a/lib/batch/job-backend.js b/lib/batch/job-backend.js index 6c914aa0..1f73d93d 100644 --- a/lib/batch/job-backend.js +++ b/lib/batch/job-backend.js @@ -20,7 +20,7 @@ function toRedisParams (job) { delete obj.job_id; for (var property in obj) { - if (obj.hasOwnProperty(property)) { + if (Object.prototype.hasOwnProperty.call(obj, property)) { redisParams.push(property); if (property === 'query' && typeof obj[property] !== 'string') { redisParams.push(JSON.stringify(obj[property])); @@ -33,7 +33,7 @@ function toRedisParams (job) { return redisParams; } -function toObject (job_id, redisParams, redisValues) { +function toObject (jobId, redisParams, redisValues) { var obj = {}; redisParams.shift(); // job_id value @@ -52,7 +52,7 @@ function toObject (job_id, redisParams, redisValues) { } } - obj.job_id = job_id; // adds redisKey as object property + obj.job_id = jobId; // adds redisKey as object property return obj; } @@ -61,20 +61,20 @@ function isJobFound (redisValues) { return !!(redisValues[0] && redisValues[1] && redisValues[2] && redisValues[3] && redisValues[4]); } -function getNotFoundError (job_id) { - var notFoundError = new Error('Job with id ' + job_id + ' not found'); +function getNotFoundError (jobId) { + var notFoundError = new Error('Job with id ' + jobId + ' not found'); notFoundError.name = 'NotFoundError'; return notFoundError; } -JobBackend.prototype.get = function (job_id, callback) { - if (!job_id) { - return callback(getNotFoundError(job_id)); +JobBackend.prototype.get = function (jobId, callback) { + if (!jobId) { + return callback(getNotFoundError(jobId)); } var self = this; var redisParams = [ - REDIS_PREFIX + job_id, + REDIS_PREFIX + jobId, 'user', 'status', 'query', @@ -96,10 +96,10 @@ JobBackend.prototype.get = function (job_id, callback) { } if (!isJobFound(redisValues)) { - return callback(getNotFoundError(job_id)); + return callback(getNotFoundError(jobId)); } - var jobData = toObject(job_id, redisParams, redisValues); + var jobData = toObject(jobId, redisParams, redisValues); callback(null, jobData); }); diff --git a/lib/batch/job-canceller.js b/lib/batch/job-canceller.js index dc00fdb8..976a5bce 100644 --- a/lib/batch/job-canceller.js +++ b/lib/batch/job-canceller.js @@ -19,10 +19,10 @@ JobCanceller.prototype.cancel = function (job, callback) { doCancel(job.data.job_id, dbConfiguration, callback); }; -function doCancel (job_id, dbConfiguration, callback) { +function doCancel (jobId, dbConfiguration, callback) { var pg = new PSQL(dbConfiguration); - getQueryPID(pg, job_id, function (err, pid) { + getQueryPID(pg, jobId, function (err, pid) { if (err) { return callback(err); } @@ -45,8 +45,8 @@ function doCancel (job_id, dbConfiguration, callback) { }); } -function getQueryPID (pg, job_id, callback) { - var getPIDQuery = "SELECT pid FROM pg_stat_activity WHERE query LIKE '/* " + job_id + " */%'"; +function getQueryPID (pg, jobId, callback) { + var getPIDQuery = "SELECT pid FROM pg_stat_activity WHERE query LIKE '/* " + jobId + " */%'"; pg.query(getPIDQuery, function (err, result) { if (err) { diff --git a/lib/batch/job-runner.js b/lib/batch/job-runner.js index 79dff67f..0eea3f06 100644 --- a/lib/batch/job-runner.js +++ b/lib/batch/job-runner.js @@ -18,13 +18,13 @@ function JobRunner (jobService, jobQueue, queryRunner, metadataBackend, statsdCl this.statsdClient = statsdClient; } -JobRunner.prototype.run = function (job_id, callback) { +JobRunner.prototype.run = function (jobId, callback) { var self = this; var profiler = new Profiler({ statsd_client: self.statsdClient }); profiler.start('sqlapi.batch.job'); - self.jobService.get(job_id, function (err, job) { + self.jobService.get(jobId, function (err, job) { if (err) { return callback(err); } @@ -70,6 +70,10 @@ JobRunner.prototype.getQueryStatementTimeout = function (username, callback) { var batchLimitsKey = REDIS_LIMITS.PREFIX + username; this.metadataBackend.redisCmd(REDIS_LIMITS.DB, 'HGET', [batchLimitsKey, 'timeout'], function (err, timeoutLimit) { + if (err) { + return callback(err); + } + if (timeoutLimit !== null && Number.isFinite(+timeoutLimit)) { timeout = +timeoutLimit; } diff --git a/lib/batch/job-service.js b/lib/batch/job-service.js index ff64b039..80a91f62 100644 --- a/lib/batch/job-service.js +++ b/lib/batch/job-service.js @@ -11,8 +11,8 @@ function JobService (jobBackend, jobCanceller, logger) { module.exports = JobService; -JobService.prototype.get = function (job_id, callback) { - this.jobBackend.get(job_id, function (err, data) { +JobService.prototype.get = function (jobId, callback) { + this.jobBackend.get(jobId, function (err, data) { if (err) { return callback(err); } @@ -68,10 +68,10 @@ JobService.prototype.save = function (job, callback) { }); }; -JobService.prototype.cancel = function (job_id, callback) { +JobService.prototype.cancel = function (jobId, callback) { var self = this; - self.get(job_id, function (err, job) { + self.get(jobId, function (err, job) { if (err) { return callback(err); } @@ -98,17 +98,17 @@ JobService.prototype.cancel = function (job_id, callback) { }); }; -JobService.prototype.drain = function (job_id, callback) { +JobService.prototype.drain = function (jobId, callback) { var self = this; - self.get(job_id, function (err, job) { + self.get(jobId, function (err, job) { if (err) { return callback(err); } self.jobCanceller.cancel(job, function (err) { if (err) { - self.logger.debug('There was an error while draining job %s, %s ', job_id, err); + self.logger.debug('There was an error while draining job %s, %s ', jobId, err); return callback(err); }