apt_key.rb 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. require 'pathname'
  2. Puppet::Type.newtype(:apt_key) do
  3. @doc = <<-EOS
  4. This type provides Puppet with the capabilities to manage GPG keys needed
  5. by apt to perform package validation. Apt has it's own GPG keyring that can
  6. be manipulated through the `apt-key` command.
  7. apt_key { '4BD6EC30':
  8. source => 'http://apt.puppetlabs.com/pubkey.gpg'
  9. }
  10. **Autorequires**:
  11. If Puppet is given the location of a key file which looks like an absolute
  12. path this type will autorequire that file.
  13. EOS
  14. ensurable
  15. validate do
  16. if self[:content] and self[:source]
  17. fail('The properties content and source are mutually exclusive.')
  18. end
  19. end
  20. newparam(:id, :namevar => true) do
  21. desc 'The ID of the key you want to manage.'
  22. # GPG key ID's should be either 32-bit (short) or 64-bit (long) key ID's
  23. # and may start with the optional 0x
  24. newvalues(/\A(0x)?[0-9a-fA-F]{8}\Z/, /\A(0x)?[0-9a-fA-F]{16}\Z/)
  25. munge do |value|
  26. if value.start_with?('0x')
  27. id = value.partition('0x').last.upcase
  28. else
  29. id = value.upcase
  30. end
  31. if id.length == 16
  32. id[8..-1]
  33. else
  34. id
  35. end
  36. end
  37. end
  38. newparam(:content) do
  39. desc 'The content of, or string representing, a GPG key.'
  40. end
  41. newparam(:source) do
  42. desc 'Location of a GPG key file, /path/to/file, ftp://, http:// or https://'
  43. newvalues(/\Ahttps?:\/\//, /\Aftp:\/\//, /\A\/\w+/)
  44. end
  45. autorequire(:file) do
  46. if self[:source] and Pathname.new(self[:source]).absolute?
  47. self[:source]
  48. end
  49. end
  50. newparam(:server) do
  51. desc 'The key server to fetch the key from based on the ID.'
  52. defaultto :'keyserver.ubuntu.com'
  53. # Need to validate this, preferably through stdlib is_fqdn
  54. # but still working on getting to that.
  55. end
  56. newparam(:keyserver_options) do
  57. desc 'Additional options to pass to apt-key\'s --keyserver-options.'
  58. end
  59. newproperty(:expired) do
  60. desc <<-EOS
  61. Indicates if the key has expired.
  62. This property is read-only.
  63. EOS
  64. end
  65. newproperty(:expiry) do
  66. desc <<-EOS
  67. The date the key will expire, or nil if it has no expiry date.
  68. This property is read-only.
  69. EOS
  70. end
  71. newproperty(:size) do
  72. desc <<-EOS
  73. The key size, usually a multiple of 1024.
  74. This property is read-only.
  75. EOS
  76. end
  77. newproperty(:type) do
  78. desc <<-EOS
  79. The key type, either RSA or DSA.
  80. This property is read-only.
  81. EOS
  82. end
  83. newproperty(:created) do
  84. desc <<-EOS
  85. Date the key was created.
  86. This property is read-only.
  87. EOS
  88. end
  89. end