Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add url_rewrite feature #78

Merged
merged 2 commits into from
May 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,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.

Expand All @@ -179,7 +210,7 @@ squid::http_access { 'our_networks hosts':
}
```

Adds a squid.conf line
Adds a squid.conf line

```
# http_access fragment for out_networks hosts
Expand Down Expand Up @@ -310,6 +341,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.

Expand Down
4 changes: 4 additions & 0 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
$auth_params = $::squid::auth_params,
$http_ports = $::squid::http_ports,
$https_ports = $::squid::https_ports,
$url_rewrite_program = $::squid::url_rewrite_program,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you've forgotten to edit init.pp

$refresh_patterns = $::squid::refresh_patterns,
$snmp_incoming_address = $::squid::snmp_incoming_address,
$snmp_ports = $::squid::snmp_ports,
Expand Down Expand Up @@ -78,6 +79,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)
}
Expand Down
1 change: 1 addition & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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] $send_hit = $squid::params::send_hit,
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
$auth_params = undef
$http_ports = undef
$https_ports = undef
$url_rewrite_program = undef
$refresh_patterns = undef
$snmp_incoming_address = undef
$snmp_ports = undef
Expand Down
15 changes: 15 additions & 0 deletions manifests/url_rewrite_program.pp
Original file line number Diff line number Diff line change
@@ -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}",
}

}
38 changes: 38 additions & 0 deletions spec/classes/url_rewrite_program.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions templates/squid.conf.url_rewrite_program.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# fragment for url_rewrite_program <%= @program %>
url_rewrite_program <%= @program %>
<% if @children -%>
url_rewrite_children <%= @children %> <%= @child_options%>
<% end -%>