Skip to content

Commit

Permalink
Merge pull request #2449 from puppetlabs/CAT-1348_erb_to_epp_conversi…
Browse files Browse the repository at this point in the history
…on_except_in_mod_vhost_directory

(CAT-1348)-Conversion of erb to epp templates except mod or vhost dir…
  • Loading branch information
Ramesh7 committed Sep 7, 2023
2 parents e22e3c6 + 3339242 commit 99b4488
Show file tree
Hide file tree
Showing 17 changed files with 254 additions and 172 deletions.
2 changes: 1 addition & 1 deletion manifests/confd/no_accf.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
file { 'no-accf.conf':
ensure => 'file',
path => "${apache::confd_dir}/no-accf.conf",
content => template('apache/confd/no-accf.conf.erb'),
content => epp('apache/confd/no-accf.conf.epp'),
require => Exec["mkdir ${apache::confd_dir}"],
before => File[$apache::confd_dir],
}
Expand Down
13 changes: 12 additions & 1 deletion manifests/fastcgi/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,24 @@
$socket = $host
}

$parameters = {
'timeout' => $timeout,
'flush' => $flush,
'socket' => $socket,
'host' => $host,
'pass_header' => $pass_header,
'faux_path' => $faux_path,
'fcgi_alias' => $fcgi_alias,
'file_type' => $file_type,
}

file { "fastcgi-pool-${name}.conf":
ensure => file,
path => "${apache::confd_dir}/fastcgi-pool-${name}.conf",
owner => 'root',
group => $apache::params::root_group,
mode => $apache::file_mode,
content => template('apache/fastcgi/server.erb'),
content => epp('apache/fastcgi/server.epp', $parameters),
require => Exec["mkdir ${apache::confd_dir}"],
before => File[$apache::confd_dir],
notify => Class['apache::service'],
Expand Down
51 changes: 49 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@
}
concat::fragment { 'Apache ports header':
target => $ports_file,
content => template('apache/ports_header.erb'),
content => epp('apache/ports_header.epp'),
}

if $apache::conf_dir and $apache::params::conf_file {
Expand Down Expand Up @@ -782,10 +782,57 @@
# - $server_signature
# - $trace_enable
# - $root_directory_secured
$parameters = {
'server_tokens' => $server_tokens,
'server_signature' => $server_signature,
'trace_enable' => $trace_enable,
'servername' => $servername,
'server_root' => $server_root,
'serveradmin' => $serveradmin,
'pidfile' => $pidfile,
'timeout' => $timeout,
'keepalive' => $keepalive,
'max_keepalive_requests' => $max_keepalive_requests,
'keepalive_timeout' => $keepalive_timeout,
'limitreqfieldsize' => $limitreqfieldsize,
'limitreqfields' => $limitreqfields,
'limitreqline' => $limitreqline,
'http_protocol_options' => $http_protocol_options,
'protocols' => $protocols,
'protocols_honor_order' => $protocols_honor_order,
'user' => $user,
'group' => $group,
'root_directory_options' => $root_directory_options,
'root_directory_secured' => $root_directory_secured,
'default_charset' => $default_charset,
'hostname_lookups' => $hostname_lookups,
'error_log' => $error_log,
'logroot' => $logroot,
'log_level' => $log_level,
'sendfile' => $sendfile,
'allow_encoded_slashes' => $allow_encoded_slashes,
'file_e_tag' => $file_e_tag,
'use_canonical_name' => $use_canonical_name,
'apxs_workaround' => $apxs_workaround,
'mod_load_dir' => $mod_load_dir,
'confd_dir' => $confd_dir,
'vhost_load_dir' => $vhost_load_dir,
'vhost_include_pattern' => $vhost_include_pattern,
'ports_file' => $ports_file,
'log_formats' => $log_formats,
'conf_enabled' => $conf_enabled,
'ldap_verify_server_cert' => $ldap_verify_server_cert,
'ldap_trusted_mode' => $ldap_trusted_mode,
'error_documents' => $error_documents,
'error_documents_path' => $error_documents_path,
}

notice $conf_template

file { "${apache::conf_dir}/${apache::params::conf_file}":
ensure => file,
mode => $apache::file_mode,
content => template($conf_template),
content => epp($conf_template, $parameters),
notify => Class['Apache::Service'],
require => [Package['httpd'], Concat[$ports_file]],
}
Expand Down
2 changes: 1 addition & 1 deletion manifests/listen.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
# Template uses: $listen_addr_port
concat::fragment { "Listen ${listen_addr_port}":
target => $apache::ports_file,
content => template('apache/listen.erb'),
content => epp('apache/listen.epp', { 'listen_addr_port' => $listen_addr_port }),
}
}
2 changes: 1 addition & 1 deletion manifests/namevirtualhost.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
# Template uses: $addr_port
concat::fragment { "NameVirtualHost ${addr_port}":
target => $apache::ports_file,
content => template('apache/namevirtualhost.erb'),
content => epp('apache/namevirtualhost.epp', { 'addr_port' => $addr_port }),
}
}
12 changes: 6 additions & 6 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
$mod_libs = {
'nss' => 'libmodnss.so',
}
$conf_template = 'apache/httpd.conf.erb'
$conf_template = 'apache/httpd.conf.epp'
$http_protocol_options = undef
$keepalive = 'On'
$keepalive_timeout = 15
Expand Down Expand Up @@ -231,7 +231,7 @@
default => 'mod_wsgi_python3.so',
},
}
$conf_template = 'apache/httpd.conf.erb'
$conf_template = 'apache/httpd.conf.epp'
$http_protocol_options = undef
$keepalive = 'On'
$keepalive_timeout = 15
Expand Down Expand Up @@ -383,7 +383,7 @@
$mod_libs = {
'shib2' => $shib2_lib,
}
$conf_template = 'apache/httpd.conf.erb'
$conf_template = 'apache/httpd.conf.epp'
$http_protocol_options = undef
$keepalive = 'On'
$keepalive_timeout = 15
Expand Down Expand Up @@ -492,7 +492,7 @@
}
$mod_libs = {
}
$conf_template = 'apache/httpd.conf.erb'
$conf_template = 'apache/httpd.conf.epp'
$http_protocol_options = undef
$keepalive = 'On'
$keepalive_timeout = 15
Expand Down Expand Up @@ -558,7 +558,7 @@
}
$mod_libs = {
}
$conf_template = 'apache/httpd.conf.erb'
$conf_template = 'apache/httpd.conf.epp'
$http_protocol_options = undef
$keepalive = 'On'
$keepalive_timeout = 15
Expand Down Expand Up @@ -633,7 +633,7 @@
'security' => '/usr/lib64/apache2/mod_security2.so',
'php53' => '/usr/lib64/apache2/mod_php5.so',
}
$conf_template = 'apache/httpd.conf.erb'
$conf_template = 'apache/httpd.conf.epp'
$http_protocol_options = undef
$keepalive = 'On'
$keepalive_timeout = 15
Expand Down
2 changes: 1 addition & 1 deletion readmes/README_ja_JP.md
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ Apacheサーバのメイン設定ファイルを置くディレクトリを設

