]> gitweb.fluxo.info Git - puppet-sshkeys_core.git/commitdiff
(MODULES-10827) Exported sshkey already exists error
authorDorin Pleava <dorin.pleava@puppet.com>
Mon, 5 Oct 2020 09:02:33 +0000 (12:02 +0300)
committerDorin Pleava <dorin.pleava@puppet.com>
Mon, 5 Oct 2020 12:52:36 +0000 (15:52 +0300)
Using module https://github.com/ghoneycutt/puppet-module-ssh to export
and collect sshkey resources from nodes, an 'already declared' error
appears.

This happened because when the catalog is first converted to resouces,
the sshkey resource is added via
https://github.com/puppetlabs/puppet/blob/main/lib/puppet/resource/catalog.rb#L137,
where 'resource.ref'(https://github.com/puppetlabs/puppet/blob/main/lib/puppet/type.rb#L2548)
uses 'self.title'.
Since self.title goes to the title method defined in type.rb, it will
return a different title than the title method from
https://github.com/puppetlabs/puppetlabs-sshkeys_core/blob/main/lib/puppet/provider/sshkey/parsed.rb#L31.
This mismatch try to add both resource, resulting in the 'already
declared' error.

lib/puppet/type/sshkey.rb
spec/unit/type/sshkey_spec.rb

index d45c059c9fdb85ed40300db3f324b6b6b3893351..6e603a212e1c5a1dbeb95709f1d72ae51cab85c6 100644 (file)
@@ -12,6 +12,8 @@ module Puppet
       "#{self[:name]}@#{self[:type]}"
     end
 
+    alias_method :title, :name
+
     def self.parameters_to_include
       [:name, :type]
     end
index 53448ed0c71946cec743e26d68c884c2f89b3289..2804ee4b0b2211f2460133c9a586b17d28fb3ae4 100644 (file)
@@ -81,5 +81,10 @@ describe Puppet::Type.type(:sshkey) do
         described_class.new(name: 'host,host.domain,ip')
       }.to raise_error(Puppet::Error, %r{No comma in resourcename})
     end
+
+    it 'aliases :title to :name' do
+      key = described_class.new(name: 'foo', type: :rsa)
+      expect(key.name).to eq key.title
+    end
   end
 end