params existence responsability for UserLimits
This commit is contained in:
parent
a997881048
commit
0bb7cec9f4
@ -51,10 +51,8 @@ function rateLimit(userLimits, endpointGroup = null) {
|
||||
}
|
||||
|
||||
function isRateLimitEnabled(endpointGroup) {
|
||||
return global.settings.ratelimits &&
|
||||
global.settings.ratelimits.rateLimitsEnabled &&
|
||||
return global.settings.ratelimits.rateLimitsEnabled &&
|
||||
endpointGroup &&
|
||||
global.settings.ratelimits.endpoints &&
|
||||
global.settings.ratelimits.endpoints[endpointGroup];
|
||||
}
|
||||
|
||||
|
@ -137,9 +137,10 @@ function App(statsClient) {
|
||||
|
||||
var userDatabaseService = new UserDatabaseService(metadataBackend);
|
||||
|
||||
UserLimitsService.configure();
|
||||
const userLimitsServiceOptions = {
|
||||
limits: {
|
||||
rateLimitsEnabled: (global.settings.ratelimits && global.settings.ratelimits.rateLimitsEnabled) || false
|
||||
rateLimitsEnabled: global.settings.ratelimits.rateLimitsEnabled
|
||||
}
|
||||
};
|
||||
const userLimitsService = new UserLimitsService(metadataBackend, userLimitsServiceOptions);
|
||||
|
@ -1,3 +1,14 @@
|
||||
const DEFAULT_RATE_LIMITS_OPTIONS = {
|
||||
rateLimitsEnabled: false,
|
||||
endpoints: {
|
||||
query: false,
|
||||
query_format: false,
|
||||
job_create: false,
|
||||
job_get: false,
|
||||
job_delete: false
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* UserLimits
|
||||
* @param {cartodb-redis} metadataBackend
|
||||
@ -11,6 +22,13 @@ class UserLimits {
|
||||
this.preprareRateLimit();
|
||||
}
|
||||
|
||||
static configure() {
|
||||
// default rate limits
|
||||
if(!global.settings.ratelimits) {
|
||||
global.settings.ratelimits = DEFAULT_RATE_LIMITS_OPTIONS;
|
||||
}
|
||||
}
|
||||
|
||||
preprareRateLimit() {
|
||||
if (this.options.limits.rateLimitsEnabled) {
|
||||
this.metadataBackend.loadRateLimitsScript();
|
||||
|
@ -72,10 +72,6 @@ function assertRequest (status, limit, remaining, reset, retry, done = null) {
|
||||
|
||||
describe('rate limit', function() {
|
||||
before(function() {
|
||||
if (!global.settings.ratelimits) {
|
||||
global.settings.ratelimits = {};
|
||||
global.settings.ratelimits.endpoints = {};
|
||||
}
|
||||
global.settings.ratelimits.rateLimitsEnabled = true;
|
||||
global.settings.ratelimits.endpoints.query = true;
|
||||
|
||||
@ -89,10 +85,6 @@ describe('rate limit', function() {
|
||||
});
|
||||
|
||||
after(function() {
|
||||
if (!global.settings.ratelimits) {
|
||||
global.settings.ratelimits = {};
|
||||
global.settings.ratelimits.endpoints = {};
|
||||
}
|
||||
global.settings.ratelimits.rateLimitsEnabled = false;
|
||||
global.settings.ratelimits.endpoints.query = false;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user