Skip to content

Commit

Permalink
Use EPP for plugin templates
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ekohl committed Feb 11, 2022
1 parent aebbec7 commit 5f351b3
Show file tree
Hide file tree
Showing 30 changed files with 73 additions and 46 deletions.
6 changes: 5 additions & 1 deletion manifests/module.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@
# @param template_path
# An optional template path
#
# @param config_context
# Context to pass to the template
#
define foreman_proxy::module (
Boolean $enabled = false,
Foreman_proxy::ListenOn $listen_on = 'https',
Optional[String] $template_path = undef,
Hash[String, Any] $config_context = {},
String $feature = upcase($title),
) {
if $enabled {
Expand All @@ -39,7 +43,7 @@
}

foreman_proxy::settings_file { $name:
module_enabled => $module_enabled,
template_path => $template_path,
config_context => $config_context + {'module_enabled' => $module_enabled},
}
}
19 changes: 16 additions & 3 deletions manifests/plugin/abrt.pp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,22 @@
Optional[Stdlib::Absolutepath] $faf_server_ssl_cert = undef,
Optional[Stdlib::Absolutepath] $faf_server_ssl_key = undef,
) {
$context = {
abrt_send_log_file => $abrt_send_log_file,
abrt_send_log_file => $abrt_send_log_file,
spooldir => $spooldir,
aggregate_reports => $aggregate_reports,
send_period => $send_period,
faf_server_url => $faf_server_url,
faf_server_ssl_noverify => $faf_server_ssl_noverify,
faf_server_ssl_cert => $faf_server_ssl_cert,
faf_server_ssl_key => $faf_server_ssl_key,
}

foreman_proxy::plugin::module { 'abrt':
version => $version,
listen_on => $listen_on,
enabled => $enabled,
version => $version,
listen_on => $listen_on,
enabled => $enabled,
config_context => $context,
}
}
15 changes: 10 additions & 5 deletions manifests/plugin/module.pp
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,27 @@
# @param template_path
# An optional template path
#
# @param config_context
# Context to pass to the template
#
define foreman_proxy::plugin::module (
Optional[String] $version = undef,
Optional[String] $package = undef,
Boolean $enabled = false,
Optional[Foreman_proxy::ListenOn] $listen_on = undef,
String $template_path = "foreman_proxy/plugin/${title}.yml.erb",
String $template_path = "foreman_proxy/plugin/${title}.yml.epp",
String $feature = $title.capitalize(),
Hash[String, Any] $config_context = {},
) {
foreman_proxy::plugin { $title:
version => $version,
package => $package,
}
-> foreman_proxy::module { $name:
enabled => $enabled,
feature => $feature,
listen_on => $listen_on,
template_path => $template_path,
enabled => $enabled,
feature => $feature,
listen_on => $listen_on,
template_path => $template_path,
config_context => $config_context,
}
}
7 changes: 2 additions & 5 deletions manifests/settings_file.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
# @param ensure
# Whether the config file should be a file or absent
#
# @param module_enabled
# If module is enabled or not. Only relevant when it's a module.
#
# @param path
# Path to module's settings file
#
Expand All @@ -23,18 +20,18 @@
#
define foreman_proxy::settings_file (
Enum['file', 'absent'] $ensure = 'file',
String $module_enabled = 'false',
Stdlib::Absolutepath $path = "${foreman_proxy::params::config_dir}/settings.d/${title}.yml",
String $owner = 'root',
String $group = $foreman_proxy::params::user,
Stdlib::Filemode $mode = '0640',
String $template_path = "foreman_proxy/${title}.yml.erb",
Hash[String, Any] $config_context = {},
) {
if $ensure == 'absent' {
$content = undef
} else {
$content = if $template_path.match(/\.epp$/) {
epp($template_path)
epp($template_path, $config_context)
} elsif $template_path.match(/\.erb$/) {
template($template_path)
} else {
Expand Down
40 changes: 40 additions & 0 deletions templates/plugin/abrt.yml.epp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<%- |
String $module_enabled,
Stdlib::Absolutepath $abrt_send_log_file,
Stdlib::Absolutepath $spooldir,
Boolean $aggregate_reports,
Integer[0] $send_period = 600,
Optional[String] $faf_server_url = undef,
Boolean $faf_server_ssl_noverify = true,
Optional[Stdlib::Absolutepath] $faf_server_ssl_cert = undef,
Optional[Stdlib::Absolutepath] $faf_server_ssl_key = undef,
| -%>
---
:enabled: <%= $module_enabled %>
# Log file for the forwarding script.
:abrt_send_log_file: <%= $abrt_send_log_file %>
# Directory where uReports are stored before they are sent
:spooldir: <%= $spooldir %>
# Merge duplicate reports before sending (requires the satyr gem)
:aggregate_reports: <%= $aggregate_reports %>
# Period (in seconds) after which collected reports are forwarded. Meaningful
# only if smart-proxy-abrt-send is run as a daemon (not from cron).
:send_period: <%= $send_period %>
# FAF server instance the reports will be forwarded to (optional)
<% if $faf_server_url { -%>
:server_url: <%= $faf_server_url %>
# Set to true if FAF server uses self-signed certificate
:server_ssl_noverify: <%= $faf_server_ssl_noverify %>
<% } else { %>
#:server_url:
# Set to true if FAF server uses self-signed certificate
#:server_ssl_noverify:
<% } %>
# Following two options enable client authentication to FAF server
<% if $faf_server_ssl_cert and $faf_server_ssl_key { -%>
:server_ssl_cert: <%= $faf_server_ssl_cert %>
:server_ssl_key: <%= $faf_server_ssl_key %>
<% } else { %>
#:server_ssl_cert:
#:server_ssl_key:
<% } %>
32 changes: 0 additions & 32 deletions templates/plugin/abrt.yml.erb

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 5f351b3

Please sign in to comment.