Merge pull request #873 from raphink/default_key_options
authorErick Banks <erick@puppetlabs.com>
Wed, 14 Aug 2019 20:59:35 +0000 (13:59 -0700)
committerGitHub <noreply@github.com>
Wed, 14 Aug 2019 20:59:35 +0000 (13:59 -0700)
Add apt::key_options for default apt::key options

manifests/init.pp
manifests/key.pp
manifests/params.pp
spec/defines/key_spec.rb

index 9c6a44b4603d17048f2a21393b16b326a887b3a6..f205b3e057cbd009fb4e252fba20de4bcdcbc7de 100644 (file)
@@ -9,6 +9,9 @@
 #   Specifies a keyserver to provide the GPG key. Valid options: a string containing a domain name or a full URL (http://, https://, or
 #   hkp://).
 #
+# @param key_options
+#   Specifies the default options for apt::key resources.
+#
 # @param ppa_options
 #   Supplies options to be passed to the `add-apt-repository` command.
 #
@@ -122,6 +125,7 @@ class apt (
   Hash $include_defaults        = $apt::params::include_defaults,
   String $provider              = $apt::params::provider,
   String $keyserver             = $apt::params::keyserver,
+  Optional[String] $key_options = $apt::params::key_options,
   Optional[String] $ppa_options = $apt::params::ppa_options,
   Optional[String] $ppa_package = $apt::params::ppa_package,
   Optional[Hash] $backports     = $apt::params::backports,
index 1f9a495f54f4f3f19424fe571842ed04955bd46f..41e78e643bbe3245528b9cab037f34247b8cf800 100644 (file)
@@ -42,7 +42,7 @@ define apt::key (
   Optional[Pattern[/\Ahttps?:\/\//, /\Aftp:\/\//, /\A\/\w+/]] $source                                = undef,
   Pattern[/\A((hkp|hkps|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$/] $server = $::apt::keyserver,
   Boolean $weak_ssl                                                                                  = false,
-  Optional[String] $options                                                                          = undef,
+  Optional[String] $options                                                                          = $::apt::key_options,
   ) {
 
   case $ensure {
index 65219fef5a7a65967a20a4ceff313641115b739a..b0c367ca109cb4858df14ee0fbcdc56263d19332 100644 (file)
@@ -18,6 +18,7 @@ class apt::params {
   $preferences_d  = "${root}/preferences.d"
   $apt_conf_d     = "${root}/apt.conf.d"
   $keyserver      = 'keyserver.ubuntu.com'
+  $key_options    = undef
   $confs          = {}
   $update         = {}
   $purge          = {}
index 68d5fcea89a15ef86adab0813df73950d451fd65..ad715d6e595a1d9439bd20b9e0dfbe2897491557 100644 (file)
@@ -379,4 +379,30 @@ describe 'apt::key' do
       end
     end
   end
+
+  describe 'defaults' do
+    context 'when setting keyserver on the apt class' do
+      let :pre_condition do
+        'class { "apt":
+          keyserver => "keyserver.example.com",
+        }'
+      end
+
+      it 'uses default keyserver' do
+        is_expected.to contain_apt_key(title).with_server('keyserver.example.com')
+      end
+    end
+
+    context 'when setting key_options on the apt class' do
+      let :pre_condition do
+        'class { "apt":
+          key_options => "http-proxy=http://proxy.example.com:8080",
+        }'
+      end
+
+      it 'uses default keyserver' do
+        is_expected.to contain_apt_key(title).with_options('http-proxy=http://proxy.example.com:8080')
+      end
+    end
+  end
 end