Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b27e457

Browse files
committedDec 18, 2024·
Add support for allow and deny directive on streamhost
1 parent 071c48d commit b27e457

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed
 

‎manifests/resource/streamhost.pp

+6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
# nginx::resource::streamhost { 'test2.local':
4848
# ensure => present,
4949
# }
50+
# @param allow
51+
# Locations to allow connections from
52+
# @param deny
53+
# Locations to deny connections from
5054
#
5155
define nginx::resource::streamhost (
5256
Enum['absent', 'present'] $ensure = 'present',
@@ -66,6 +70,8 @@
6670
String $owner = $nginx::global_owner,
6771
String $group = $nginx::global_group,
6872
String $mode = $nginx::global_mode,
73+
Array $allow = [],
74+
Array $deny = [],
6975
) {
7076
if ! defined(Class['nginx']) {
7177
fail('You must include the nginx base class before using any defined resources')

‎spec/defines/resource_stream_spec.rb

+12
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@
112112
value: ['203.0.113.1', '203.0.113.2'],
113113
match: %r{\s+resolver\s+203.0.113.1 203.0.113.2;}
114114
},
115+
{
116+
title: 'should set allow(s)',
117+
attr: 'allow',
118+
value: ['203.0.113.1', '203.0.113.2'],
119+
match: %r{\s+allow\s+203.0.113.1;}
120+
},
121+
{
122+
title: 'should set deny(s)',
123+
attr: 'deny',
124+
value: ['203.0.113.1', '203.0.113.2'],
125+
match: %r{\s+deny\s+203.0.113.1;}
126+
},
115127
{
116128
title: 'should contain raw_prepend directives',
117129
attr: 'raw_prepend',

‎templates/streamhost/streamhost.erb

+17-6
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,26 @@ server {
2222
resolver <% @resolver.each do |res| %> <%= res %><% end %>;
2323
<%- end -%>
2424

25-
<% Array(@raw_prepend).each do |line| -%>
26-
<%= line %>
27-
<% end %>
25+
<% if @allow -%>
26+
<%- @allow.flatten.uniq.each do |allow_rule| -%>
27+
allow <%= allow_rule %>;
28+
<%- end -%>
29+
<% end -%>
30+
<% if @deny -%>
31+
<%- @deny.uniq.each do |deny_rule| -%>
32+
deny <%= deny_rule %>;
33+
<%- end -%>
34+
<% end -%>
35+
36+
<% Array(@raw_prepend).each do |line| -%>
37+
<%= line %>
38+
<% end %>
2839

2940
proxy_timeout <%= @proxy_read_timeout %>;
3041
proxy_connect_timeout <%= @proxy_connect_timeout %>;
3142
proxy_pass <%= @proxy %>;
3243

33-
<% Array(@raw_append).each do |line| -%>
34-
<%= line %>
35-
<% end -%>
44+
<% Array(@raw_append).each do |line| -%>
45+
<%= line %>
46+
<% end -%>
3647
}

0 commit comments

Comments
 (0)
Please sign in to comment.