Eslint errors

remotes/origin/middlewarify-query-controller
Daniel García Aubert 5 years ago
parent ac4d1c4e28
commit 1e413a9332

@ -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}`);
}

@ -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();
};

@ -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');
}

@ -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;

@ -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);
}

@ -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);
});
});
};

@ -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);
});

@ -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) {

@ -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;
}

@ -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);
}

Loading…
Cancel
Save