From 6cbeafc9858d31eb4fa0f37b6188280af695344b Mon Sep 17 00:00:00 2001 From: Frank Wall Date: Tue, 25 Jul 2023 15:24:31 +0200 Subject: [PATCH] convert template to EPP, fix tests --- manifests/config.pp | 4 +++- spec/default_facts.yml | 4 ++++ templates/thumbor.conf.epp | 15 +++++++++++++++ templates/thumbor.conf.erb | 15 --------------- 4 files changed, 22 insertions(+), 16 deletions(-) create mode 100644 templates/thumbor.conf.epp delete mode 100644 templates/thumbor.conf.erb diff --git a/manifests/config.pp b/manifests/config.pp index 50d6d21..b91cad4 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -13,7 +13,9 @@ } -> file { "${thumbor::cfg_path}/thumbor.conf": ensure => $thumbor::ensure, - content => template('thumbor/thumbor.conf.erb'), + content => epp('thumbor/thumbor.conf.epp', { + _default_config => $_default_config, + }), owner => $thumbor::user, group => $thumbor::group, mode => '0644', diff --git a/spec/default_facts.yml b/spec/default_facts.yml index f777abf..6a7c52b 100644 --- a/spec/default_facts.yml +++ b/spec/default_facts.yml @@ -6,3 +6,7 @@ ipaddress: "172.16.254.254" ipaddress6: "FE80:0000:0000:0000:AAAA:AAAA:AAAA" is_pe: false macaddress: "AA:AA:AA:AA:AA:AA" + +# XXX: This is required for unit tests, because the +# pyvenv defined type requires a valid python version. +python3_version: '3.8.12' diff --git a/templates/thumbor.conf.epp b/templates/thumbor.conf.epp new file mode 100644 index 0000000..1f34801 --- /dev/null +++ b/templates/thumbor.conf.epp @@ -0,0 +1,15 @@ +<% $_default_config.keys.sort.each |$config_key| { -%> +<% if ($_default_config[$config_key] =~ Hash) { -%> +<%= $config_key.upcase -%> = [ +<% $_default_config[$config_key].flatten.each |$value| { -%> + '<%= $value -%>', +<% } -%> +] +<% } elsif ($_default_config[$config_key] =~ Boolean) { -%> +<%= $config_key.upcase %> = <%= $_default_config[$config_key].bool2str.capitalize %> +<% } elsif ($_default_config[$config_key] =~ Integer) { -%> +<%= $config_key.upcase %> = <%= $_default_config[$config_key] %> +<% } elsif ($_default_config[$config_key] =~ String) { -%> +<%= $config_key.upcase %> = '<%= $_default_config[$config_key] %>' +<% } -%> +<% } -%> diff --git a/templates/thumbor.conf.erb b/templates/thumbor.conf.erb deleted file mode 100644 index 3780871..0000000 --- a/templates/thumbor.conf.erb +++ /dev/null @@ -1,15 +0,0 @@ -<% @_default_config.keys.sort.each do |config_key| -%> -<% if @_default_config[config_key].respond_to?(:each) -%> -<%= config_key.upcase -%> = [ -<% @_default_config[config_key].flatten.each do |value| -%> - '<%= value -%>', -<% end -%> -] -<% elsif (@_default_config[config_key].is_a?(TrueClass) || @_default_config[config_key].is_a?(FalseClass)) -%> -<%= config_key.upcase -%> = <%= @_default_config[config_key].to_s.capitalize %> -<% elsif @_default_config[config_key].is_a?(Fixnum) -%> -<%= config_key.upcase -%> = <%= @_default_config[config_key] %> -<% elsif @_default_config[config_key].respond_to?(:to_s) -%> -<%= config_key.upcase -%> = '<%= @_default_config[config_key] %>' -<% end -%> -<% end -%>