diff --git a/lib/cartodb/controllers/named_maps_admin.js b/lib/cartodb/controllers/named_maps_admin.js index a4d05467..88caf741 100644 --- a/lib/cartodb/controllers/named_maps_admin.js +++ b/lib/cartodb/controllers/named_maps_admin.js @@ -1,6 +1,7 @@ const { templateName } = require('../backends/template_maps'); const cors = require('../middleware/cors'); const userMiddleware = require('../middleware/user'); +const { rateLimitMiddleware, RATE_LIMIT_ENDPOINTS_GROUPS } = require('../middleware/rate-limit'); /** * @param {AuthApi} authApi @@ -8,9 +9,10 @@ const userMiddleware = require('../middleware/user'); * @param {TemplateMaps} templateMaps * @constructor */ -function NamedMapsAdminController(authApi, templateMaps) { +function NamedMapsAdminController(authApi, templateMaps, metadataBackend) { this.authApi = authApi; this.templateMaps = templateMaps; + this.metadataBackend = metadataBackend; } module.exports = NamedMapsAdminController; @@ -22,6 +24,7 @@ NamedMapsAdminController.prototype.register = function (app) { `${base_url_templated}/`, cors(), userMiddleware, + rateLimitMiddleware(this.metadataBackend, RATE_LIMIT_ENDPOINTS_GROUPS.ENDPOINT_11), this.checkContentType('POST', 'POST TEMPLATE'), this.authorizedByAPIKey('create', 'POST TEMPLATE'), this.create() @@ -31,6 +34,7 @@ NamedMapsAdminController.prototype.register = function (app) { `${base_url_templated}/:template_id`, cors(), userMiddleware, + rateLimitMiddleware(this.metadataBackend, RATE_LIMIT_ENDPOINTS_GROUPS.ENDPOINT_14), this.checkContentType('PUT', 'PUT TEMPLATE'), this.authorizedByAPIKey('update', 'PUT TEMPLATE'), this.update() @@ -40,6 +44,7 @@ NamedMapsAdminController.prototype.register = function (app) { `${base_url_templated}/:template_id`, cors(), userMiddleware, + rateLimitMiddleware(this.metadataBackend, RATE_LIMIT_ENDPOINTS_GROUPS.ENDPOINT_12), this.authorizedByAPIKey('get', 'GET TEMPLATE'), this.retrieve() ); @@ -48,6 +53,7 @@ NamedMapsAdminController.prototype.register = function (app) { `${base_url_templated}/:template_id`, cors(), userMiddleware, + rateLimitMiddleware(this.metadataBackend, RATE_LIMIT_ENDPOINTS_GROUPS.ENDPOINT_15), this.authorizedByAPIKey('delete', 'DELETE TEMPLATE'), this.destroy() ); @@ -56,6 +62,7 @@ NamedMapsAdminController.prototype.register = function (app) { `${base_url_templated}/`, cors(), userMiddleware, + rateLimitMiddleware(this.metadataBackend, RATE_LIMIT_ENDPOINTS_GROUPS.ENDPOINT_10), this.authorizedByAPIKey('list', 'GET TEMPLATE LIST'), this.list() );