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

adding support for include directive in map #1149

Merged
merged 3 commits into from
Nov 18, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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.
# [*includes*] - 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':
#
# includes => [ '/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] $includes = [],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work if it's an empty array, since you're not checking if it's empty in the template? Will this create an empty includes line?
Maybe this should be Optional[Array[String]] $includes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there's a default value you can omit it ; it acts as an optional parameter.
So if you pass an empty Array it will be the same as passing nothing and use the default value: it won't iterate nothing into the loop in template so nothing will be written (no empty includes line).
I agree with you since it is finally an optional parameter that declaring it explicitly as Optional would be better (but in that case the test in the template will became mandatory).

Boolean $hostnames = false
) {
if ! defined(Class['nginx']) {
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 -%>
<%- @includes.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