Rename user limits api by user limits backend

This commit is contained in:
Daniel García Aubert 2018-04-10 10:16:07 +02:00
parent 8519d2724b
commit d1a4057a8d
22 changed files with 108 additions and 108 deletions

View File

@ -14,7 +14,7 @@ const PgQueryRunner = require('../backends/pg_query_runner');
const StatsBackend = require('../backends/stats');
const AuthBackend = require('../backends/auth');
const UserLimitsApi = require('../backends/api/user_limits_api');
const UserLimitsBackend = require('../backends/user-limits');
const OverviewsMetadataBackend = require('../backends/overviews-metadata');
const FilterStatsApi = require('../backends/filter-stats');
const TablesExtentBackend = require('../backends/tables-extent');
@ -106,7 +106,7 @@ module.exports = class ApiRouter {
const dataviewBackend = new DataviewBackend(analysisBackend);
const statsBackend = new StatsBackend();
const userLimitsApi = new UserLimitsApi(metadataBackend, {
const userLimitsBackend = new UserLimitsBackend(metadataBackend, {
limits: {
cacheOnTimeout: serverOptions.renderer.mapnik.limits.cacheOnTimeout || false,
render: serverOptions.renderer.mapnik.limits.render || 0,
@ -145,7 +145,7 @@ module.exports = class ApiRouter {
templateMaps,
pgConnection,
metadataBackend,
userLimitsApi,
userLimitsBackend,
mapConfigAdapter,
layergroupAffectedTablesCache
);
@ -162,7 +162,7 @@ module.exports = class ApiRouter {
tileBackend,
pgConnection,
mapStore,
userLimitsApi,
userLimitsBackend,
layergroupAffectedTablesCache,
authBackend,
surrogateKeysCache,

View File

@ -8,10 +8,10 @@ const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimit;
const cacheControlHeader = require('../middlewares/cache-control-header');
const dbParamsFromResLocals = require('../../utils/database-params');
function AnalysesController(pgConnection, authBackend, userLimitsApi) {
function AnalysesController(pgConnection, authBackend, userLimitsBackend) {
this.pgConnection = pgConnection;
this.authBackend = authBackend;
this.userLimitsApi = userLimitsApi;
this.userLimitsBackend = userLimitsBackend;
}
module.exports = AnalysesController;
@ -22,7 +22,7 @@ AnalysesController.prototype.register = function (mapRouter) {
credentials(),
authorize(this.authBackend),
dbConnSetup(this.pgConnection),
rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.ANALYSIS_CATALOG),
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.ANALYSIS_CATALOG),
cleanUpQueryParams(),
createPGClient(),
getDataFromQuery({ queryTemplate: catalogQueryTpl, key: 'catalog' }),

View File

@ -12,7 +12,7 @@ module.exports = class AnalysisLayergroupController {
analysisStatusBackend,
pgConnection,
mapStore,
userLimitsApi,
userLimitsBackend,
layergroupAffectedTablesCache,
authBackend,
surrogateKeysCache
@ -20,7 +20,7 @@ module.exports = class AnalysisLayergroupController {
this.analysisStatusBackend = analysisStatusBackend;
this.pgConnection = pgConnection;
this.mapStore = mapStore;
this.userLimitsApi = userLimitsApi;
this.userLimitsBackend = userLimitsBackend;
this.layergroupAffectedTablesCache = layergroupAffectedTablesCache;
this.authBackend = authBackend;
this.surrogateKeysCache = surrogateKeysCache;
@ -33,7 +33,7 @@ module.exports = class AnalysisLayergroupController {
credentials(),
authorize(this.authBackend),
dbConnSetup(this.pgConnection),
rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.ANALYSIS),
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.ANALYSIS),
cleanUpQueryParams(),
analysisNodeStatus(this.analysisStatusBackend)
);

View File

@ -29,7 +29,7 @@ const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimit;
* @param {MapBackend} mapBackend
* @param metadataBackend
* @param {SurrogateKeysCache} surrogateKeysCache
* @param {UserLimitsApi} userLimitsApi
* @param {UserLimitsBackend} userLimitsBackend
* @param {LayergroupAffectedTables} layergroupAffectedTables
* @param {MapConfigAdapter} mapConfigAdapter
* @param {StatsBackend} statsBackend
@ -41,7 +41,7 @@ function AnonymousMapController (
mapBackend,
metadataBackend,
surrogateKeysCache,
userLimitsApi,
userLimitsBackend,
layergroupAffectedTables,
mapConfigAdapter,
statsBackend,
@ -53,7 +53,7 @@ function AnonymousMapController (
this.mapBackend = mapBackend;
this.metadataBackend = metadataBackend;
this.surrogateKeysCache = surrogateKeysCache;
this.userLimitsApi = userLimitsApi;
this.userLimitsBackend = userLimitsBackend;
this.layergroupAffectedTables = layergroupAffectedTables;
this.mapConfigAdapter = mapConfigAdapter;
this.statsBackend = statsBackend;
@ -80,7 +80,7 @@ AnonymousMapController.prototype.composeCreateMapMiddleware = function () {
credentials(),
authorize(this.authBackend),
dbConnSetup(this.pgConnection),
rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.ANONYMOUS),
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.ANONYMOUS),
cleanUpQueryParams(['aggregation']),
initProfiler(isTemplateInstantiation),
checkJsonContentType(),
@ -88,7 +88,7 @@ AnonymousMapController.prototype.composeCreateMapMiddleware = function () {
prepareAdapterMapConfig(this.mapConfigAdapter),
createLayergroup (
this.mapBackend,
this.userLimitsApi,
this.userLimitsBackend,
this.pgConnection,
this.layergroupAffectedTables
),
@ -166,7 +166,7 @@ function prepareAdapterMapConfig (mapConfigAdapter) {
};
}
function createLayergroup (mapBackend, userLimitsApi, pgConnection, affectedTablesCache) {
function createLayergroup (mapBackend, userLimitsBackend, pgConnection, affectedTablesCache) {
return function createLayergroupMiddleware (req, res, next) {
const requestMapConfig = req.body;
@ -185,7 +185,7 @@ function createLayergroup (mapBackend, userLimitsApi, pgConnection, affectedTabl
const mapConfigProvider = new CreateLayergroupMapConfigProvider(
mapConfig,
user,
userLimitsApi,
userLimitsBackend,
pgConnection,
affectedTablesCache,
params

View File

@ -16,7 +16,7 @@ module.exports = class AttributesLayergroupController {
attributesBackend,
pgConnection,
mapStore,
userLimitsApi,
userLimitsBackend,
layergroupAffectedTablesCache,
authBackend,
surrogateKeysCache
@ -24,7 +24,7 @@ module.exports = class AttributesLayergroupController {
this.attributesBackend = attributesBackend;
this.pgConnection = pgConnection;
this.mapStore = mapStore;
this.userLimitsApi = userLimitsApi;
this.userLimitsBackend = userLimitsBackend;
this.layergroupAffectedTablesCache = layergroupAffectedTablesCache;
this.authBackend = authBackend;
this.surrogateKeysCache = surrogateKeysCache;
@ -37,11 +37,11 @@ module.exports = class AttributesLayergroupController {
credentials(),
authorize(this.authBackend),
dbConnSetup(this.pgConnection),
rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.ATTRIBUTES),
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.ATTRIBUTES),
cleanUpQueryParams(),
createMapStoreMapConfigProvider(
this.mapStore,
this.userLimitsApi,
this.userLimitsBackend,
this.pgConnection,
this.layergroupAffectedTablesCache
),

View File

@ -31,7 +31,7 @@ module.exports = class DataviewLayergroupController {
dataviewBackend,
pgConnection,
mapStore,
userLimitsApi,
userLimitsBackend,
layergroupAffectedTablesCache,
authBackend,
surrogateKeysCache
@ -39,7 +39,7 @@ module.exports = class DataviewLayergroupController {
this.dataviewBackend = dataviewBackend;
this.pgConnection = pgConnection;
this.mapStore = mapStore;
this.userLimitsApi = userLimitsApi;
this.userLimitsBackend = userLimitsBackend;
this.layergroupAffectedTablesCache = layergroupAffectedTablesCache;
this.authBackend = authBackend;
this.surrogateKeysCache = surrogateKeysCache;
@ -55,11 +55,11 @@ module.exports = class DataviewLayergroupController {
credentials(),
authorize(this.authBackend),
dbConnSetup(this.pgConnection),
rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.DATAVIEW),
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.DATAVIEW),
cleanUpQueryParams(ALLOWED_DATAVIEW_QUERY_PARAMS),
createMapStoreMapConfigProvider(
this.mapStore,
this.userLimitsApi,
this.userLimitsBackend,
this.pgConnection,
this.layergroupAffectedTablesCache
),
@ -76,11 +76,11 @@ module.exports = class DataviewLayergroupController {
credentials(),
authorize(this.authBackend),
dbConnSetup(this.pgConnection),
rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.DATAVIEW),
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.DATAVIEW),
cleanUpQueryParams(ALLOWED_DATAVIEW_QUERY_PARAMS),
createMapStoreMapConfigProvider(
this.mapStore,
this.userLimitsApi,
this.userLimitsBackend,
this.pgConnection,
this.layergroupAffectedTablesCache
),
@ -97,11 +97,11 @@ module.exports = class DataviewLayergroupController {
credentials(),
authorize(this.authBackend),
dbConnSetup(this.pgConnection),
rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.DATAVIEW_SEARCH),
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.DATAVIEW_SEARCH),
cleanUpQueryParams(ALLOWED_DATAVIEW_QUERY_PARAMS),
createMapStoreMapConfigProvider(
this.mapStore,
this.userLimitsApi,
this.userLimitsBackend,
this.pgConnection,
this.layergroupAffectedTablesCache
),
@ -118,11 +118,11 @@ module.exports = class DataviewLayergroupController {
credentials(),
authorize(this.authBackend),
dbConnSetup(this.pgConnection),
rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.DATAVIEW_SEARCH),
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.DATAVIEW_SEARCH),
cleanUpQueryParams(ALLOWED_DATAVIEW_QUERY_PARAMS),
createMapStoreMapConfigProvider(
this.mapStore,
this.userLimitsApi,
this.userLimitsBackend,
this.pgConnection,
this.layergroupAffectedTablesCache
),

View File

@ -19,7 +19,7 @@ module.exports = class MapRouter {
tileBackend,
pgConnection,
mapStore,
userLimitsApi,
userLimitsBackend,
layergroupAffectedTablesCache,
authBackend,
surrogateKeysCache,
@ -37,7 +37,7 @@ module.exports = class MapRouter {
analysisStatusBackend,
pgConnection,
mapStore,
userLimitsApi,
userLimitsBackend,
layergroupAffectedTablesCache,
authBackend,
surrogateKeysCache
@ -47,7 +47,7 @@ module.exports = class MapRouter {
attributesBackend,
pgConnection,
mapStore,
userLimitsApi,
userLimitsBackend,
layergroupAffectedTablesCache,
authBackend,
surrogateKeysCache
@ -57,7 +57,7 @@ module.exports = class MapRouter {
dataviewBackend,
pgConnection,
mapStore,
userLimitsApi,
userLimitsBackend,
layergroupAffectedTablesCache,
authBackend,
surrogateKeysCache
@ -67,7 +67,7 @@ module.exports = class MapRouter {
previewBackend,
pgConnection,
mapStore,
userLimitsApi,
userLimitsBackend,
layergroupAffectedTablesCache,
authBackend,
surrogateKeysCache
@ -77,7 +77,7 @@ module.exports = class MapRouter {
tileBackend,
pgConnection,
mapStore,
userLimitsApi,
userLimitsBackend,
layergroupAffectedTablesCache,
authBackend,
surrogateKeysCache
@ -89,7 +89,7 @@ module.exports = class MapRouter {
mapBackend,
metadataBackend,
surrogateKeysCache,
userLimitsApi,
userLimitsBackend,
layergroupAffectedTablesCache,
mapConfigAdapter,
statsBackend,
@ -105,13 +105,13 @@ module.exports = class MapRouter {
metadataBackend,
pgConnection,
authBackend,
userLimitsApi
userLimitsBackend
);
this.analysesController = new AnalysesCatalogController(
pgConnection,
authBackend,
userLimitsApi
userLimitsBackend
);
}

View File

@ -16,7 +16,7 @@ module.exports = class PreviewLayergroupController {
previewBackend,
pgConnection,
mapStore,
userLimitsApi,
userLimitsBackend,
layergroupAffectedTablesCache,
authBackend,
surrogateKeysCache
@ -24,7 +24,7 @@ module.exports = class PreviewLayergroupController {
this.previewBackend = previewBackend;
this.pgConnection = pgConnection;
this.mapStore = mapStore;
this.userLimitsApi = userLimitsApi;
this.userLimitsBackend = userLimitsBackend;
this.layergroupAffectedTablesCache = layergroupAffectedTablesCache;
this.authBackend = authBackend;
this.surrogateKeysCache = surrogateKeysCache;
@ -39,11 +39,11 @@ module.exports = class PreviewLayergroupController {
credentials(),
authorize(this.authBackend),
dbConnSetup(this.pgConnection),
rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.STATIC),
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.STATIC),
cleanUpQueryParams(['layer']),
createMapStoreMapConfigProvider(
this.mapStore,
this.userLimitsApi,
this.userLimitsBackend,
this.pgConnection,
this.layergroupAffectedTablesCache,
forcedFormat
@ -61,11 +61,11 @@ module.exports = class PreviewLayergroupController {
credentials(),
authorize(this.authBackend),
dbConnSetup(this.pgConnection),
rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.STATIC),
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.STATIC),
cleanUpQueryParams(['layer']),
createMapStoreMapConfigProvider(
this.mapStore,
this.userLimitsApi,
this.userLimitsBackend,
this.pgConnection,
this.layergroupAffectedTablesCache,
forcedFormat

View File

@ -30,7 +30,7 @@ function PreviewTemplateController (
metadataBackend,
pgConnection,
authBackend,
userLimitsApi
userLimitsBackend
) {
this.namedMapProviderCache = namedMapProviderCache;
this.previewBackend = previewBackend;
@ -39,7 +39,7 @@ function PreviewTemplateController (
this.metadataBackend = metadataBackend;
this.pgConnection = pgConnection;
this.authBackend = authBackend;
this.userLimitsApi = userLimitsApi;
this.userLimitsBackend = userLimitsBackend;
}
module.exports = PreviewTemplateController;
@ -50,7 +50,7 @@ PreviewTemplateController.prototype.register = function (mapRouter) {
credentials(),
authorize(this.authBackend),
dbConnSetup(this.pgConnection),
rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.STATIC_NAMED),
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.STATIC_NAMED),
cleanUpQueryParams(['layer', 'zoom', 'lon', 'lat', 'bbox']),
namedMapProvider({
namedMapProviderCache: this.namedMapProviderCache,

View File

@ -26,7 +26,7 @@ module.exports = class TileLayergroupController {
tileBackend,
pgConnection,
mapStore,
userLimitsApi,
userLimitsBackend,
layergroupAffectedTablesCache,
authBackend,
surrogateKeysCache
@ -34,7 +34,7 @@ module.exports = class TileLayergroupController {
this.tileBackend = tileBackend;
this.pgConnection = pgConnection;
this.mapStore = mapStore;
this.userLimitsApi = userLimitsApi;
this.userLimitsBackend = userLimitsBackend;
this.layergroupAffectedTablesCache = layergroupAffectedTablesCache;
this.authBackend = authBackend;
this.surrogateKeysCache = surrogateKeysCache;
@ -52,11 +52,11 @@ module.exports = class TileLayergroupController {
credentials(),
authorize(this.authBackend),
dbConnSetup(this.pgConnection),
rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.TILE),
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.TILE),
cleanUpQueryParams(),
createMapStoreMapConfigProvider(
this.mapStore,
this.userLimitsApi,
this.userLimitsBackend,
this.pgConnection,
this.layergroupAffectedTablesCache
),
@ -77,11 +77,11 @@ module.exports = class TileLayergroupController {
credentials(),
authorize(this.authBackend),
dbConnSetup(this.pgConnection),
rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.TILE),
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.TILE),
cleanUpQueryParams(),
createMapStoreMapConfigProvider(
this.mapStore,
this.userLimitsApi,
this.userLimitsBackend,
this.pgConnection,
this.layergroupAffectedTablesCache
),
@ -102,11 +102,11 @@ module.exports = class TileLayergroupController {
credentials(),
authorize(this.authBackend),
dbConnSetup(this.pgConnection),
rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.TILE),
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.TILE),
cleanUpQueryParams(),
createMapStoreMapConfigProvider(
this.mapStore,
this.userLimitsApi,
this.userLimitsBackend,
this.pgConnection,
this.layergroupAffectedTablesCache
),

View File

@ -2,7 +2,7 @@ const MapStoreMapConfigProvider = require('../../models/mapconfig/provider/map-s
module.exports = function createMapStoreMapConfigProvider (
mapStore,
userLimitsApi,
userLimitsBackend,
pgConnection,
affectedTablesCache,
forcedFormat = null
@ -26,7 +26,7 @@ module.exports = function createMapStoreMapConfigProvider (
res.locals.mapConfigProvider = new MapStoreMapConfigProvider(
mapStore,
user,
userLimitsApi,
userLimitsBackend,
pgConnection,
affectedTablesCache,
params

View File

@ -19,13 +19,13 @@ const RATE_LIMIT_ENDPOINTS_GROUPS = {
NAMED_TILES: 'named_tiles'
};
function rateLimit(userLimitsApi, endpointGroup = null) {
function rateLimit(userLimitsBackend, endpointGroup = null) {
if (!isRateLimitEnabled(endpointGroup)) {
return function rateLimitDisabledMiddleware(req, res, next) { next(); };
}
return function rateLimitMiddleware(req, res, next) {
userLimitsApi.getRateLimit(res.locals.user, endpointGroup, function (err, userRateLimit) {
userLimitsBackend.getRateLimit(res.locals.user, endpointGroup, function (err, userRateLimit) {
if (err) {
return next(err);
}

View File

@ -9,10 +9,10 @@ const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimit;
* @param {TemplateMaps} templateMaps
* @constructor
*/
function AdminTemplateController(authBackend, templateMaps, userLimitsApi) {
function AdminTemplateController(authBackend, templateMaps, userLimitsBackend) {
this.authBackend = authBackend;
this.templateMaps = templateMaps;
this.userLimitsApi = userLimitsApi;
this.userLimitsBackend = userLimitsBackend;
}
module.exports = AdminTemplateController;
@ -24,7 +24,7 @@ AdminTemplateController.prototype.register = function (templateRouter) {
`/`,
credentials(),
authorizedByAPIKey({ authBackend: this.authBackend, action: 'create', label: 'POST TEMPLATE' }),
rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.NAMED_CREATE),
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.NAMED_CREATE),
checkContentType({ action: 'POST', label: 'POST TEMPLATE' }),
createTemplate({ templateMaps: this.templateMaps })
);
@ -33,7 +33,7 @@ AdminTemplateController.prototype.register = function (templateRouter) {
`/:template_id`,
credentials(),
authorizedByAPIKey({ authBackend: this.authBackend, action: 'update', label: 'PUT TEMPLATE' }),
rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.NAMED_UPDATE),
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.NAMED_UPDATE),
checkContentType({ action: 'PUT', label: 'PUT TEMPLATE' }),
updateTemplate({ templateMaps: this.templateMaps })
);
@ -42,7 +42,7 @@ AdminTemplateController.prototype.register = function (templateRouter) {
`/:template_id`,
credentials(),
authorizedByAPIKey({ authBackend: this.authBackend, action: 'get', label: 'GET TEMPLATE' }),
rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.NAMED_GET),
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.NAMED_GET),
retrieveTemplate({ templateMaps: this.templateMaps })
);
@ -50,7 +50,7 @@ AdminTemplateController.prototype.register = function (templateRouter) {
`/:template_id`,
credentials(),
authorizedByAPIKey({ authBackend: this.authBackend, action: 'delete', label: 'DELETE TEMPLATE' }),
rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.NAMED_DELETE),
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.NAMED_DELETE),
destroyTemplate({ templateMaps: this.templateMaps })
);
@ -58,7 +58,7 @@ AdminTemplateController.prototype.register = function (templateRouter) {
`/`,
credentials(),
authorizedByAPIKey({ authBackend: this.authBackend, action: 'list', label: 'GET TEMPLATE LIST' }),
rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.NAMED_LIST),
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.NAMED_LIST),
listTemplates({ templateMaps: this.templateMaps })
);
};

View File

@ -27,7 +27,7 @@ const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimit;
* @param {MapBackend} mapBackend
* @param metadataBackend
* @param {SurrogateKeysCache} surrogateKeysCache
* @param {UserLimitsApi} userLimitsApi
* @param {UserLimitsBackend} userLimitsBackend
* @param {LayergroupAffectedTables} layergroupAffectedTables
* @param {MapConfigAdapter} mapConfigAdapter
* @param {StatsBackend} statsBackend
@ -39,7 +39,7 @@ function NamedMapController (
mapBackend,
metadataBackend,
surrogateKeysCache,
userLimitsApi,
userLimitsBackend,
layergroupAffectedTables,
mapConfigAdapter,
statsBackend,
@ -51,7 +51,7 @@ function NamedMapController (
this.mapBackend = mapBackend;
this.metadataBackend = metadataBackend;
this.surrogateKeysCache = surrogateKeysCache;
this.userLimitsApi = userLimitsApi;
this.userLimitsBackend = userLimitsBackend;
this.layergroupAffectedTables = layergroupAffectedTables;
this.mapConfigAdapter = mapConfigAdapter;
this.statsBackend = statsBackend;
@ -84,7 +84,7 @@ NamedMapController.prototype.composeInstantiateTemplateMiddleware = function ()
credentials(),
authorize(this.authBackend),
dbConnSetup(this.pgConnection),
rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.NAMED),
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.NAMED),
cleanUpQueryParams(['aggregation']),
initProfiler(isTemplateInstantiation),
checkJsonContentType(),
@ -93,13 +93,13 @@ NamedMapController.prototype.composeInstantiateTemplateMiddleware = function ()
this.templateMaps,
this.pgConnection,
this.metadataBackend,
this.userLimitsApi,
this.userLimitsBackend,
this.mapConfigAdapter,
this.layergroupAffectedTables
),
instantiateLayergroup(
this.mapBackend,
this.userLimitsApi,
this.userLimitsBackend,
this.pgConnection,
this.layergroupAffectedTables
),
@ -145,7 +145,7 @@ function getTemplate (
templateMaps,
pgConnection,
metadataBackend,
userLimitsApi,
userLimitsBackend,
mapConfigAdapter,
affectedTablesCache
) {
@ -161,7 +161,7 @@ function getTemplate (
templateMaps,
pgConnection,
metadataBackend,
userLimitsApi,
userLimitsBackend,
mapConfigAdapter,
affectedTablesCache,
user,
@ -186,13 +186,13 @@ function getTemplate (
};
}
function instantiateLayergroup (mapBackend, userLimitsApi, pgConnection, affectedTablesCache) {
function instantiateLayergroup (mapBackend, userLimitsBackend, pgConnection, affectedTablesCache) {
return function instantiateLayergroupMiddleware (req, res, next) {
const { user, mapConfig, rendererParams } = res.locals;
const mapConfigProvider = new CreateLayergroupMapConfigProvider(
mapConfig,
user,
userLimitsApi,
userLimitsBackend,
pgConnection,
affectedTablesCache,
rendererParams

View File

@ -12,7 +12,7 @@ module.exports = class TemplateRouter {
mapBackend,
metadataBackend,
surrogateKeysCache,
userLimitsApi,
userLimitsBackend,
layergroupAffectedTablesCache,
mapConfigAdapter,
statsBackend,
@ -28,7 +28,7 @@ module.exports = class TemplateRouter {
mapBackend,
metadataBackend,
surrogateKeysCache,
userLimitsApi,
userLimitsBackend,
layergroupAffectedTablesCache,
mapConfigAdapter,
statsBackend,
@ -42,13 +42,13 @@ module.exports = class TemplateRouter {
surrogateKeysCache,
pgConnection,
authBackend,
userLimitsApi
userLimitsBackend
);
this.adminTemplateController = new AdminTemplateController(
authBackend,
templateMaps,
userLimitsApi
userLimitsBackend
);
}

View File

@ -17,14 +17,14 @@ function TileTemplateController (
surrogateKeysCache,
pgConnection,
authBackend,
userLimitsApi
userLimitsBackend
) {
this.namedMapProviderCache = namedMapProviderCache;
this.tileBackend = tileBackend;
this.surrogateKeysCache = surrogateKeysCache;
this.pgConnection = pgConnection;
this.authBackend = authBackend;
this.userLimitsApi = userLimitsApi;
this.userLimitsBackend = userLimitsBackend;
}
module.exports = TileTemplateController;
@ -35,7 +35,7 @@ TileTemplateController.prototype.register = function (templateRouter) {
credentials(),
authorize(this.authBackend),
dbConnSetup(this.pgConnection),
rateLimit(this.userLimitsApi, RATE_LIMIT_ENDPOINTS_GROUPS.NAMED_TILES),
rateLimit(this.userLimitsBackend, RATE_LIMIT_ENDPOINTS_GROUPS.NAMED_TILES),
cleanUpQueryParams(),
namedMapProvider({
namedMapProviderCache: this.namedMapProviderCache,

View File

@ -5,9 +5,9 @@ var step = require('step');
* @param metadataBackend
* @param options
* @constructor
* @type {UserLimitsApi}
* @type {UserLimitsBackend}
*/
function UserLimitsApi(metadataBackend, options) {
function UserLimitsBackend(metadataBackend, options) {
this.metadataBackend = metadataBackend;
this.options = options || {};
this.options.limits = this.options.limits || {};
@ -15,9 +15,9 @@ function UserLimitsApi(metadataBackend, options) {
this.preprareRateLimit();
}
module.exports = UserLimitsApi;
module.exports = UserLimitsBackend;
UserLimitsApi.prototype.getRenderLimits = function (username, apiKey, callback) {
UserLimitsBackend.prototype.getRenderLimits = function (username, apiKey, callback) {
var self = this;
var limits = {
@ -40,7 +40,7 @@ UserLimitsApi.prototype.getRenderLimits = function (username, apiKey, callback)
});
};
UserLimitsApi.prototype.getTimeoutRenderLimit = function (username, apiKey, callback) {
UserLimitsBackend.prototype.getTimeoutRenderLimit = function (username, apiKey, callback) {
var self = this;
step(
@ -80,12 +80,12 @@ UserLimitsApi.prototype.getTimeoutRenderLimit = function (username, apiKey, call
);
};
UserLimitsApi.prototype.preprareRateLimit = function () {
UserLimitsBackend.prototype.preprareRateLimit = function () {
if (this.options.limits.rateLimitsEnabled) {
this.metadataBackend.loadRateLimitsScript();
}
};
UserLimitsApi.prototype.getRateLimit = function (user, endpointGroup, callback) {
UserLimitsBackend.prototype.getRateLimit = function (user, endpointGroup, callback) {
this.metadataBackend.getRateLimit(user, 'maps', endpointGroup, callback);
};

View File

@ -10,14 +10,14 @@ function NamedMapProviderCache(
templateMaps,
pgConnection,
metadataBackend,
userLimitsApi,
userLimitsBackend,
mapConfigAdapter,
affectedTablesCache
) {
this.templateMaps = templateMaps;
this.pgConnection = pgConnection;
this.metadataBackend = metadataBackend;
this.userLimitsApi = userLimitsApi;
this.userLimitsBackend = userLimitsBackend;
this.mapConfigAdapter = mapConfigAdapter;
this.affectedTablesCache = affectedTablesCache;
@ -36,7 +36,7 @@ NamedMapProviderCache.prototype.get = function(user, templateId, config, authTok
this.templateMaps,
this.pgConnection,
this.metadataBackend,
this.userLimitsApi,
this.userLimitsBackend,
this.mapConfigAdapter,
this.affectedTablesCache,
user,

View File

@ -7,16 +7,16 @@ const QueryTables = require('cartodb-query-tables');
/**
* @param {MapConfig} mapConfig
* @param {String} user
* @param {UserLimitsApi} userLimitsApi
* @param {UserLimitsBackend} userLimitsBackend
* @param {Object} params
* @constructor
* @type {CreateLayergroupMapConfigProvider}
*/
function CreateLayergroupMapConfigProvider(mapConfig, user, userLimitsApi, pgConnection, affectedTablesCache, params) {
function CreateLayergroupMapConfigProvider(mapConfig, user, userLimitsBackend, pgConnection, affectedTablesCache, params) {
this.mapConfig = mapConfig;
this.user = user;
this.userLimitsApi = userLimitsApi;
this.userLimitsBackend = userLimitsBackend;
this.pgConnection = pgConnection;
this.affectedTablesCache = affectedTablesCache;
this.params = params;
@ -36,7 +36,7 @@ CreateLayergroupMapConfigProvider.prototype.getMapConfig = function(callback) {
step(
function prepareContextLimits() {
self.userLimitsApi.getRenderLimits(self.user, self.params.api_key, this);
self.userLimitsBackend.getRenderLimits(self.user, self.params.api_key, this);
},
function handleRenderLimits(err, renderLimits) {
assert.ifError(err);

View File

@ -7,15 +7,15 @@ const QueryTables = require('cartodb-query-tables');
/**
* @param {MapStore} mapStore
* @param {String} user
* @param {UserLimitsApi} userLimitsApi
* @param {UserLimitsBackend} userLimitsBackend
* @param {Object} params
* @constructor
* @type {MapStoreMapConfigProvider}
*/
function MapStoreMapConfigProvider(mapStore, user, userLimitsApi, pgConnection, affectedTablesCache, params) {
function MapStoreMapConfigProvider(mapStore, user, userLimitsBackend, pgConnection, affectedTablesCache, params) {
this.mapStore = mapStore;
this.user = user;
this.userLimitsApi = userLimitsApi;
this.userLimitsBackend = userLimitsBackend;
this.pgConnection = pgConnection;
this.affectedTablesCache = affectedTablesCache;
this.token = params.token;
@ -38,7 +38,7 @@ MapStoreMapConfigProvider.prototype.getMapConfig = function(callback) {
step(
function prepareContextLimits() {
self.userLimitsApi.getRenderLimits(self.user, self.params.api_key, this);
self.userLimitsBackend.getRenderLimits(self.user, self.params.api_key, this);
},
function handleRenderLimits(err, renderLimits) {
assert.ifError(err);

View File

@ -15,7 +15,7 @@ function NamedMapMapConfigProvider(
templateMaps,
pgConnection,
metadataBackend,
userLimitsApi,
userLimitsBackend,
mapConfigAdapter,
affectedTablesCache,
owner,
@ -27,7 +27,7 @@ function NamedMapMapConfigProvider(
this.templateMaps = templateMaps;
this.pgConnection = pgConnection;
this.metadataBackend = metadataBackend;
this.userLimitsApi = userLimitsApi;
this.userLimitsBackend = userLimitsBackend;
this.mapConfigAdapter = mapConfigAdapter;
this.owner = owner;
@ -125,7 +125,7 @@ NamedMapMapConfigProvider.prototype.getMapConfig = function(callback) {
function prepareContextLimits(err, _mapConfig) {
assert.ifError(err);
mapConfig = _mapConfig;
self.userLimitsApi.getRenderLimits(self.owner, self.params.api_key, this);
self.userLimitsBackend.getRenderLimits(self.owner, self.params.api_key, this);
},
function cacheAndReturnMapConfig(err, renderLimits) {
self.err = err;

View File

@ -5,7 +5,7 @@ const redis = require('redis');
const RedisPool = require('redis-mpool');
const cartodbRedis = require('cartodb-redis');
const TestClient = require('../support/test-client');
const UserLimitsApi = require('../../lib/cartodb/backends/api/user_limits_api');
const UserLimitsBackend = require('../../lib/cartodb/backends/user-limits');
const rateLimitMiddleware = require('../../lib/cartodb/api/middlewares/rate-limit');
const { RATE_LIMIT_ENDPOINTS_GROUPS } = rateLimitMiddleware;
@ -218,7 +218,7 @@ describe('rate limit middleware', function () {
const redisPool = new RedisPool(global.environment.redis);
const metadataBackend = cartodbRedis({ pool: redisPool });
userLimitsApi = new UserLimitsApi(metadataBackend, {
userLimitsApi = new UserLimitsBackend(metadataBackend, {
limits: {
rateLimitsEnabled: global.environment.enabledFeatures.rateLimitsEnabled
}