From 0047af92aab14e830f81f4b28104acf85d6db586 Mon Sep 17 00:00:00 2001 From: pantsel Date: Wed, 3 Apr 2019 21:47:49 +0300 Subject: [PATCH] Fix new response-ratelimiting plugin schema. Ref issue #363 --- .../app/apis/controllers/apis-controller.js | 2 +- .../certificates/certificates-controller.js | 2 +- .../app/connections/connections-controller.js | 4 +- .../apis/consumer-apis-controller.js | 2 +- .../consumer-credentials-controller.js | 10 +- .../mass-assign-credentials-controller.js | 2 +- .../groups/consumer-groups-controller.js | 2 +- .../groups/manage-groups-modal-controllers.js | 2 +- .../plugins/consumer-plugins-controller.js | 2 +- .../routes/consumer-routes-controller.js | 2 +- .../services/consumer-services-controller.js | 2 +- assets/js/app/core/services/DialogService.js | 42 ++- .../js/app/core/services/ListConfigService.js | 2 +- .../healthchecks/healthchecks-controller.js | 2 +- .../js/app/plugins/add-plugin-controller.js | 29 +- .../plugins/add-plugin-modal-controller.js | 2 +- .../js/app/plugins/api-plugins-controller.js | 2 +- .../js/app/plugins/edit-plugin-controller.js | 98 ++++--- .../plugins/forms/response-ratelimiting.html | 270 ++++++++++++++++++ .../app/plugins/modals/add-plugin-modal.html | 2 +- .../app/plugins/modals/edit-plugin-modal.html | 4 +- .../controllers/route-plugins-controller.js | 2 +- .../controllers/service-plugins-controller.js | 2 +- .../controllers/service-routes-controller.js | 2 +- .../edit-upstream-targets-controller.js | 2 +- assets/js/app/users/users-controller.js | 2 +- 26 files changed, 426 insertions(+), 69 deletions(-) create mode 100644 assets/js/app/plugins/forms/response-ratelimiting.html diff --git a/assets/js/app/apis/controllers/apis-controller.js b/assets/js/app/apis/controllers/apis-controller.js index 8ac500cf1..032eb402f 100644 --- a/assets/js/app/apis/controllers/apis-controller.js +++ b/assets/js/app/apis/controllers/apis-controller.js @@ -134,7 +134,7 @@ } function deleteApiHealthChecks() { - DialogService.prompt( + DialogService.confirm( "Confirm", "You are about to reset the healthchecks of all APIs on all Kong connections." + "

That means that you will have to setup each and every one of the from scratch." + "

