From 1160bcd6d1c190e9afc3399b6b4895f9606b213f Mon Sep 17 00:00:00 2001 From: William Van Hevelingen Date: Thu, 9 Feb 2012 16:18:14 -0800 Subject: [PATCH] (#12526) Add ability to reverse apt { disable_keys => true } The setting `disable_keys => true` parameter in the apt module creates /etc/apt/apt.conf.d/99unauth with the contents "APT::Get::AllowUnauthenticated 1;". Changing `disable_keys` does not remove this file. This patch makes it so that `disable_keys => false` will remove /etc/apt/apt.conf.d/99unauth. --- manifests/init.pp | 22 +++++++++++++++++----- spec/classes/apt_spec.rb | 28 ++++++++++++++++++---------- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index b0acdd0..472ed06 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -16,7 +16,7 @@ # class { 'apt': } class apt( $always_apt_update = false, - $disable_keys = false, + $disable_keys = undef, $proxy_host = false, $proxy_port = '8080', $purge = false @@ -59,11 +59,23 @@ class apt( subscribe => [ File["sources.list"], File["sources.list.d"] ], refreshonly => $refresh_only_apt_update, } - if($disable_keys) { - exec { 'make-apt-insecure': - command => '/bin/echo "APT::Get::AllowUnauthenticated 1;" >> /etc/apt/apt.conf.d/99unauth', - creates => '/etc/apt/apt.conf.d/99unauth' + + case $disable_keys { + true: { + file { "99unauth": + content => "APT::Get::AllowUnauthenticated 1;\n", + ensure => present, + path => "/etc/apt/apt.conf.d/99unauth", + } + } + false: { + file { "99unauth": + ensure => absent, + path => "/etc/apt/apt.conf.d/99unauth", + } } + undef: { } # do nothing + default: { fail("Valid values for disable_keys are true or false") } } if($proxy_host) { diff --git a/spec/classes/apt_spec.rb b/spec/classes/apt_spec.rb index 294892f..e21c78e 100644 --- a/spec/classes/apt_spec.rb +++ b/spec/classes/apt_spec.rb @@ -2,19 +2,22 @@ require 'spec_helper' describe 'apt', :type => :class do let :default_params do { - :disable_keys => false, + :disable_keys => :undef, :always_apt_update => false, :purge => false } end [{}, - { + { :disable_keys => true, :always_apt_update => true, :proxy_host => true, :proxy_port => '3128', :purge => true + }, + { + :disable_keys => false } ].each do |param_set| describe "when #{param_set == {} ? "using default" : "specifying"} class parameters" do @@ -90,15 +93,20 @@ describe 'apt', :type => :class do } it { - if param_hash[:disable_keys] - should contain_exec("make-apt-insecure").with({ - 'command' => '/bin/echo "APT::Get::AllowUnauthenticated 1;" >> /etc/apt/apt.conf.d/99unauth', - 'creates' => '/etc/apt/apt.conf.d/99unauth' + if param_hash[:disable_keys] == true + should create_file("99unauth").with({ + 'content' => "APT::Get::AllowUnauthenticated 1;\n", + 'ensure' => "present", + 'path' => "/etc/apt/apt.conf.d/99unauth" }) - else - should_not contain_exec("make-apt-insecure").with({ - 'command' => '/bin/echo "APT::Get::AllowUnauthenticated 1;" >> /etc/apt/apt.conf.d/99unauth', - 'creates' => '/etc/apt/apt.conf.d/99unauth' + elsif param_hash[:disable_keys] == false + should create_file("99unauth").with({ + 'ensure' => "absent", + 'path' => "/etc/apt/apt.conf.d/99unauth" + }) + elsif param_hash[:disable_keys] != :undef + should_not create_file("99unauth").with({ + 'path' => "/etc/apt/apt.conf.d/99unauth" }) end } -- 2.45.2