From c525a334c89e1859353d3aac6b04e76c97b2b819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eirik=20=C3=98verby?= Date: Tue, 18 Jul 2023 15:57:43 +0200 Subject: [PATCH 1/2] Add support for multiple limit_req statements in locations --- REFERENCE.md | 7 ++++--- manifests/resource/location.pp | 7 ++++--- spec/defines/resource_location_spec.rb | 9 +++++++++ templates/server/location_header.erb | 4 +++- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/REFERENCE.md b/REFERENCE.md index 630e0c278..0a87f517c 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -2281,10 +2281,11 @@ Default value: `undef` ##### `limit_zone` -Data type: `Optional[String[1]]` +Data type: `Optional[Variant[String[1],Array[String[1],1]]]` -Apply a limit_req_zone to the location. Expects a string indicating a -previously defined limit_req_zone in the main nginx configuration +Apply a limit_req_zone to the location. Expects a string or array of +strings indicating a previously defined limit_req_zone in the main nginx +configuration Default value: `undef` diff --git a/manifests/resource/location.pp b/manifests/resource/location.pp index c35c0cce5..f55e0893f 100644 --- a/manifests/resource/location.pp +++ b/manifests/resource/location.pp @@ -92,8 +92,9 @@ # (after custom_cfg directives). NOTE: YOU are responsible for a semicolon on # each line that requires one. # @param limit_zone -# Apply a limit_req_zone to the location. Expects a string indicating a -# previously defined limit_req_zone in the main nginx configuration +# Apply a limit_req_zone to the location. Expects a string or array of +# strings indicating a previously defined limit_req_zone in the main nginx +# configuration # @param location_custom_cfg # Expects a hash with custom directives, cannot be used with other location # types (proxy, fastcgi, root, or stub_status) @@ -270,7 +271,7 @@ Boolean $ssl = false, Boolean $ssl_only = false, Optional[String] $location_alias = undef, - Optional[String[1]] $limit_zone = undef, + Optional[Variant[String[1],Array[String[1],1]]] $limit_zone = undef, Optional[Enum['any', 'all']] $location_satisfy = undef, Optional[Array] $location_allow = undef, Optional[Array] $location_deny = undef, diff --git a/spec/defines/resource_location_spec.rb b/spec/defines/resource_location_spec.rb index 75cad664d..1aa7e76ed 100644 --- a/spec/defines/resource_location_spec.rb +++ b/spec/defines/resource_location_spec.rb @@ -109,6 +109,15 @@ value: 'myzone1', match: ' limit_req zone=myzone1;' }, + { + title: 'should set multiple limit_zone', + attr: 'limit_zone', + value: %w[myzone1 myzone2], + match: [ + ' limit_req zone=myzone1;', + ' limit_req zone=myzone1;' + ] + }, { title: 'should set expires', attr: 'expires', diff --git a/templates/server/location_header.erb b/templates/server/location_header.erb index e88e1b92c..25c16fc36 100644 --- a/templates/server/location_header.erb +++ b/templates/server/location_header.erb @@ -78,7 +78,9 @@ <%- end -%> <% end -%> <% if @limit_zone -%> - limit_req zone=<%= @limit_zone %>; + <%- Array(@limit_zone).each do |lz| -%> + limit_req zone=<%= lz %>; + <%- end -%> <% end -%> <% if @reset_timedout_connection -%> reset_timedout_connection <%= @reset_timedout_connection %>; From 25749eeeca6c84120a504c8b21728e99269b57f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eirik=20=C3=98verby?= Date: Mon, 6 Nov 2023 23:56:59 +0100 Subject: [PATCH 2/2] Update spec/defines/resource_location_spec.rb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Romain Tartière --- spec/defines/resource_location_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/defines/resource_location_spec.rb b/spec/defines/resource_location_spec.rb index 1aa7e76ed..f52021395 100644 --- a/spec/defines/resource_location_spec.rb +++ b/spec/defines/resource_location_spec.rb @@ -115,7 +115,7 @@ value: %w[myzone1 myzone2], match: [ ' limit_req zone=myzone1;', - ' limit_req zone=myzone1;' + ' limit_req zone=myzone2;' ] }, {