Don't truncate to short keys in the type

You should be able to create/delete keys using the long key to avoid
collisions, and truncating in the type makes that not work.
This commit is contained in:
Morgan Haskel 2014-10-01 12:55:41 -05:00
parent 43b894b12e
commit 87f3f1023c
3 changed files with 20 additions and 14 deletions

View file

@ -57,7 +57,12 @@ Puppet::Type.type(:apt_key).provide(:apt_key) do
def self.prefetch(resources) def self.prefetch(resources)
apt_keys = instances apt_keys = instances
resources.keys.each do |name| resources.keys.each do |name|
if provider = apt_keys.find{ |key| key.name == name } if name.length == 16
shortname=name[8..-1]
else
shortname=name
end
if provider = apt_keys.find{ |key| key.name == shortname }
resources[name].provider = provider resources[name].provider = provider
end end
end end

View file

@ -36,13 +36,9 @@ Puppet::Type.newtype(:apt_key) do
else else
id = value.upcase id = value.upcase
end end
if id.length == 16
id[8..-1]
else
id id
end end
end end
end
newparam(:content) do newparam(:content) do
desc 'The content of, or string representing, a GPG key.' desc 'The content of, or string representing, a GPG key.'

View file

@ -1,6 +1,7 @@
require 'spec_helper_acceptance' require 'spec_helper_acceptance'
PUPPETLABS_GPG_KEY_ID = '4BD6EC30' PUPPETLABS_GPG_KEY_ID = '4BD6EC30'
PUPPETLABS_GPG_LONG_KEY_ID = '1054B7A24BD6EC30'
PUPPETLABS_APT_URL = 'apt.puppetlabs.com' PUPPETLABS_APT_URL = 'apt.puppetlabs.com'
PUPPETLABS_GPG_KEY_FILE = 'pubkey.gpg' PUPPETLABS_GPG_KEY_FILE = 'pubkey.gpg'
CENTOS_GPG_KEY_ID = 'C105B9DE' CENTOS_GPG_KEY_ID = 'C105B9DE'
@ -9,6 +10,10 @@ CENTOS_GPG_KEY_FILE = 'RPM-GPG-KEY-CentOS-6'
describe 'apt_key' do describe 'apt_key' do
before(:each) do before(:each) do
# Delete twice to make sure everything is cleaned
# up after the short key collision
shell("apt-key del #{PUPPETLABS_GPG_KEY_ID}",
:acceptable_exit_codes => [0,1,2])
shell("apt-key del #{PUPPETLABS_GPG_KEY_ID}", shell("apt-key del #{PUPPETLABS_GPG_KEY_ID}",
:acceptable_exit_codes => [0,1,2]) :acceptable_exit_codes => [0,1,2])
end end
@ -36,7 +41,7 @@ describe 'apt_key' do
EOS EOS
apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_failures => true) apply_manifest(pp, :catch_changes => true)
shell("apt-key list | grep #{PUPPETLABS_GPG_KEY_ID}") shell("apt-key list | grep #{PUPPETLABS_GPG_KEY_ID}")
end end
end end
@ -69,7 +74,7 @@ describe 'apt_key' do
# Install the key first # Install the key first
shell("apt-key adv --keyserver keyserver.ubuntu.com \ shell("apt-key adv --keyserver keyserver.ubuntu.com \
--recv-keys #{PUPPETLABS_GPG_KEY_ID}") --recv-keys #{PUPPETLABS_GPG_LONG_KEY_ID}")
shell("apt-key list | grep #{PUPPETLABS_GPG_KEY_ID}") shell("apt-key list | grep #{PUPPETLABS_GPG_KEY_ID}")
# Time to remove it using Puppet # Time to remove it using Puppet