メインのApache設定ファイルで使用される[テンプレート][]を定義します。apacheモジュールは、`conf.d`エントリによりカスタマイズされた最小限の設定ファイルを使用するように設計されているため、このパラメータの変更には潜在的なリスクが伴います。

デフォルト値: `apache/httpd.conf.erb`
デフォルト値: `apache/httpd.conf.epp`

##### `confd_dir`

Expand Down
8 changes: 4 additions & 4 deletions spec/acceptance/apache_parameters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
end

if os[:family] == 'freebsd'
describe file("#{apache_hash['confd_dir']}/no-accf.conf.erb") do
describe file("#{apache_hash['confd_dir']}/no-accf.conf.epp") do
it { is_expected.not_to be_file }
end
end
Expand All @@ -24,7 +24,7 @@
end

if os[:family] == 'freebsd'
describe file("#{apache_hash['confd_dir']}/no-accf.conf.erb") do
describe file("#{apache_hash['confd_dir']}/no-accf.conf.epp") do
it { is_expected.to be_file }
end
end
Expand Down Expand Up @@ -310,9 +310,9 @@ class { 'apache': httpd_dir => '/tmp', service_ensure => stopped }
describe 'conf_template' do
describe 'setup' do
it 'applies cleanly' do
pp = "class { 'apache': conf_template => 'another/test.conf.erb', service_ensure => stopped }"
pp = "class { 'apache': conf_template => 'another/test.conf.epp', service_ensure => stopped }"
run_shell('mkdir -p /etc/puppetlabs/code/environments/production/modules/another/templates')
run_shell("echo 'testcontent' >> /etc/puppetlabs/code/environments/production/modules/another/templates/test.conf.erb")
run_shell("echo 'testcontent' >> /etc/puppetlabs/code/environments/production/modules/another/templates/test.conf.epp")
apply_manifest(pp, catch_failures: true)
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/classes/apache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -433,15 +433,15 @@

describe 'different templates for httpd.conf with default' do
let :params do
{ conf_template: 'apache/httpd.conf.erb' }
{ conf_template: 'apache/httpd.conf.epp' }
end

it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^# Security\n} }
end

describe 'different templates for httpd.conf with non-default' do
let :params do
{ conf_template: 'site_apache/fake.conf.erb' }
{ conf_template: 'site_apache/fake.conf.epp' }
end

it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^Fake template for rspec.$} }
Expand Down
File renamed without changes.
24 changes: 24 additions & 0 deletions templates/fastcgi/server.epp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<%
$timeout_updated = " -idle-timeout #{$timeout}"

if $flush {
$flush_updated = " -flush"
} else {
$flush_updated = ""
}
if $socket {
$host_or_socket = " -socket #{$socket}"
} else {
$host_or_socket = " -host #{$host}"
}
if $pass_header and !$pass_header.empty {
$pass_header_updated = " -pass-header #{$pass_header}"
} else {
$pass_header_updated = ""
}

$options = $timeout_updated + $flush_updated + $host_or_socket + $pass_header_updated
-%>
FastCGIExternalServer <%= $faux_path %><%= $options %>
Alias <%= $fcgi_alias %> <%= $faux_path %>
Action <%= $file_type %> <%= $fcgi_alias %>
Loading

0 comments on commit 99b4488

Please sign in to comment.