ソースを参照

(#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.
William Van Hevelingen 12 年 前
コミット
1160bcd
2 ファイル変更35 行追加15 行削除
  1. 17 5
      manifests/init.pp
  2. 18 10
      spec/classes/apt_spec.rb

+ 17 - 5
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) {

+ 18 - 10
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
       }