make jshint happy

This commit is contained in:
Simon Martín 2018-03-01 14:47:34 +01:00
parent f3adad57aa
commit 7a6ef637ae
5 changed files with 45 additions and 13 deletions

View File

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

View File

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

View File

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

View File

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

View File

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