Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for multiple limit_req statements in location directives #1570

Merged
merged 2 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2281,10 +2281,11 @@ Default value: `undef`

##### <a name="-nginx--resource--location--limit_zone"></a>`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`

Expand Down
7 changes: 4 additions & 3 deletions manifests/resource/location.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions spec/defines/resource_location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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=myzone2;'
]
},
{
title: 'should set expires',
attr: 'expires',
Expand Down
4 changes: 3 additions & 1 deletion templates/server/location_header.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>;
Expand Down
Loading