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

Use EPP template in nginx::resource::map #1575

Merged
merged 1 commit into from
Sep 29, 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
14 changes: 13 additions & 1 deletion REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
* [`Nginx::GzipProxied`](#Nginx--GzipProxied): custom type for gzip_proxied
* [`Nginx::LogFormat`](#Nginx--LogFormat)
* [`Nginx::Size`](#Nginx--Size)
* [`Nginx::StringMappings`](#Nginx--StringMappings): custom type for the `map` variable mapping
* [`Nginx::Time`](#Nginx--Time)
* [`Nginx::UpstreamCustomParameters`](#Nginx--UpstreamCustomParameters)
* [`Nginx::UpstreamDefaults`](#Nginx--UpstreamDefaults)
Expand Down Expand Up @@ -3170,10 +3171,12 @@ Source string or variable to provide mapping for

##### <a name="-nginx--resource--map--mappings"></a>`mappings`

Data type: `Variant[Array, Hash]`
Data type: `Nginx::StringMappings`

Hash of map lookup keys and resultant values

Default value: `[]`

##### <a name="-nginx--resource--map--hostnames"></a>`hostnames`

Data type: `Boolean`
Expand Down Expand Up @@ -5189,6 +5192,15 @@ The Nginx::Size data type.

Alias of `Variant[Integer[0], Pattern[/\A\d+[k|K|m|M]?\z/]]`

### <a name="Nginx--StringMappings"></a>`Nginx::StringMappings`

custom type for the `map` variable mapping

* **See also**
* http://nginx.org/en/docs/http/ngx_http_map_module.html

Alias of `Variant[Array[Struct[{ 'key' => String[1], 'value' => String }]], Hash[String[1], String]]`

### <a name="Nginx--Time"></a>`Nginx::Time`

The Nginx::Time data type.
Expand Down
11 changes: 9 additions & 2 deletions manifests/resource/map.pp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
#
define nginx::resource::map (
String[2] $string,
Variant[Array, Hash] $mappings,
Nginx::StringMappings $mappings = [],
Optional[String] $default = undef,
Enum['absent', 'present'] $ensure = 'present',
Array[String] $include_files = [],
Expand Down Expand Up @@ -93,7 +93,14 @@
owner => 'root',
group => $root_group,
mode => $nginx::global_mode,
content => template('nginx/conf.d/map.erb'),
content => epp('nginx/conf.d/map.epp', {
'default' => $default,
'hostnames' => $hostnames,
'include_files' => $include_files,
'mappings' => $mappings,
'name' => $name,
'string' => $string,
}),
notify => Class['nginx::service'],
tag => 'nginx_config_file',
}
Expand Down
31 changes: 31 additions & 0 deletions templates/conf.d/map.epp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<%- |
Optional[String] $default = undef,
Boolean $hostnames,
Array[String] $include_files,
Nginx::StringMappings $mappings,
String $name,
String[2] $string,
| -%>
# MANAGED BY PUPPET
map <%= $string %> $<%= $name %> {
<% if $hostnames { -%>
hostnames;
<% } -%>
<% if $default { -%>
default <%= $default %>;
<% } -%>
<%- $include_files.each |$h| { -%>
include <%= $h %>;
<%- } -%>

<%-
$m = $mappings ? {
Hash => $mappings.keys.sort.map |$k| { { key => $k, value => $mappings[$k] } },
default => $mappings,
}
$field_width = $m.map |$x| { $x['key'].length }.max
-%>
<%- $m.each |$h| { -%>
<%= sprintf("%-*s %s", $field_width, $h['key'], $h['value']) %>;
<%- } -%>
}
25 changes: 0 additions & 25 deletions templates/conf.d/map.erb

This file was deleted.

6 changes: 6 additions & 0 deletions types/stringmappings.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# @summary custom type for the `map` variable mapping
# @see http://nginx.org/en/docs/http/ngx_http_map_module.html
type Nginx::StringMappings = Variant[
jay7x marked this conversation as resolved.
Show resolved Hide resolved
Array[Struct[{ 'key' => String[1], 'value' => String }]],
Hash[String[1], String]
]
Loading