From 06ec3f80b9d62f38c4917cd26756eebf0220f820 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Mart=C3=ADn?= Date: Tue, 20 Feb 2018 11:25:56 +0100 Subject: [PATCH] adding rate limit middlewware to named maps admin controller --- lib/cartodb/controllers/named_maps_admin.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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() );