(MODULES-8321) - Add manage_auth_conf parameter
authorEimhin Laverty <eimhin.laverty@puppet.com>
Thu, 6 Dec 2018 16:31:40 +0000 (16:31 +0000)
committerEimhin Laverty <eimhin.laverty@puppet.com>
Thu, 6 Dec 2018 17:17:39 +0000 (17:17 +0000)
manifests/init.pp
manifests/params.pp
spec/classes/apt_spec.rb

index f3472aca0097e6ce45505ca34587caf1327736ce..b23acc7890b3c9e963f861060bcbb935fd16a4f2 100644 (file)
 # @param settings
 #   Creates new `apt::setting` resources. Valid options: a hash to be passed to the create_resources function linked above.
 #
+# @param manage_auth_conf
+#   Specifies whether to manage the /etc/apt/auth.conf file. When true, the file will be overwritten with the entries specified in
+#   the auth_conf_entries parameter. When false, the file will be ignored (note that this does not set the file to absent.
+#
 # @param auth_conf_entries
 #   An optional array of login configuration settings (hashes) that are recorded in the file /etc/apt/auth.conf. This file has a netrc-like 
 #   format (similar to what curl uses) and contains the login configuration for APT sources and proxies that require authentication. See 
 #   https://manpages.debian.org/testing/apt/apt_auth.conf.5.en.html for details. If specified each hash must contain the keys machine, login and 
-#   password and no others.
+#   password and no others. Specifying manage_auth_conf and not specifying this parameter will set /etc/apt/auth.conf to absent.
 #
 # @param root
 #   Specifies root directory of Apt executable.
@@ -127,6 +131,7 @@ class apt (
   Hash $ppas                    = $apt::params::ppas,
   Hash $pins                    = $apt::params::pins,
   Hash $settings                = $apt::params::settings,
+  Boolean $manage_auth_conf     = $apt::params::manage_auth_conf,
   Array[Apt::Auth_conf_entry]
     $auth_conf_entries          = $apt::params::auth_conf_entries,
   String $root                  = $apt::params::root,
@@ -269,20 +274,22 @@ class apt (
     create_resources('apt::setting', $settings)
   }
 
-  $auth_conf_ensure = $auth_conf_entries ? {
-    []      => 'absent',
-    default => 'present',
-  }
+  if $manage_auth_conf {
+    $auth_conf_ensure = $auth_conf_entries ? {
+      []      => 'absent',
+      default => 'present',
+    }
 
-  $auth_conf_tmp = epp('apt/auth_conf.epp')
+    $auth_conf_tmp = epp('apt/auth_conf.epp')
 
-  file { '/etc/apt/auth.conf':
-    ensure  => $auth_conf_ensure,
-    owner   => 'root',
-    group   => 'root',
-    mode    => '0600',
-    content => "${confheadertmp}${auth_conf_tmp}",
-    notify  => Class['apt::update'],
+    file { '/etc/apt/auth.conf':
+      ensure  => $auth_conf_ensure,
+      owner   => 'root',
+      group   => 'root',
+      mode    => '0600',
+      content => "${confheadertmp}${auth_conf_tmp}",
+      notify  => Class['apt::update'],
+    }
   }
 
   # manage pins if present
index ae26a7dfda57248a5a02b22fb0a7073b44e855d0..52b9bca3fcaa231c6f9a4ab997df448cd7a1e9e9 100644 (file)
@@ -26,6 +26,7 @@ class apt::params {
   $ppas           = {}
   $pins           = {}
   $settings       = {}
+  $manage_auth_conf = true
   $auth_conf_entries = []
 
   $config_files = {
index f93770e234d004547608cf05e31c7c55aa43557e..69cbb8c1131b04fdd05973788723d24034d34e64 100644 (file)
@@ -202,19 +202,35 @@ describe 'apt' do
       }
     end
 
-    auth_conf_content = "// This file is managed by Puppet. DO NOT EDIT.
+    context 'with manage_auth_conf => true' do
+      let(:params) do
+        super().merge(manage_auth_conf: true)
+      end
+
+      auth_conf_content = "// This file is managed by Puppet. DO NOT EDIT.
 machine deb.example.net login foologin password secret
 machine apt.example.com login aptlogin password supersecret
 "
 
-    it {
-      is_expected.to contain_file('/etc/apt/auth.conf').with(ensure: 'present',
-                                                             owner: 'root',
-                                                             group: 'root',
-                                                             mode: '0600',
-                                                             notify: 'Class[Apt::Update]',
-                                                             content: auth_conf_content)
-    }
+      it {
+        is_expected.to contain_file('/etc/apt/auth.conf').with(ensure: 'present',
+                                                               owner: 'root',
+                                                               group: 'root',
+                                                               mode: '0600',
+                                                               notify: 'Class[Apt::Update]',
+                                                               content: auth_conf_content)
+      }
+    end
+
+    context 'with manage_auth_conf => false' do
+      let(:params) do
+        super().merge(manage_auth_conf: false)
+      end
+
+      it {
+        is_expected.not_to contain_file('/etc/apt/auth.conf')
+      }
+    end
   end
 
   context 'with improperly specified entries for /etc/apt/auth.conf' do