From 3dd5caffc571b7ae442c637561eb867d4ed403b7 Mon Sep 17 00:00:00 2001 From: SourceDoctor Date: Fri, 19 Jan 2018 18:47:55 +0100 Subject: [PATCH] add url_rewrite feature with docs and tests --- README.md | 50 +++++++++++++++++++- manifests/config.pp | 4 ++ manifests/init.pp | 7 +-- manifests/params.pp | 1 + manifests/url_rewrite_program.pp | 15 ++++++ spec/classes/url_rewrite_program.rb | 38 +++++++++++++++ templates/squid.conf.url_rewrite_program.erb | 5 ++ 7 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 manifests/url_rewrite_program.pp create mode 100644 spec/classes/url_rewrite_program.rb create mode 100644 templates/squid.conf.url_rewrite_program.erb diff --git a/README.md b/README.md index 39fc391..90d262d 100644 --- a/README.md +++ b/README.md @@ -165,6 +165,37 @@ Adds a squid.conf line cache deny our_network_hosts_acl ``` +### Defined Type squid::url\_rewrite\_program +Defines [url_rewrite_program entries](http://www.squid-cache.org/Doc/config/url_rewrite_program/) for a squid server. + +```puppet +squid::url_rewrite_program { '/usr/bin/squidguard -c /etc/squidguard/squidguard.conf': +} +``` + +Adds a squid.conf line + +``` + +# fragment for url_rewrite_program /usr/bin/squidguard -c /etc/squidguard/squidguard.conf +url_rewrite_program /usr/bin/squidguard -c /etc/squidguard/squidguard.conf +``` + +```puppet +squid::url_rewrite_program { '/usr/bin/squidguard -c /etc/squidguard/squidguard.conf': + children => 10 +} + +``` + +Adds a squid.conf line + +``` +# fragment for url_rewrite_program /usr/bin/squidguard -c /etc/squidguard/squidguard.conf +url_rewrite_program /usr/bin/squidguard -c /etc/squidguard/squidguard.conf +url_rewrite_children 10 +``` + ### Defined Type squid::http\_access Defines [http_access entries](http://www.squid-cache.org/Doc/config/http_access/) for a squid server. @@ -174,7 +205,7 @@ squid::http_access { 'our_networks hosts': } ``` -Adds a squid.conf line +Adds a squid.conf line ``` # http_access fragment for out_networks hosts @@ -284,6 +315,23 @@ As an alternative to using the Squid::Http\_port defined type with `ssl` set to * `port` defaults to the namevar and is the port number. * `options` A string to specify any options to add to the https_port line. Defaults to an empty string. +### Defined Type squid::url_rewrite_program +Defines [url_rewrite_program](http://www.squid-cache.org/Doc/config/url_rewrite_program/) for a squid server. + +```puppet +squid::url_rewrite_program { '/usr/bin/squidGuard -c /etc/squidguard/squidGuard.conf': + children => 8, + child_options => 'startup=0 idle=1 concurrency=0', +} +``` + +would result in the following squid url rewrite program + +``` +url_rewrite_program /usr/bin/squidGuard -c /etc/squidguard/squidGuard.conf +url_rewrite_children 8 startup=0 idle=1 concurrency=0 +``` + ### Defined Type squid::refresh_pattern Defines [refresh_pattern entries](http://www.squid-cache.org/Doc/config/refresh_pattern/) for a squid server. diff --git a/manifests/config.pp b/manifests/config.pp index 43143d7..8002797 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -18,6 +18,7 @@ $auth_params = $::squid::auth_params, $http_ports = $::squid::http_ports, $https_ports = $::squid::https_ports, + $url_rewrite_program = $::squid::url_rewrite_program, $refresh_patterns = $::squid::refresh_patterns, $snmp_incoming_address = $::squid::snmp_incoming_address, $snmp_ports = $::squid::snmp_ports, @@ -71,6 +72,9 @@ if $cache { create_resources('squid::cache', $cache) } + if $url_rewrite_program { + create_resources('squid::url_rewrite_program', $url_rewrite_program) + } if $refresh_patterns { create_resources('squid::refresh_pattern', $refresh_patterns) } diff --git a/manifests/init.pp b/manifests/init.pp index 9ff2ef5..b3365ff 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -13,11 +13,12 @@ String $service_name = $squid::params::service_name, Optional[Stdlib::Absolutepath] $error_directory = $squid::params::error_directory, Optional[Stdlib::Absolutepath] $err_page_stylesheet = $squid::params::err_page_stylesheet, - Optional[Hash] $acls = $squid::params::acls, - Optional[Hash] $auth_params = $squid::params::auth_params, - Optional[Hash] $cache_dirs = $squid::params::cache_dirs, + Optional[Hash] $acls = $squid::params::acls, + Optional[Hash] $auth_params = $squid::params::auth_params, + Optional[Hash] $cache_dirs = $squid::params::cache_dirs, Optional[Hash] $cache = $squid::params::cache, Optional[String] $coredump_dir = $squid::params::coredump_dir, + Optional[Hash] $url_rewrite_program = $squid::params::url_rewrite_program, Optional[Hash] $extra_config_sections = {}, Optional[Hash] $http_access = $squid::params::http_access, Optional[Hash] $snmp_access = $squid::params::snmp_access, diff --git a/manifests/params.pp b/manifests/params.pp index b84c5aa..7c8de22 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -19,6 +19,7 @@ $auth_params = undef $http_ports = undef $https_ports = undef + $url_rewrite_program = undef $refresh_patterns = undef $snmp_incoming_address = undef $snmp_ports = undef diff --git a/manifests/url_rewrite_program.pp b/manifests/url_rewrite_program.pp new file mode 100644 index 0000000..db4b063 --- /dev/null +++ b/manifests/url_rewrite_program.pp @@ -0,0 +1,15 @@ +class squid::url_rewrite_program ( + String $program = $title, + String $order = '05', + Optional[Integer] $children = undef, + Optional[String] $child_options = undef, + +) { + + concat::fragment{'squid_url_rewrite_program': + target => $squid::config, + content => template('squid/squid.conf.url_rewrite_program.erb'), + order => "44-${order}", + } + +} diff --git a/spec/classes/url_rewrite_program.rb b/spec/classes/url_rewrite_program.rb new file mode 100644 index 0000000..92a333c --- /dev/null +++ b/spec/classes/url_rewrite_program.rb @@ -0,0 +1,38 @@ +require 'spec_helper' + +describe 'squid::url_rewrite_program' do + on_supported_os.each do |os, facts| + context "on #{os}" do + let(:facts) do + facts + end + let :pre_condition do + ' class{"::squid": + config => "/tmp/squid.conf" + } + ' + end + let(:title) { 'someprogram' } + + context 'when parameters are unset' do + it { is_expected.to contain_concat_fragment('squid_url_rewrite_program_someprogram').with_target('/tmp/squid.conf') } + it { is_expected.to contain_concat_fragment('squid_url_rewrite_program_someprogram').with_order('44-05') } + it { is_expected.to contain_concat_fragment('squid_url_rewrite_program_someprogram').with_content(%r{^url_rewrite_program\s+someprogram\s*$}) } + end + context 'when parameters are set' do + let(:params) do + { + program: 'someotherprogram', + children: 10, + order: '08' + } + end + + it { is_expected.to contain_concat_fragment('squid_url_rewrite_program_someotherprogram').with_target('/tmp/squid.conf') } + it { is_expected.to contain_concat_fragment('squid_url_rewrite_program_someotherprogram').with_order('44-08') } + it { is_expected.to contain_concat_fragment('squid_url_rewrite_program_someotherprogram').with_content(%r{^url_rewrite_program\s+someotherprogram\s*$}) } + it { is_expected.to contain_concat_fragment('squid_url_rewrite_program_someotherprogram').with_content(%r{^url_rewrite_children\s+10\s*$}) } + end + end + end +end diff --git a/templates/squid.conf.url_rewrite_program.erb b/templates/squid.conf.url_rewrite_program.erb new file mode 100644 index 0000000..57a272e --- /dev/null +++ b/templates/squid.conf.url_rewrite_program.erb @@ -0,0 +1,5 @@ +# fragment for url_rewrite_program <%= @program %> +url_rewrite_program <%= @program %> +<% if @children -%> +url_rewrite_children <%= @children %> <%= @child_options%> +<% end -%>