Don't worry about affecting the API or Kong Connections entities." + diff --git a/assets/js/app/certificates/certificates-controller.js b/assets/js/app/certificates/certificates-controller.js index c60237c86..e1b851e05 100644 --- a/assets/js/app/certificates/certificates-controller.js +++ b/assets/js/app/certificates/certificates-controller.js @@ -33,7 +33,7 @@ } $scope.deleteSNI = function (sni) { - DialogService.prompt( + DialogService.confirm( "Confirm", "Really want to delete the selected item?", ['No don\'t', 'Yes! delete it'], function accept() { diff --git a/assets/js/app/connections/connections-controller.js b/assets/js/app/connections/connections-controller.js index dfead4b84..14a8d2cd0 100644 --- a/assets/js/app/connections/connections-controller.js +++ b/assets/js/app/connections/connections-controller.js @@ -123,7 +123,7 @@ return false; } - DialogService.prompt( + DialogService.confirm( "Confirm", "Really want to delete the selected item?", ['No don\'t', 'Yes! delete it'], function accept() { @@ -528,4 +528,4 @@ } ]) ; -}()); \ No newline at end of file +}()); diff --git a/assets/js/app/consumers/apis/consumer-apis-controller.js b/assets/js/app/consumers/apis/consumer-apis-controller.js index 90cb3141a..77ad92a70 100644 --- a/assets/js/app/consumers/apis/consumer-apis-controller.js +++ b/assets/js/app/consumers/apis/consumer-apis-controller.js @@ -139,7 +139,7 @@ } function deletePlugin(api,plugin) { - DialogService.prompt( + DialogService.confirm( "Delete Plugin","Really want to delete the plugin?", ['No don\'t','Yes! delete it'], function accept(){ diff --git a/assets/js/app/consumers/credentials/consumer-credentials-controller.js b/assets/js/app/consumers/credentials/consumer-credentials-controller.js index a63256995..1a987c408 100644 --- a/assets/js/app/consumers/credentials/consumer-credentials-controller.js +++ b/assets/js/app/consumers/credentials/consumer-credentials-controller.js @@ -94,7 +94,7 @@ function deleteHMACAuthCredentials($index, credentials) { - DialogService.prompt( + DialogService.confirm( "Delete Credentials", "Really want to delete the selected credentials?", ['No don\'t', 'Yes! delete it'], function accept() { @@ -112,7 +112,7 @@ } function deleteBasicAuthCredentials($index, credentials) { - DialogService.prompt( + DialogService.confirm( "Delete Credentials", "Really want to delete the selected credentials?", ['No don\'t', 'Yes! delete it'], function accept() { @@ -130,7 +130,7 @@ } function deleteOAuth2($index, oauth) { - DialogService.prompt( + DialogService.confirm( "Delete JWT", "Really want to delete the selected OAuth2?", ['No don\'t', 'Yes! delete it'], function accept() { @@ -148,7 +148,7 @@ } function deleteJWT($index, jwt) { - DialogService.prompt( + DialogService.confirm( "Delete JWT", "Really want to delete the selected JWT?", ['No don\'t', 'Yes! delete it'], function accept() { @@ -166,7 +166,7 @@ } function deleteKey($index, key) { - DialogService.prompt( + DialogService.confirm( "Delete Key", "Really want to delete the selected key?", ['No don\'t', 'Yes! delete it'], function accept() { diff --git a/assets/js/app/consumers/credentials/mass-assign-credentials-controller.js b/assets/js/app/consumers/credentials/mass-assign-credentials-controller.js index b247464f5..30b465818 100644 --- a/assets/js/app/consumers/credentials/mass-assign-credentials-controller.js +++ b/assets/js/app/consumers/credentials/mass-assign-credentials-controller.js @@ -42,7 +42,7 @@ $scope.onCredentialSelected = function(credential) { - DialogService.prompt( + DialogService.confirm( "Mass Assign Credentials", "You are about to mass assign " + credential + " credentials" + " to " + $scope.consumers.length + " selected consumers.
Continue?", diff --git a/assets/js/app/consumers/groups/consumer-groups-controller.js b/assets/js/app/consumers/groups/consumer-groups-controller.js index 9abfa8648..8cd9fdf3d 100644 --- a/assets/js/app/consumers/groups/consumer-groups-controller.js +++ b/assets/js/app/consumers/groups/consumer-groups-controller.js @@ -58,7 +58,7 @@ } function deleteConsumerGroup(group) { - DialogService.prompt( + DialogService.confirm( "Delete Group", "Really want to remove the group from the consumer?", ['No', 'Remove it!'], function accept() { diff --git a/assets/js/app/consumers/groups/manage-groups-modal-controllers.js b/assets/js/app/consumers/groups/manage-groups-modal-controllers.js index 105a33218..30ac196b8 100644 --- a/assets/js/app/consumers/groups/manage-groups-modal-controllers.js +++ b/assets/js/app/consumers/groups/manage-groups-modal-controllers.js @@ -97,7 +97,7 @@ function deleteGroup(group) { - DialogService.prompt( + DialogService.confirm( "Delete Group","Really want to delete the '" + group.name + "' group?", ['No don\'t','Yes! delete it'], function accept(){ diff --git a/assets/js/app/consumers/plugins/consumer-plugins-controller.js b/assets/js/app/consumers/plugins/consumer-plugins-controller.js index 8b2c9b616..6b18beddf 100644 --- a/assets/js/app/consumers/plugins/consumer-plugins-controller.js +++ b/assets/js/app/consumers/plugins/consumer-plugins-controller.js @@ -105,7 +105,7 @@ } function deletePlugin(plugin) { - DialogService.prompt( + DialogService.confirm( "Delete Plugin", "Really want to delete the plugin?", ['No don\'t', 'Yes! delete it'], function accept() { diff --git a/assets/js/app/consumers/routes/consumer-routes-controller.js b/assets/js/app/consumers/routes/consumer-routes-controller.js index 10ffdfd94..29a64a57b 100644 --- a/assets/js/app/consumers/routes/consumer-routes-controller.js +++ b/assets/js/app/consumers/routes/consumer-routes-controller.js @@ -141,7 +141,7 @@ function deletePlugin(api,plugin) { - DialogService.prompt( + DialogService.confirm( "Delete Plugin","Really want to delete the plugin?", ['No don\'t','Yes! delete it'], function accept(){ diff --git a/assets/js/app/consumers/services/consumer-services-controller.js b/assets/js/app/consumers/services/consumer-services-controller.js index 1fd43a1cc..4b083e7c2 100644 --- a/assets/js/app/consumers/services/consumer-services-controller.js +++ b/assets/js/app/consumers/services/consumer-services-controller.js @@ -139,7 +139,7 @@ function deletePlugin(api,plugin) { - DialogService.prompt( + DialogService.confirm( "Delete Plugin","Really want to delete the plugin?", ['No don\'t','Yes! delete it'], function accept(){ diff --git a/assets/js/app/core/services/DialogService.js b/assets/js/app/core/services/DialogService.js index 3b850f826..93380e022 100644 --- a/assets/js/app/core/services/DialogService.js +++ b/assets/js/app/core/services/DialogService.js @@ -22,7 +22,7 @@ - service.prompt = function prompt(title,message, buttonTexts,accept, decline) { + service.confirm = function prompt(title,message, buttonTexts,accept, decline) { var modalInstance = $uibModal.open({ animation: true, @@ -89,6 +89,46 @@ }; + service.prompt = function prompt(title,message,accept, decline) { + + var modalInstance = $uibModal.open({ + animation: true, + ariaLabelledBy: 'modal-title', + ariaDescribedBy: 'modal-body', + windowClass : 'dialog', + template: '' + + '' + + '' + + '' + + '', + controller: function($scope,$uibModalInstance){ + $scope.data = ''; + $scope.accept = function() { + if(!$scope.data) return false; + $uibModalInstance.close($scope.data) + } + $scope.decline = function(){ + $uibModalInstance.dismiss('decline') + } + }, + size: 'sm' + }); + + modalInstance.result.then(function (d) { + accept(d); + }, function (d) { + decline() + }); + + }; + diff --git a/assets/js/app/core/services/ListConfigService.js b/assets/js/app/core/services/ListConfigService.js index 6cd2519a9..a54c63b4c 100644 --- a/assets/js/app/core/services/ListConfigService.js +++ b/assets/js/app/core/services/ListConfigService.js @@ -733,7 +733,7 @@ }, deleteItem: function deleteItem($index, item) { - DialogService.prompt( + DialogService.confirm( "Confirm", "Really want to delete the selected item?", ['No don\'t', 'Yes! delete it'], function accept() { diff --git a/assets/js/app/healthchecks/healthchecks-controller.js b/assets/js/app/healthchecks/healthchecks-controller.js index c0c4fca59..eae37c37e 100644 --- a/assets/js/app/healthchecks/healthchecks-controller.js +++ b/assets/js/app/healthchecks/healthchecks-controller.js @@ -192,7 +192,7 @@ $scope.deleteItem = function deleteItem(item) { - DialogService.prompt( + DialogService.confirm( "Confirm", "Really want to delete the selected item?", ['No don\'t', 'Yes! delete it'], function accept() { diff --git a/assets/js/app/plugins/add-plugin-controller.js b/assets/js/app/plugins/add-plugin-controller.js index a5ad3d6f5..9b631140a 100644 --- a/assets/js/app/plugins/add-plugin-controller.js +++ b/assets/js/app/plugins/add-plugin-controller.js @@ -9,10 +9,10 @@ angular.module('frontend.plugins') .controller('AddPluginController', [ '_', '$scope', '$rootScope', '$log', '$state', 'ListConfig', 'ApiService', - 'MessageService', 'ConsumerModel', 'ServiceService', 'SocketHelperService', 'PluginHelperService', + 'MessageService', 'ConsumerModel', 'ServiceService', 'DialogService', 'SocketHelperService', 'PluginHelperService', 'KongPluginsService', '$uibModalInstance', 'PluginsService', '_pluginName', '_schema', '_context', function controller(_, $scope, $rootScope, $log, $state, ListConfig, ApiService, - MessageService, ConsumerModel, ServiceService, SocketHelperService, PluginHelperService, + MessageService, ConsumerModel, ServiceService, DialogService, SocketHelperService, PluginHelperService, KongPluginsService, $uibModalInstance, PluginsService, _pluginName, _schema,_context) { @@ -50,7 +50,7 @@ // Define the plugins that will have their own custom form // so that it can be included via ng-include in the .html files - $scope.customPluginForms = ['statsd']; + $scope.customPluginForms = ['statsd', 'response-ratelimiting']; $scope.humanizeLabel = function (key) { return key.split("_").join(" "); @@ -291,6 +291,29 @@ $scope.getFieldProp = (field) => { return Object.keys(field)[0]; } + + /** + * RESPONSE RATE LIMITING + */ + + $scope.addMap = (obj) => { + + DialogService.prompt('Add Limit', 'Enter key', (keyName) => { + if(!obj.value) { + obj.value = {} + } + + obj.value[keyName] = {}; + obj.values.fields.forEach(field => { + obj.value[keyName][Object.keys(field)[0]] = null + }) + }) + + } + + $scope.removeMap = (keyName, obj) => { + delete obj.value[keyName]; + } } ]); }()); diff --git a/assets/js/app/plugins/add-plugin-modal-controller.js b/assets/js/app/plugins/add-plugin-modal-controller.js index a6cdf43ec..fdef7e7da 100644 --- a/assets/js/app/plugins/add-plugin-modal-controller.js +++ b/assets/js/app/plugins/add-plugin-modal-controller.js @@ -30,7 +30,7 @@ // Define the plugins that will have their own custom form // so that it can be included via ng-include in the .html files - $scope.customPluginForms = ['statsd']; + $scope.customPluginForms = ['statsd', 'response-ratelimiting']; new KongPluginsService().makePluginGroups().then(function (groups) { $scope.pluginGroups = groups diff --git a/assets/js/app/plugins/api-plugins-controller.js b/assets/js/app/plugins/api-plugins-controller.js index c34474ae1..82e8a54ea 100644 --- a/assets/js/app/plugins/api-plugins-controller.js +++ b/assets/js/app/plugins/api-plugins-controller.js @@ -84,7 +84,7 @@ function deletePlugin(plugin) { - DialogService.prompt( + DialogService.confirm( "Delete Plugin","Really want to delete the plugin?", ['No don\'t','Yes! delete it'], function accept(){ diff --git a/assets/js/app/plugins/edit-plugin-controller.js b/assets/js/app/plugins/edit-plugin-controller.js index f7b695f9f..a6e0606eb 100644 --- a/assets/js/app/plugins/edit-plugin-controller.js +++ b/assets/js/app/plugins/edit-plugin-controller.js @@ -9,10 +9,10 @@ angular.module('frontend.plugins') .controller('EditPluginController', [ '_', '$scope', '$rootScope', '$log', 'ListConfig', - 'MessageService', 'ConsumerModel', 'SocketHelperService', 'PluginHelperService', + 'MessageService', 'ConsumerModel', 'SocketHelperService', 'PluginHelperService', 'DialogService', 'KongPluginsService', '$uibModalInstance', 'PluginsService', '_plugin', '_schema', function controller(_, $scope, $rootScope, $log, ListConfig, - MessageService, ConsumerModel, SocketHelperService, PluginHelperService, + MessageService, ConsumerModel, SocketHelperService, PluginHelperService, DialogService, KongPluginsService, $uibModalInstance, PluginsService, _plugin, _schema) { $scope.plugin = _plugin; @@ -38,7 +38,7 @@ // Define the plugins that will have their own custom form // so that it can be included via ng-include in the .html files - $scope.customPluginForms = ['statsd']; + $scope.customPluginForms = ['statsd', 'response-ratelimiting']; //$log.debug("Options", options) @@ -103,40 +103,40 @@ }); // Monkey patch for response-ratelimiting plugin - if (_plugin.name === 'response-ratelimiting') { - console.log("response-ratelimiting:limits =>", _plugin.config.limits); - - // Delete initial schema fields - delete $scope.data.fields.limits.schema.fields.day; - delete $scope.data.fields.limits.schema.fields.hour; - delete $scope.data.fields.limits.schema.fields.minute; - delete $scope.data.fields.limits.schema.fields.month; - delete $scope.data.fields.limits.schema.fields.second; - delete $scope.data.fields.limits.schema.fields.year; - - - if (_plugin.config.limits) { - Object.keys(_plugin.config.limits).forEach(function (key) { - - //console.log("_plugin.config.limits[key]",_plugin.config.limits[key]) - - var inner_fields = {}; - Object.keys(_plugin.config.limits[key]).forEach(function (k) { - inner_fields[k] = { - type: 'number', - default: _plugin.config.limits[key][k] - } - }); - - $scope.data.fields.limits.schema.fields[key] = { - - schema: { - fields: inner_fields - } - } - }) - } - } + // if (_plugin.name === 'response-ratelimiting') { + // console.log("response-ratelimiting:limits =>", _plugin.config.limits); + // + // // Delete initial schema fields + // delete $scope.data.fields.limits.schema.fields.day; + // delete $scope.data.fields.limits.schema.fields.hour; + // delete $scope.data.fields.limits.schema.fields.minute; + // delete $scope.data.fields.limits.schema.fields.month; + // delete $scope.data.fields.limits.schema.fields.second; + // delete $scope.data.fields.limits.schema.fields.year; + // + // + // if (_plugin.config.limits) { + // Object.keys(_plugin.config.limits).forEach(function (key) { + // + // //console.log("_plugin.config.limits[key]",_plugin.config.limits[key]) + // + // var inner_fields = {}; + // Object.keys(_plugin.config.limits[key]).forEach(function (k) { + // inner_fields[k] = { + // type: 'number', + // default: _plugin.config.limits[key][k] + // } + // }); + // + // $scope.data.fields.limits.schema.fields[key] = { + // + // schema: { + // fields: inner_fields + // } + // } + // }) + // } + // } // Customize data fields according to plugin PluginHelperService.customizeDataFieldsForPlugin(_plugin.name, $scope.data.fields); @@ -306,6 +306,30 @@ } }; + + /** + * RESPONSE RATE LIMITING + */ + + $scope.addMap = (obj) => { + + DialogService.prompt('Add Limit', 'Enter key', (keyName) => { + if(!obj.value) { + obj.value = {} + } + + obj.value[keyName] = {}; + obj.values.fields.forEach(field => { + obj.value[keyName][Object.keys(field)[0]] = null + }) + }) + + } + + $scope.removeMap = (keyName, obj) => { + delete obj.value[keyName]; + } + $scope.getFieldProp = (field) => { return Object.keys(field)[0]; } diff --git a/assets/js/app/plugins/forms/response-ratelimiting.html b/assets/js/app/plugins/forms/response-ratelimiting.html new file mode 100644 index 000000000..f0f1642a1 --- /dev/null +++ b/assets/js/app/plugins/forms/response-ratelimiting.html @@ -0,0 +1,270 @@ +
+
+ +
+ +

+ The CONSUMER ID that this plugin configuration will target. + This value can only be used if authentication has been enabled + so that the system can identify the user making the request. + If left blank, the plugin will be applied to all consumers. +

+
+
+ +
+ +
+
+ +
+
+
+ + +
+
+ + +
+ {{chip}} + +
+
+ +
+
+
+ +
+
+

{{data.help}}

+
+
+
+ + +
+ + +
+ +
+
+
+
+ {{mapKey}} +
+
+
+ +
+
+
+ +
+
+ + +
+
+ + +
+ {{chip}} + +
+
+ +
+
+
+ +
+
+

{{data.help}}

+
+
+
+
+ + + + + + + +
+ + +
+ +
+
+

+ {{cf_key}} + +

+
+
+
+ +
{{title}}
+
+
+ +
+
+ + + + +
+ +
+
+
+ +
+
+ + +
+ {{chip}} + +
+
+ +
+
+
+ +
+
+

{{data.help}}

+
+
+
+ + +
+ + +
+
+ +
+
+ + +
+
+ + +
+ +
+ + +
+ + +
+ {{chip}} + +
+
+ +
+

Tip: Press Enter to accept a value.

+
+ + +
+ + +
+ {{chip}} + +
+
+ +
+

Tip: Press Enter to accept a value.

+
+ + +
+ +
+ + +
+ + +
+ + +
+ +
+ + +
+ + +
+ +
+

{{value.help}}

+
+
+
+
+
+ +
+
+
+
+ +
+
+
diff --git a/assets/js/app/plugins/modals/add-plugin-modal.html b/assets/js/app/plugins/modals/add-plugin-modal.html index 2e14767cf..191a29e64 100644 --- a/assets/js/app/plugins/modals/add-plugin-modal.html +++ b/assets/js/app/plugins/modals/add-plugin-modal.html @@ -221,4 +221,4 @@