From 7f1348ef36a1cfe8dd2fb20127f0c52fab9aa72f Mon Sep 17 00:00:00 2001 From: Eimhin Laverty Date: Thu, 20 Sep 2018 11:43:25 +0100 Subject: [PATCH] Rubocop fixes and i18n update --- lib/puppet/provider/apt_key/apt_key.rb | 30 ++-- lib/puppet/type/apt_key.rb | 4 +- locales/puppetlabs-apt.pot | 194 +++++------------------ manifests/key.pp | 9 -- spec/acceptance/apt_key_provider_spec.rb | 20 +-- spec/defines/key_spec.rb | 19 ++- spec/unit/puppet/type/apt_key_spec.rb | 14 +- 7 files changed, 82 insertions(+), 208 deletions(-) diff --git a/lib/puppet/provider/apt_key/apt_key.rb b/lib/puppet/provider/apt_key/apt_key.rb index 3ccc97cf1a..5a66e34dce 100644 --- a/lib/puppet/provider/apt_key/apt_key.rb +++ b/lib/puppet/provider/apt_key/apt_key.rb @@ -71,7 +71,7 @@ def self.instances end key_array.compact! end - + def self.prefetch(resources) apt_keys = instances resources.each_key do |name| @@ -181,27 +181,29 @@ def tempfile(content) # Update a key if it is expired def update_expired_key - # Return without doing anything if expired is false - return unless (resource[:refresh] == true && resource[:expired] == true) + # Return without doing anything if refresh or expired is false + return unless resource[:refresh] == true && resource[:expired] == true + # Execute command to update key command = [] - if resource[:source].nil? && resource[:content].nil? - # Breaking up the command like this is needed because it blows up - # if --recv-keys isn't the last argument. - command.push('adv', '--keyserver', resource[:server]) - unless resource[:options].nil? - command.push('--keyserver-options', resource[:options]) - end - command.push('--recv-keys', resource[:id]) - else + + unless resource[:source].nil? && resource[:content].nil? raise(_('an unexpected condition occurred while trying to add the key: %{_resource}') % { _resource: resource[:id] }) end + + # Breaking up the command like this is needed because it blows up + # if --recv-keys isn't the last argument. + command.push('adv', '--keyserver', resource[:server]) + unless resource[:options].nil? + command.push('--keyserver-options', resource[:options]) + end + command.push('--recv-keys', resource[:id]) end def exists? - update_expired_key() + update_expired_key # report expired keys as non-existing when refresh => true - @property_hash[:ensure] == :present && !(resource[:refresh] && @property_hash[:expired]) + @property_hash[:ensure] == :present && !(resource[:refresh] && @property_hash[:expired]) end def create diff --git a/lib/puppet/type/apt_key.rb b/lib/puppet/type/apt_key.rb index d0858753ba..5150ee8ed2 100644 --- a/lib/puppet/type/apt_key.rb +++ b/lib/puppet/type/apt_key.rb @@ -24,7 +24,7 @@ validate do if self[:refresh] == true && self[:ensure] == :absent - fail('ensure => absent and refresh => true are mutually exclusive') + raise(_('ensure => absent and refresh => true are mutually exclusive')) end if self[:content] && self[:source] raise(_('The properties content and source are mutually exclusive.')) @@ -75,7 +75,7 @@ desc 'Additional options to pass to apt-key\'s --keyserver-options.' end - newparam(:refresh, :boolean => true, :parent => Puppet::Parameter::Boolean) do + newparam(:refresh, boolean: true, parent: Puppet::Parameter::Boolean) do desc 'When true, recreate an existing expired key' end diff --git a/locales/puppetlabs-apt.pot b/locales/puppetlabs-apt.pot index e43d0098b5..69cd5f173d 100644 --- a/locales/puppetlabs-apt.pot +++ b/locales/puppetlabs-apt.pot @@ -1,62 +1,15 @@ -# #-#-#-#-# accounts.pot (PACKAGE VERSION) #-#-#-#-# -# #-#-#-#-# accounts.pot (PACKAGE VERSION) #-#-#-#-# -# #-#-#-#-# puppetlabs-apt.pot (puppetlabs-apt 6.0.0-9-g1d5c598) #-#-#-#-# -# SOME DESCRIPTIVE TITLE. -# Copyright (C) 2018 Puppet, Inc. -# This file is distributed under the same license as the puppetlabs-apt package. -# FIRST AUTHOR , 2018. -# +# #-#-#-#-# puppetlabs-apt.pot (PACKAGE VERSION) #-#-#-#-# # #-#-#-#-# puppetlabs-apt_metadata.pot (PACKAGE VERSION) #-#-#-#-# # -# #-#-#-#-# puppetlabs-apt.pot (puppetlabs-apt 6.0.0-9-g1d5c598) #-#-#-#-# -# SOME DESCRIPTIVE TITLE. -# Copyright (C) 2018 Puppet, Inc. -# This file is distributed under the same license as the puppetlabs-apt package. -# FIRST AUTHOR , 2018. -# -# #-#-#-#-# puppetlabs-apt_metadata.pot (PACKAGE VERSION) #-#-#-#-# -# -# #-#-#-#-# puppetlabs-apt.pot (puppetlabs-apt 6.0.0-9-g1d5c598) #-#-#-#-# -# SOME DESCRIPTIVE TITLE. -# Copyright (C) 2018 Puppet, Inc. -# This file is distributed under the same license as the puppetlabs-apt package. -# FIRST AUTHOR , 2018. -# # #-#-#-#-# puppetlabs-apt_metadata.pot (PACKAGE VERSION) #-#-#-#-# # #, fuzzy msgid "" msgstr "" -"#-#-#-#-# accounts.pot (PACKAGE VERSION) #-#-#-#-#\n" -"#-#-#-#-# accounts.pot (PACKAGE VERSION) #-#-#-#-#\n" "#-#-#-#-# puppet.pot (PACKAGE VERSION) #-#-#-#-#\n" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-08-30 14:54:05 +0100\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"X-Generator: Translate Toolkit 2.0.0\n" -"#-#-#-#-# puppetlabs-apt.pot (puppetlabs-apt 6.0.0-9-g1d5c598) #-#-#-#-#\n" -"Project-Id-Version: puppetlabs-apt 6.0.0-9-g1d5c598\n" -"\n" -"Report-Msgid-Bugs-To: docs@puppet.com\n" -"POT-Creation-Date: 2018-08-30 14:48+0100\n" -"PO-Revision-Date: 2018-08-30 14:48+0100\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"Language: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" -"#-#-#-#-# puppetlabs-apt_metadata.pot (PACKAGE VERSION) #-#-#-#-#\n" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To:\n" -"POT-Creation-Date: 2018-08-30T14:54:45+01:00\n" +"POT-Creation-Date: 2018-09-20 10:58:13 +0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -64,10 +17,11 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "X-Generator: Translate Toolkit 2.0.0\n" +"#-#-#-#-# puppetlabs-apt.pot (PACKAGE VERSION) #-#-#-#-#\n" "#-#-#-#-# puppet.pot (PACKAGE VERSION) #-#-#-#-#\n" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-08-30 14:54:05 +0100\n" +"POT-Creation-Date: 2018-09-20 10:58:13 +0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -75,34 +29,10 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "X-Generator: Translate Toolkit 2.0.0\n" -"#-#-#-#-# puppetlabs-apt.pot (puppetlabs-apt 6.0.0-9-g1d5c598) #-#-#-#-#\n" -"Project-Id-Version: puppetlabs-apt 6.0.0-9-g1d5c598\n" -"\n" -"Report-Msgid-Bugs-To: docs@puppet.com\n" -"POT-Creation-Date: 2018-08-30 14:48+0100\n" -"PO-Revision-Date: 2018-08-30 14:48+0100\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"Language: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" "#-#-#-#-# puppetlabs-apt_metadata.pot (PACKAGE VERSION) #-#-#-#-#\n" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To:\n" -"POT-Creation-Date: 2018-08-30T14:54:45+01:00\n" -"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"X-Generator: Translate Toolkit 2.0.0\n" -"#-#-#-#-# puppet.pot (PACKAGE VERSION) #-#-#-#-#\n" -"Project-Id-Version: PACKAGE VERSION\n" -"Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-08-30 16:09:57 +0100\n" +"POT-Creation-Date: 2018-09-20T10:56:25+01:00\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -110,23 +40,10 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "X-Generator: Translate Toolkit 2.0.0\n" -"#-#-#-#-# puppetlabs-apt.pot (puppetlabs-apt 6.0.0-9-g1d5c598) #-#-#-#-#\n" -"Project-Id-Version: puppetlabs-apt 6.0.0-9-g1d5c598\n" -"\n" -"Report-Msgid-Bugs-To: docs@puppet.com\n" -"POT-Creation-Date: 2018-08-30 16:09+0100\n" -"PO-Revision-Date: 2018-08-30 16:09+0100\n" -"Last-Translator: FULL NAME \n" -"Language-Team: LANGUAGE \n" -"Language: \n" -"MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=UTF-8\n" -"Content-Transfer-Encoding: 8bit\n" -"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n" "#-#-#-#-# puppetlabs-apt_metadata.pot (PACKAGE VERSION) #-#-#-#-#\n" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To:\n" -"POT-Creation-Date: 2018-08-30T14:54:45+01:00\n" +"POT-Creation-Date: 2018-09-20T10:56:25+01:00\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -135,132 +52,93 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "X-Generator: Translate Toolkit 2.0.0\n" -#. ./manifests/backports.pp:36 +#. ./manifests/backports.pp:69 msgid "" "If not on Debian or Ubuntu, you must explicitly pass location, release, " "repos, and key" msgstr "" -#. ./manifests/backports.pp:50 +#. ./manifests/backports.pp:95 msgid "pin must be either a string, number or hash" msgstr "" -#. ./manifests/conf.pp:11 +#. ./manifests/conf.pp:25 msgid "Need to pass in content parameter" msgstr "" -#. ./manifests/init.pp:37 - ./manifests/params.pp:5 +#. ./manifests/key.pp:46 +msgid "key with id %{_id} already ensured as absent" +msgstr "" + +#. ./manifests/key.pp:89 +msgid "key with id %{_id} already ensured as present" +msgstr "" + +#. ./manifests/key.pp:105 +msgid "Invalid 'ensure' value '%{_ensure}' for apt::key" +msgstr "" + +#. ./manifests/params.pp:8 ./manifests/init.pp:143 msgid "This module only works on Debian or derivatives like Ubuntu" msgstr "" -#. ./manifests/params.pp:97 -msgid "Unable to determine value for fact os['name']" +#. ./manifests/params.pp:100 +msgid "Unable to determine value for fact os[\"name\"]" msgstr "" -#. ./manifests/pin.pp:52 +#. ./manifests/pin.pp:84 msgid "parameters release, origin, and version are mutually exclusive" msgstr "" -#. ./manifests/pin.pp:56 +#. ./manifests/pin.pp:88 msgid "parameter version cannot be used in general form" msgstr "" -#. ./manifests/pin.pp:59 +#. ./manifests/pin.pp:91 msgid "parameters release and origin are mutually exclusive" msgstr "" -#. ./manifests/ppa.pp:10 - ./manifests/source.pp:25 +#. ./manifests/ppa.pp:30 ./manifests/source.pp:79 msgid "lsbdistcodename fact not available: release parameter required" msgstr "" -#. ./manifests/ppa.pp:14 +#. ./manifests/ppa.pp:34 msgid "apt::ppa is not currently supported on Debian." msgstr "" -#. ./manifests/setting.pp:11 +#. ./manifests/setting.pp:31 msgid "apt::setting cannot have both content and source" msgstr "" -#. ./manifests/setting.pp:15 +#. ./manifests/setting.pp:35 msgid "apt::setting needs either of content or source" msgstr "" -#. ./manifests/setting.pp:23 +#. ./manifests/setting.pp:43 msgid "" "apt::setting resource name/title must start with either 'conf-', 'pref-' or " "'list-'" msgstr "" -#. ./manifests/setting.pp:29 +#. ./manifests/setting.pp:49 msgid "apt::setting priority must be an integer or a zero-padded integer" msgstr "" -#. ./manifests/source.pp:33 +#. ./manifests/source.pp:87 msgid "cannot create a source entry without specifying a location" msgstr "" -#. ./manifests/source.pp:47 +#. ./manifests/source.pp:101 msgid "key hash must contain at least an id entry" msgstr "" -#. ./manifests/source.pp:86 +#. ./manifests/source.pp:140 msgid "Received invalid value for pin parameter" msgstr "" -#: ../lib/puppet/provider/apt_key/apt_key.rb:122 -msgid "The file %{_value} does not exist" -msgstr "" - -#: ../lib/puppet/provider/apt_key/apt_key.rb:218 -msgid "This is a read-only property." -msgstr "" - -#: ../lib/puppet/type/apt_key.rb:23 -msgid "The properties content and source are mutually exclusive." -msgstr "" - #. metadata.json #: .summary msgid "" "Provides an interface for managing Apt source, key, and definitions with " "Puppet" msgstr "" - -#. ./manifests/params.pp:97 -msgid "Unable to determine value for fact os[\"name\"]" -msgstr "" - -#. ./manifests/key.pp:29 -msgid "key with id %{_id} already ensured as absent" -msgstr "" - -#. ./manifests/key.pp:62 -msgid "key with id %{_id} already ensured as present" -msgstr "" - -#. ./manifests/key.pp:78 -msgid "Invalid 'ensure' value '%{_ensure}' for apt::key" -msgstr "" - -#: ../lib/puppet/provider/apt_key/apt_key.rb:142 -msgid "%{_e} for %{_resource}" -msgstr "" - -#: ../lib/puppet/provider/apt_key/apt_key.rb:144 -msgid "could not resolve %{_resource}" -msgstr "" - -#: ../lib/puppet/provider/apt_key/apt_key.rb:171 -msgid "" -"The id in your manifest %{_resource} and the fingerprint from content/source " -"don't match. Check for an error in the id and content/source is legitimate." -msgstr "" - -#: ../lib/puppet/provider/apt_key/apt_key.rb:202 -msgid "" -"an unexpected condition occurred while trying to add the key: %{_resource}" -msgstr "" - -#: ../lib/puppet/type/apt_key.rb:26 -msgid "The id should be a full fingerprint (40 characters), see README." -msgstr "" diff --git a/manifests/key.pp b/manifests/key.pp index afa1f29281..acd6843f40 100644 --- a/manifests/key.pp +++ b/manifests/key.pp @@ -57,15 +57,6 @@ options => $options, } -> anchor { "apt_key ${id} present": } - /* if $ensure == 'refreshed' { - notify { "Executing update of key ${id}": } - exec { "apt-key ${id}": - path => '/bin:/usr/bin', - unless => "apt-key list | grep '${id}' | grep expired", - command => "apt-key adv --keyserver ${server} --recv-keys ${id}", - } - } - */ case $facts['os']['name'] { 'Debian': { if versioncmp($facts['os']['release']['major'], '9') >= 0 { diff --git a/spec/acceptance/apt_key_provider_spec.rb b/spec/acceptance/apt_key_provider_spec.rb index 686014e0a9..1daf063270 100644 --- a/spec/acceptance/apt_key_provider_spec.rb +++ b/spec/acceptance/apt_key_provider_spec.rb @@ -10,15 +10,15 @@ CENTOS_GPG_KEY_FINGERPRINT = 'C1DAC52D1664E8A4386DBA430946FCA2C105B9DE'.freeze CENTOS_REPO_URL = 'ftp.cvut.cz/centos'.freeze CENTOS_GPG_KEY_FILE = 'RPM-GPG-KEY-CentOS-6'.freeze -PUPPETLABS_EXP_KEY_SHORT_ID = '4BD6EC30' -PUPPETLABS_EXP_KEY_LONG_ID = "47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30" -PUPPETLABS_EXP_KEY_DATES = "pub:e:4096:1:1054B7A24BD6EC30:2010-07-10:2017-01-05::-:Puppet Labs Release Key" +PUPPETLABS_EXP_KEY_SHORT_ID = '4BD6EC30'.freeze +PUPPETLABS_EXP_KEY_LONG_ID = '47B320EB4C7C375AA9DAE1A01054B7A24BD6EC30'.freeze +PUPPETLABS_EXP_KEY_DATES = 'pub:e:4096:1:1054B7A24BD6EC30:2010-07-10:2017-01-05::-:Puppet Labs Release Key'.freeze SHOULD_NEVER_EXIST_ID = 'EF8D349F'.freeze KEY_CHECK_COMMAND = 'apt-key adv --list-keys --with-colons --fingerprint | grep '.freeze PUPPETLABS_KEY_CHECK_COMMAND = "#{KEY_CHECK_COMMAND} #{PUPPETLABS_GPG_KEY_FINGERPRINT}".freeze CENTOS_KEY_CHECK_COMMAND = "#{KEY_CHECK_COMMAND} #{CENTOS_GPG_KEY_FINGERPRINT}".freeze PUPPETLABS_EXP_CHECK_COMMAND = "#{KEY_CHECK_COMMAND} '#{PUPPETLABS_EXP_KEY_DATES}'".freeze -TIMEOUT_ERROR_MATCHER = /no valid OpenPGP data found/ +TIMEOUT_ERROR_MATCHER = %r{no valid OpenPGP data found} def populate_default_options_pp(value) default_options_pp = <<-MANIFEST @@ -648,8 +648,8 @@ def apply_manifest_twice(manifest_pp) MANIFEST refresh_del_key_pp = <<-MANIFEST - apt_key { '#{PUPPETLABS_EXP_KEY_LONG_ID}': - ensure => 'absent', + apt_key { '#{PUPPETLABS_EXP_KEY_LONG_ID}': + ensure => 'absent', } MANIFEST @@ -936,26 +936,26 @@ def apply_manifest_twice(manifest_pp) end end end - + describe 'refresh' do before(:each) do # delete the Puppet Labs Release Key # and install an expired version of the key apply_manifest(refresh_del_key_pp) - apply_manifest(refresh_pp, :catch_failures => true) + apply_manifest(refresh_pp, catch_failures: true) end context 'when refresh => true' do it 'updates an expired key' do apply_manifest(refresh_true_pp) # Check key has been updated to new version - shell("#{PUPPETLABS_EXP_CHECK_COMMAND} | grep \"#{PUPPETLABS_EXP_KEY_DATES}\"", :acceptable_exit_codes => [0]) + shell("#{PUPPETLABS_EXP_CHECK_COMMAND} | grep \"#{PUPPETLABS_EXP_KEY_DATES}\"", acceptable_exit_codes: [0]) end end context 'when refresh => false' do it 'does not replace an expired key' do apply_manifest(refresh_false_pp) # Expired key is present and has not been updated by the new version - shell("#{PUPPETLABS_EXP_CHECK_COMMAND} | grep \"#{PUPPETLABS_EXP_KEY_DATES}\"", :acceptable_exit_codes => [1]) + shell("#{PUPPETLABS_EXP_CHECK_COMMAND} | grep \"#{PUPPETLABS_EXP_KEY_DATES}\"", acceptable_exit_codes: [1]) end end end diff --git a/spec/defines/key_spec.rb b/spec/defines/key_spec.rb index eb14bee977..cf596e996b 100644 --- a/spec/defines/key_spec.rb +++ b/spec/defines/key_spec.rb @@ -99,15 +99,18 @@ def absent_apt_key(title) end end - describe "ensure => refreshed" do - let :params do { - :ensure => 'refreshed', - } end + describe 'ensure => refreshed' do + let :params do + { + ensure: 'refreshed', + } + end + it 'contains the apt_key with refresh => true' do - is_expected.to contain_apt_key(title).with({ - :ensure => 'present', - :refresh => true, - }) + is_expected.to contain_apt_key(title).with( + ensure: 'present', + refresh: true, + ) end end diff --git a/spec/unit/puppet/type/apt_key_spec.rb b/spec/unit/puppet/type/apt_key_spec.rb index 9fc6b03bf2..5b205e9924 100644 --- a/spec/unit/puppet/type/apt_key_spec.rb +++ b/spec/unit/puppet/type/apt_key_spec.rb @@ -30,7 +30,7 @@ end it 'refresh is not set' do - expect(resource[:content]).to eq nil + expect(resource[:refresh]).to eq nil end end @@ -143,12 +143,12 @@ end it 'raises an error if refresh => true and ensure => absent' do - expect { Puppet::Type.type(:apt_key).new( - :id => 'EF8D349F', - :source => 'http://apt.puppetlabs.com/pubkey.gpg', - :ensure => :absent, - :refresh => :true - )}.to raise_error(/ensure => absent and refresh => true are mutually exclusive/) + expect { + Puppet::Type.type(:apt_key).new(id: 'EF8D349F', + source: 'http://apt.puppetlabs.com/pubkey.gpg', + ensure: :absent, + refresh: :true) + }.to raise_error(%r{ensure => absent and refresh => true are mutually exclusive}) end it 'raises an error if a weird length key is used' do