apt_key.rb 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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, or they can be 40-digit key fingerprints
  24. 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/)
  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. id
  32. end
  33. end
  34. newparam(:content) do
  35. desc 'The content of, or string representing, a GPG key.'
  36. end
  37. newparam(:source) do
  38. desc 'Location of a GPG key file, /path/to/file, ftp://, http:// or https://'
  39. newvalues(/\Ahttps?:\/\//, /\Aftp:\/\//, /\A\/\w+/)
  40. end
  41. autorequire(:file) do
  42. if self[:source] and Pathname.new(self[:source]).absolute?
  43. self[:source]
  44. end
  45. end
  46. newparam(:server) do
  47. desc 'The key server to fetch the key from based on the ID. It can either be a domain name or url.'
  48. defaultto :'keyserver.ubuntu.com'
  49. newvalues(/\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$/)
  50. end
  51. newparam(:keyserver_options) do
  52. desc 'Additional options to pass to apt-key\'s --keyserver-options.'
  53. end
  54. newproperty(:fingerprint) do
  55. desc <<-EOS
  56. The 40-digit hexadecimal fingerprint of the specified GPG key.
  57. This property is read-only.
  58. EOS
  59. end
  60. newproperty(:long) do
  61. desc <<-EOS
  62. The 16-digit hexadecimal id of the specified GPG key.
  63. This property is read-only.
  64. EOS
  65. end
  66. newproperty(:short) do
  67. desc <<-EOS
  68. The 8-digit hexadecimal id of the specified GPG key.
  69. This property is read-only.
  70. EOS
  71. end
  72. newproperty(:expired) do
  73. desc <<-EOS
  74. Indicates if the key has expired.
  75. This property is read-only.
  76. EOS
  77. end
  78. newproperty(:expiry) do
  79. desc <<-EOS
  80. The date the key will expire, or nil if it has no expiry date.
  81. This property is read-only.
  82. EOS
  83. end
  84. newproperty(:size) do
  85. desc <<-EOS
  86. The key size, usually a multiple of 1024.
  87. This property is read-only.
  88. EOS
  89. end
  90. newproperty(:type) do
  91. desc <<-EOS
  92. The key type, one of: rsa, dsa, ecc, ecdsa
  93. This property is read-only.
  94. EOS
  95. end
  96. newproperty(:created) do
  97. desc <<-EOS
  98. Date the key was created.
  99. This property is read-only.
  100. EOS
  101. end
  102. end