From 7a6ef637ae4f54194ea4d68224f82541b0ed1af8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Mart=C3=ADn?= Date: Thu, 1 Mar 2018 14:47:34 +0100 Subject: [PATCH] make jshint happy --- app/controllers/job_controller.js | 25 +++++++++++++++++++++---- app/controllers/query_controller.js | 2 +- app/middlewares/rate-limit.js | 6 +++--- app/server.js | 16 ++++++++++++++-- app/services/user_limits.js | 9 ++++++--- 5 files changed, 45 insertions(+), 13 deletions(-) diff --git a/app/controllers/job_controller.js b/app/controllers/job_controller.js index 699774d1..bc0e696c 100644 --- a/app/controllers/job_controller.js +++ b/app/controllers/job_controller.js @@ -27,10 +27,27 @@ JobController.prototype.route = function (app) { this.statsdClient ); - app.get(`${base_url}/jobs-wip`, listWorkInProgressJobs(this.jobService), sendResponse(), errorMiddleware()); - app.post(`${base_url}/sql/job`, checkBodyPayloadSize(), jobMiddlewares('create', createJob, RATE_LIMIT_ENDPOINTS_GROUPS.JOB_CREATE)); - app.get(`${base_url}/sql/job/:job_id`, jobMiddlewares('retrieve', getJob, RATE_LIMIT_ENDPOINTS_GROUPS.JOB_GET)); - app.delete(`${base_url}/sql/job/:job_id`, jobMiddlewares('cancel', cancelJob, RATE_LIMIT_ENDPOINTS_GROUPS.JOB_DELETE)); + app.get( + `${base_url}/jobs-wip`, + listWorkInProgressJobs(this.jobService), + sendResponse(), + errorMiddleware() + ); + app.post( + `${base_url}/sql/job`, + checkBodyPayloadSize(), + jobMiddlewares('create', createJob, RATE_LIMIT_ENDPOINTS_GROUPS.JOB_CREATE) + ); + app.get( + `${base_url}/sql/job/:job_id`, + jobMiddlewares('retrieve', + getJob, + RATE_LIMIT_ENDPOINTS_GROUPS.JOB_GET) + ); + app.delete( + `${base_url}/sql/job/:job_id`, + jobMiddlewares('cancel', cancelJob, RATE_LIMIT_ENDPOINTS_GROUPS.JOB_DELETE) + ); }; function composeJobMiddlewares (metadataBackend, userDatabaseService, jobService, statsdClient) { diff --git a/app/controllers/query_controller.js b/app/controllers/query_controller.js index 5e4df7c7..f2365753 100644 --- a/app/controllers/query_controller.js +++ b/app/controllers/query_controller.js @@ -43,7 +43,7 @@ QueryController.prototype.route = function (app) { this.handleQuery.bind(this), errorMiddleware() ]; - } + }; app.all(`${base_url}/sql`, queryMiddlewares(RATE_LIMIT_ENDPOINTS_GROUPS.QUERY)); app.all(`${base_url}/sql.:f`, queryMiddlewares(RATE_LIMIT_ENDPOINTS_GROUPS.QUERY_FORMAT)); diff --git a/app/middlewares/rate-limit.js b/app/middlewares/rate-limit.js index 38499820..4abc464a 100644 --- a/app/middlewares/rate-limit.js +++ b/app/middlewares/rate-limit.js @@ -40,9 +40,9 @@ function rateLimitFn(userLimits, endpointGroup = null) { }); if (isBlocked) { - const err = new Error('You are over the limits.'); - err.http_status = 429; - return next(err); + const rateLimitError = new Error('You are over the limits.'); + rateLimitError.http_status = 429; + return next(rateLimitError); } return next(); diff --git a/app/server.js b/app/server.js index 092883cf..6223d4eb 100644 --- a/app/server.js +++ b/app/server.js @@ -154,10 +154,22 @@ function App(statsClient) { var genericController = new GenericController(); genericController.route(app); - var queryController = new QueryController(metadataBackend, userDatabaseService, tableCache, statsClient, userLimitsService); + var queryController = new QueryController( + metadataBackend, + userDatabaseService, + tableCache, + statsClient, + userLimitsService + ); queryController.route(app); - var jobController = new JobController(metadataBackend, userDatabaseService, jobService, statsClient, userLimitsService); + var jobController = new JobController( + metadataBackend, + userDatabaseService, + jobService, + statsClient, + userLimitsService + ); jobController.route(app); var cacheStatusController = new CacheStatusController(tableCache); diff --git a/app/services/user_limits.js b/app/services/user_limits.js index 15b90b69..a7a3ee6e 100644 --- a/app/services/user_limits.js +++ b/app/services/user_limits.js @@ -1,3 +1,4 @@ +const RATE_LIMIT_REDIS_DB = 8; const getRateLimitLuaScript = ` local results = {} local resultsCounter = 0 @@ -137,7 +138,9 @@ class UserLimits { this.rateLimits.redisCommand, redisParams, (err, rateLimits) => { - if (err && err.name === 'ReplyError' && err.message === 'NOSCRIPT No matching script. Please use EVAL.') { + if (err && err.name === 'ReplyError' && + err.message === 'NOSCRIPT No matching script. Please use EVAL.') + { self.rateLimits.redisCommand = 'EVAL'; return self.getRateLimit(user, endpointGroup, callback); } @@ -150,7 +153,7 @@ class UserLimits { callback(err, rateLimit); } ); - }; -}; + } +} module.exports = UserLimits;