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) {
|
function isRateLimitEnabled(endpointGroup) {
|
||||||
return global.settings.ratelimits &&
|
return global.settings.ratelimits.rateLimitsEnabled &&
|
||||||
global.settings.ratelimits.rateLimitsEnabled &&
|
|
||||||
endpointGroup &&
|
endpointGroup &&
|
||||||
global.settings.ratelimits.endpoints &&
|
|
||||||
global.settings.ratelimits.endpoints[endpointGroup];
|
global.settings.ratelimits.endpoints[endpointGroup];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,9 +137,10 @@ function App(statsClient) {
|
|||||||
|
|
||||||
var userDatabaseService = new UserDatabaseService(metadataBackend);
|
var userDatabaseService = new UserDatabaseService(metadataBackend);
|
||||||
|
|
||||||
|
UserLimitsService.configure();
|
||||||
const userLimitsServiceOptions = {
|
const userLimitsServiceOptions = {
|
||||||
limits: {
|
limits: {
|
||||||
rateLimitsEnabled: (global.settings.ratelimits && global.settings.ratelimits.rateLimitsEnabled) || false
|
rateLimitsEnabled: global.settings.ratelimits.rateLimitsEnabled
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const userLimitsService = new UserLimitsService(metadataBackend, userLimitsServiceOptions);
|
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
|
* UserLimits
|
||||||
* @param {cartodb-redis} metadataBackend
|
* @param {cartodb-redis} metadataBackend
|
||||||
@ -11,6 +22,13 @@ class UserLimits {
|
|||||||
this.preprareRateLimit();
|
this.preprareRateLimit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static configure() {
|
||||||
|
// default rate limits
|
||||||
|
if(!global.settings.ratelimits) {
|
||||||
|
global.settings.ratelimits = DEFAULT_RATE_LIMITS_OPTIONS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
preprareRateLimit() {
|
preprareRateLimit() {
|
||||||
if (this.options.limits.rateLimitsEnabled) {
|
if (this.options.limits.rateLimitsEnabled) {
|
||||||
this.metadataBackend.loadRateLimitsScript();
|
this.metadataBackend.loadRateLimitsScript();
|
||||||
|
@ -72,10 +72,6 @@ function assertRequest (status, limit, remaining, reset, retry, done = null) {
|
|||||||
|
|
||||||
describe('rate limit', function() {
|
describe('rate limit', function() {
|
||||||
before(function() {
|
before(function() {
|
||||||
if (!global.settings.ratelimits) {
|
|
||||||
global.settings.ratelimits = {};
|
|
||||||
global.settings.ratelimits.endpoints = {};
|
|
||||||
}
|
|
||||||
global.settings.ratelimits.rateLimitsEnabled = true;
|
global.settings.ratelimits.rateLimitsEnabled = true;
|
||||||
global.settings.ratelimits.endpoints.query = true;
|
global.settings.ratelimits.endpoints.query = true;
|
||||||
|
|
||||||
@ -89,10 +85,6 @@ describe('rate limit', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
after(function() {
|
after(function() {
|
||||||
if (!global.settings.ratelimits) {
|
|
||||||
global.settings.ratelimits = {};
|
|
||||||
global.settings.ratelimits.endpoints = {};
|
|
||||||
}
|
|
||||||
global.settings.ratelimits.rateLimitsEnabled = false;
|
global.settings.ratelimits.rateLimitsEnabled = false;
|
||||||
global.settings.ratelimits.endpoints.query = false;
|
global.settings.ratelimits.endpoints.query = false;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user