(FM-6273) - Removing Debian 6
[puppet-modules/puppetlabs-apt.git] / manifests / key.pp
1 # == Define: apt::key
2 define apt::key (
3     String $id                           = $title,
4     Enum['present', 'absent'] $ensure    = present,
5     Optional[String] $content            = undef,
6     Optional[String] $source             = undef,
7     String $server                       = $::apt::keyserver,
8     Optional[String] $options            = undef,
9     ) {
10
11   validate_re($id, ['\A(0x)?[0-9a-fA-F]{8}\Z', '\A(0x)?[0-9a-fA-F]{16}\Z', '\A(0x)?[0-9a-fA-F]{40}\Z'])
12
13   if $source {
14     validate_re($source, ['\Ahttps?:\/\/', '\Aftp:\/\/', '\A\/\w+'])
15   }
16
17   if $server {
18     validate_re($server,['\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$'])
19   }
20
21   case $ensure {
22     present: {
23       if defined(Anchor["apt_key ${id} absent"]){
24         fail("key with id ${id} already ensured as absent")
25       }
26
27       if !defined(Anchor["apt_key ${id} present"]) {
28         apt_key { $title:
29           ensure  => $ensure,
30           id      => $id,
31           source  => $source,
32           content => $content,
33           server  => $server,
34           options => $options,
35         } -> anchor { "apt_key ${id} present": }
36       }
37     }
38
39     absent: {
40       if defined(Anchor["apt_key ${id} present"]){
41         fail("key with id ${id} already ensured as present")
42       }
43
44       if !defined(Anchor["apt_key ${id} absent"]){
45         apt_key { $title:
46           ensure  => $ensure,
47           id      => $id,
48           source  => $source,
49           content => $content,
50           server  => $server,
51           options => $options,
52         } -> anchor { "apt_key ${id} absent": }
53       }
54     }
55
56     default: {
57       fail "Invalid 'ensure' value '${ensure}' for apt::key"
58     }
59   }
60 }