apt_key.rb 3.2 KB

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