Skip to content

Commit 5f351b3

Browse files
committed
Use EPP for plugin templates
You can hand EPP a context and it can validate data types. This gives a higher certainty that a template is rendered correctly. It is also able to deal with Sensitive data types natively.
1 parent aebbec7 commit 5f351b3

30 files changed

+73
-46
lines changed

manifests/module.pp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@
1919
# @param template_path
2020
# An optional template path
2121
#
22+
# @param config_context
23+
# Context to pass to the template
24+
#
2225
define foreman_proxy::module (
2326
Boolean $enabled = false,
2427
Foreman_proxy::ListenOn $listen_on = 'https',
2528
Optional[String] $template_path = undef,
29+
Hash[String, Any] $config_context = {},
2630
String $feature = upcase($title),
2731
) {
2832
if $enabled {
@@ -39,7 +43,7 @@
3943
}
4044

4145
foreman_proxy::settings_file { $name:
42-
module_enabled => $module_enabled,
4346
template_path => $template_path,
47+
config_context => $config_context + {'module_enabled' => $module_enabled},
4448
}
4549
}

manifests/plugin/abrt.pp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,22 @@
4343
Optional[Stdlib::Absolutepath] $faf_server_ssl_cert = undef,
4444
Optional[Stdlib::Absolutepath] $faf_server_ssl_key = undef,
4545
) {
46+
$context = {
47+
abrt_send_log_file => $abrt_send_log_file,
48+
abrt_send_log_file => $abrt_send_log_file,
49+
spooldir => $spooldir,
50+
aggregate_reports => $aggregate_reports,
51+
send_period => $send_period,
52+
faf_server_url => $faf_server_url,
53+
faf_server_ssl_noverify => $faf_server_ssl_noverify,
54+
faf_server_ssl_cert => $faf_server_ssl_cert,
55+
faf_server_ssl_key => $faf_server_ssl_key,
56+
}
57+
4658
foreman_proxy::plugin::module { 'abrt':
47-
version => $version,
48-
listen_on => $listen_on,
49-
enabled => $enabled,
59+
version => $version,
60+
listen_on => $listen_on,
61+
enabled => $enabled,
62+
config_context => $context,
5063
}
5164
}

manifests/plugin/module.pp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,27 @@
2222
# @param template_path
2323
# An optional template path
2424
#
25+
# @param config_context
26+
# Context to pass to the template
27+
#
2528
define foreman_proxy::plugin::module (
2629
Optional[String] $version = undef,
2730
Optional[String] $package = undef,
2831
Boolean $enabled = false,
2932
Optional[Foreman_proxy::ListenOn] $listen_on = undef,
30-
String $template_path = "foreman_proxy/plugin/${title}.yml.erb",
33+
String $template_path = "foreman_proxy/plugin/${title}.yml.epp",
3134
String $feature = $title.capitalize(),
35+
Hash[String, Any] $config_context = {},
3236
) {
3337
foreman_proxy::plugin { $title:
3438
version => $version,
3539
package => $package,
3640
}
3741
-> foreman_proxy::module { $name:
38-
enabled => $enabled,
39-
feature => $feature,
40-
listen_on => $listen_on,
41-
template_path => $template_path,
42+
enabled => $enabled,
43+
feature => $feature,
44+
listen_on => $listen_on,
45+
template_path => $template_path,
46+
config_context => $config_context,
4247
}
4348
}

manifests/settings_file.pp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
# @param ensure
44
# Whether the config file should be a file or absent
55
#
6-
# @param module_enabled
7-
# If module is enabled or not. Only relevant when it's a module.
8-
#
96
# @param path
107
# Path to module's settings file
118
#
@@ -23,18 +20,18 @@
2320
#
2421
define foreman_proxy::settings_file (
2522
Enum['file', 'absent'] $ensure = 'file',
26-
String $module_enabled = 'false',
2723
Stdlib::Absolutepath $path = "${foreman_proxy::params::config_dir}/settings.d/${title}.yml",
2824
String $owner = 'root',
2925
String $group = $foreman_proxy::params::user,
3026
Stdlib::Filemode $mode = '0640',
3127
String $template_path = "foreman_proxy/${title}.yml.erb",
28+
Hash[String, Any] $config_context = {},
3229
) {
3330
if $ensure == 'absent' {
3431
$content = undef
3532
} else {
3633
$content = if $template_path.match(/\.epp$/) {
37-
epp($template_path)
34+
epp($template_path, $config_context)
3835
} elsif $template_path.match(/\.erb$/) {
3936
template($template_path)
4037
} else {

templates/plugin/abrt.yml.epp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<%- |
2+
String $module_enabled,
3+
Stdlib::Absolutepath $abrt_send_log_file,
4+
Stdlib::Absolutepath $spooldir,
5+
Boolean $aggregate_reports,
6+
Integer[0] $send_period = 600,
7+
Optional[String] $faf_server_url = undef,
8+
Boolean $faf_server_ssl_noverify = true,
9+
Optional[Stdlib::Absolutepath] $faf_server_ssl_cert = undef,
10+
Optional[Stdlib::Absolutepath] $faf_server_ssl_key = undef,
11+
| -%>
12+
---
13+
:enabled: <%= $module_enabled %>
14+
# Log file for the forwarding script.
15+
:abrt_send_log_file: <%= $abrt_send_log_file %>
16+
# Directory where uReports are stored before they are sent
17+
:spooldir: <%= $spooldir %>
18+
# Merge duplicate reports before sending (requires the satyr gem)
19+
:aggregate_reports: <%= $aggregate_reports %>
20+
# Period (in seconds) after which collected reports are forwarded. Meaningful
21+
# only if smart-proxy-abrt-send is run as a daemon (not from cron).
22+
:send_period: <%= $send_period %>
23+
# FAF server instance the reports will be forwarded to (optional)
24+
<% if $faf_server_url { -%>
25+
:server_url: <%= $faf_server_url %>
26+
# Set to true if FAF server uses self-signed certificate
27+
:server_ssl_noverify: <%= $faf_server_ssl_noverify %>
28+
<% } else { %>
29+
#:server_url:
30+
# Set to true if FAF server uses self-signed certificate
31+
#:server_ssl_noverify:
32+
<% } %>
33+
# Following two options enable client authentication to FAF server
34+
<% if $faf_server_ssl_cert and $faf_server_ssl_key { -%>
35+
:server_ssl_cert: <%= $faf_server_ssl_cert %>
36+
:server_ssl_key: <%= $faf_server_ssl_key %>
37+
<% } else { %>
38+
#:server_ssl_cert:
39+
#:server_ssl_key:
40+
<% } %>

templates/plugin/abrt.yml.erb

Lines changed: 0 additions & 32 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)