Skip to content

Commit

Permalink
Added an ensure parameter for user control of proxy presence. Default…
Browse files Browse the repository at this point in the history
…s to undef to resist breaking any current setup.

added spec entry

Added validation

fixed ensure hash
  • Loading branch information
mike-callahan committed Aug 5, 2015
1 parent f05e43c commit afa4d45
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ Main class, includes all other classes.

* 'https': Specifies whether to enable https proxies. Valid options: 'true' and 'false'. Default: 'false'.

* 'ensure': Optional parameter. Valid options: 'file', 'present', and 'absent'. Default: 'undef'. Prefer 'file' over 'present'.

* `purge`: Specifies whether to purge any existing settings that aren't managed by Puppet. Valid options: a hash made up from the following keys:

* 'sources.list': Specifies whether to purge any unmanaged entries from `sources.list`. Valid options: 'true' and 'false'. Default: 'false'.
Expand Down
6 changes: 5 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
$_purge = merge($::apt::purge_defaults, $purge)

validate_hash($proxy)
if $proxy['ensure'] {
validate_re($proxy['ensure'], ['file', 'present', 'absent'])
}
if $proxy['host'] {
validate_string($proxy['host'])
}
Expand All @@ -64,8 +67,9 @@
validate_hash($settings)
validate_hash($ppas)

if $proxy['host'] {
if $_proxy['ensure'] == 'absent' or $_proxy['host'] {
apt::setting { 'conf-proxy':
ensure => $_proxy['ensure'],
priority => '01',
content => template('apt/_conf_header.erb', 'apt/proxy.erb'),
}
Expand Down
7 changes: 4 additions & 3 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@
}

$proxy_defaults = {
'host' => undef,
'port' => 8080,
'https' => false,
'ensure' => undef,
'host' => undef,
'port' => 8080,
'https' => false,
}

$purge_defaults = {
Expand Down
8 changes: 8 additions & 0 deletions spec/classes/apt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@
/Acquire::https::proxy "https:\/\/localhost:8080\/";/
)}
end

context 'ensure=absent' do
let(:params) { { :proxy => { 'ensure' => 'absent'} } }
it { is_expected.to contain_apt__setting('conf-proxy').with({
:ensure => 'absent',
:priority => '01',
})}
end
end
context 'lots of non-defaults' do
let :params do
Expand Down

0 comments on commit afa4d45

Please sign in to comment.