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