Allow full length GPG key fingerprints.
[puppet-modules/puppetlabs-apt.git] / lib / puppet / type / apt_key.rb
index 67420de0fad9502b83202ab0e21eba0493f2eacc..70825ac218c5bb286dc04219145eecf442803094 100644 (file)
@@ -28,19 +28,15 @@ Puppet::Type.newtype(:apt_key) do
   newparam(:id, :namevar => true) do
     desc 'The ID of the key you want to manage.'
     # GPG key ID's should be either 32-bit (short) or 64-bit (long) key ID's
-    # and may start with the optional 0x
-    newvalues(/\A(0x)?[0-9a-fA-F]{8}\Z/, /\A(0x)?[0-9a-fA-F]{16}\Z/)
+    # and may start with the optional 0x, or they can be 40-digit key fingerprints
+    newvalues(/\A(0x)?[0-9a-fA-F]{8}\Z/, /\A(0x)?[0-9a-fA-F]{16}\Z/, /\A(0x)?[0-9a-fA-F]{40}\Z/)
     munge do |value|
       if value.start_with?('0x')
         id = value.partition('0x').last.upcase
       else
         id = value.upcase
       end
-      if id.length == 16
-        id[8..-1]
-      else
-        id
-      end
+      id
     end
   end
 
@@ -49,8 +45,8 @@ Puppet::Type.newtype(:apt_key) do
   end
 
   newparam(:source) do
-    desc 'Location of a GPG key file, /path/to/file, http:// or https://'
-    newvalues(/\Ahttps?:\/\//, /\A\/\w+/)
+    desc 'Location of a GPG key file, /path/to/file, ftp://, http:// or https://'
+    newvalues(/\Ahttps?:\/\//, /\Aftp:\/\//, /\A\/\w+/)
   end
 
   autorequire(:file) do
@@ -60,16 +56,40 @@ Puppet::Type.newtype(:apt_key) do
   end
 
   newparam(:server) do
-    desc 'The key server to fetch the key from based on the ID.'
+    desc 'The key server to fetch the key from based on the ID. It can either be a domain name or url.'
     defaultto :'keyserver.ubuntu.com'
-    # Need to validate this, preferably through stdlib is_fqdn
-    # but still working on getting to that.
+    
+    newvalues(/\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$/)
   end
 
   newparam(:keyserver_options) do
     desc 'Additional options to pass to apt-key\'s --keyserver-options.'
   end
 
+  newproperty(:fingerprint) do
+    desc <<-EOS
+      The 40-digit hexadecimal fingerprint of the specified GPG key.
+
+      This property is read-only.
+    EOS
+  end
+
+  newproperty(:long) do
+    desc <<-EOS
+      The 16-digit hexadecimal id of the specified GPG key.
+
+      This property is read-only.
+    EOS
+  end
+
+  newproperty(:short) do
+    desc <<-EOS
+      The 8-digit hexadecimal id of the specified GPG key.
+
+      This property is read-only.
+    EOS
+  end
+
   newproperty(:expired) do
     desc <<-EOS
       Indicates if the key has expired.
@@ -96,7 +116,7 @@ Puppet::Type.newtype(:apt_key) do
 
   newproperty(:type) do
     desc <<-EOS
-      The key type, either RSA or DSA.
+      The key type, one of: rsa, dsa, ecc, ecdsa
 
       This property is read-only.
     EOS