Skip to content

Commit

Permalink
adding support for include directive in map (voxpupuli#1149)
Browse files Browse the repository at this point in the history
* adding support for include directive in map

* change param name includes to include_files to keep naming consistent with the other manifests
adding test to ensure empty value , single and multiple inclusions works correctly

* fix rubocop offenses
  • Loading branch information
ceonizm authored and wyardley committed Nov 18, 2017
1 parent ad3d00a commit 2ea5aac
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
10 changes: 10 additions & 0 deletions manifests/resource/map.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# [*mappings*] - Hash of map lookup keys and resultant values
# [*hostnames*] - Indicates that source values can be hostnames with a
# prefix or suffix mask.
# [*include_files*] - An array of external files to include
#
# Actions:
#
Expand Down Expand Up @@ -38,6 +39,14 @@
# ]
# }
#
# Sample Usage (using external include)
#
# nginx::resource::map { 'redirections':
#
# include_files => [ '/etc/nginx/conf.d/redirections.map']
#
# }
#
# Sample Hiera usage:
#
# nginx::string_mappings:
Expand Down Expand Up @@ -67,6 +76,7 @@
Variant[Array, Hash] $mappings,
Optional[String] $default = undef,
Enum['absent', 'present'] $ensure = 'present',
Array[String] $include_files = [],
Boolean $hostnames = false
) {
if ! defined(Class['nginx']) {
Expand Down
26 changes: 26 additions & 0 deletions spec/defines/resource_map_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,32 @@
value: true,
match: ' hostnames;'
},
{
title: 'should not contain includes',
attr: 'include_files',
value: [],
notmatch: ' include ;'
},
{
title: 'should contain includes',
attr: 'include_files',
value: ['/etc/includes/includes.map'],
match: ' include /etc/includes/includes.map;'
},
{
title: 'should contain multiple includes',
attr: 'include_files',
value: [
'/etc/includes/A.map',
'/etc/includes/B.map',
'/etc/includes/C.map'
],
match: [
' include /etc/includes/A.map;',
' include /etc/includes/B.map;',
' include /etc/includes/C.map;'
]
},
{
title: 'should set default',
attr: 'default',
Expand Down
3 changes: 3 additions & 0 deletions templates/conf.d/map.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ map <%= @string %> $<%= @name %> {
<% if @default -%>
default <%= @default %>;
<% end -%>
<%- @include_files.each do |h| -%>
include <%= h %>;
<%- end -%>

<% if @mappings.is_a?(Hash) -%>
<%- field_width = @mappings.inject(0) { |l,(k,v)| k.size > l ? k.size : l } -%>
Expand Down

0 comments on commit 2ea5aac

Please sign in to comment.