1 # frozen_string_literal: true
4 require 'puppet/parameter/boolean'
6 Puppet::Type.newtype(:apt_key) do
8 @summary This type provides Puppet with the capabilities to manage GPG keys needed
9 by apt to perform package validation. Apt has it's own GPG keyring that can
10 be manipulated through the `apt-key` command.
13 apt_key { '6F6B15509CF8E59E6E469F327F438280EF8D349F':
14 source => 'http://apt.puppetlabs.com/pubkey.gpg'
19 If Puppet is given the location of a key file which looks like an absolute
20 path this type will autorequire that file.
28 if self[:refresh] == true && self[:ensure] == :absent
29 raise(_('ensure => absent and refresh => true are mutually exclusive'))
31 if self[:content] && self[:source]
32 raise(_('The properties content and source are mutually exclusive.'))
35 if self[:id].length < 40
36 warning(_('The id should be a full fingerprint (40 characters), see README.'))
40 newparam(:id, namevar: true) do
41 desc 'The ID of the key you want to manage.'
42 # GPG key ID's should be either 32-bit (short) or 64-bit (long) key ID's
43 # and may start with the optional 0x, or they can be 40-digit key fingerprints
44 newvalues(%r{\A(0x)?[0-9a-fA-F]{8}\Z}, %r{\A(0x)?[0-9a-fA-F]{16}\Z}, %r{\A(0x)?[0-9a-fA-F]{40}\Z})
46 id = if value.start_with?('0x')
47 value.partition('0x').last.upcase
56 desc 'The content of, or string representing, a GPG key.'
60 desc 'Location of a GPG key file, /path/to/file, ftp://, http:// or https://'
61 newvalues(%r{\Ahttps?://}, %r{\Aftp://}, %r{\A/\w+})
65 if self[:source] && Pathname.new(self[:source]).absolute?
71 desc 'The key server to fetch the key from based on the ID. It can either be a domain name or url.'
72 defaultto :'keyserver.ubuntu.com'
74 newvalues(%r{\A((hkp|hkps|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?(\/[a-zA-Z\d\-_.]+)*\/?$})
78 desc 'Additional options to pass to apt-key\'s --keyserver-options.'
81 newparam(:refresh, boolean: true, parent: Puppet::Parameter::Boolean) do
82 desc 'When true, recreate an existing expired key'
86 newparam(:weak_ssl, boolean: true, parent: Puppet::Parameter::Boolean) do
87 desc 'When true and source uses https, accepts download of keys without SSL verification'
91 newproperty(:fingerprint) do
93 The 40-digit hexadecimal fingerprint of the specified GPG key.
95 This property is read-only.
101 The 16-digit hexadecimal id of the specified GPG key.
103 This property is read-only.
107 newproperty(:short) do
109 The 8-digit hexadecimal id of the specified GPG key.
111 This property is read-only.
115 newproperty(:expired) do
117 Indicates if the key has expired.
119 This property is read-only.
123 newproperty(:expiry) do
125 The date the key will expire, or nil if it has no expiry date.
127 This property is read-only.
131 newproperty(:size) do
133 The key size, usually a multiple of 1024.
135 This property is read-only.
139 newproperty(:type) do
141 The key type, one of: rsa, dsa, ecc, ecdsa
143 This property is read-only.
147 newproperty(:created) do
149 Date the key was created.
151 This property is read-only.