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