Merge pull request #671 from puppetlabs/release
[puppet-modules/puppetlabs-apt.git] / manifests / key.pp
1 # == Define: apt::key
2 define apt::key (
3     Variant[String, Stdlib::Compat::String] $id                                         = $title,
4     Enum['present', 'absent'] $ensure                                                   = present,
5     Optional[Variant[String, Stdlib::Compat::String]] $content                          = undef,
6     Optional[Variant[String, Stdlib::Compat::String]] $source                           = undef,
7     Variant[String, Stdlib::Compat::String] $server                                     = $::apt::keyserver,
8     Optional[Variant[String, Stdlib::Compat::String]] $options                          = undef,
9     Optional[Variant[String, Stdlib::Compat::String, Hash, Stdlib::Compat::Hash]] $key  = undef,
10     Optional[Variant[String, Stdlib::Compat::String]] $key_content                      = undef,
11     Optional[Variant[String, Stdlib::Compat::String]] $key_source                       = undef,
12     Optional[Variant[String, Stdlib::Compat::String]] $key_server                       = undef,
13     Optional[Variant[String, Stdlib::Compat::String]] $key_options                      = undef,
14     ) {
15
16   if $key != undef {
17     deprecation('apt $key', '$key is deprecated and will be removed in the next major release. Please use $id instead.')
18     $_id = $key
19   } else {
20     $_id = $id
21   }
22
23   if $key_content != undef {
24     deprecation('apt $key_content', '$key_content is deprecated and will be removed in the next major release. Please use $content instead.')
25     $_content = $key_content
26   } else {
27     $_content = $content
28   }
29
30   if $key_source != undef {
31     deprecation('apt $key_source', '$key_source is deprecated and will be removed in the next major release. Please use $source instead.')
32     $_source = $key_source
33   } else {
34     $_source = $source
35   }
36
37   if $key_server != undef {
38     deprecation('apt $key_server', '$key_server is deprecated and will be removed in the next major release. Please use $server instead.')
39     $_server = $key_server
40   } else {
41     $_server = $server
42   }
43
44   if $key_options != undef {
45     deprecation('apt $key_options', '$key_options is deprecated and will be removed in the next major release. Please use $options instead.')
46     $_options = $key_options
47   } else {
48     $_options = $options
49   }
50
51   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'])
52   validate_re($ensure, ['\A(absent|present)\Z',])
53
54   if $_content {
55     validate_legacy(String, 'validate_string', $_content)
56   }
57
58   if $_source {
59     validate_re($_source, ['\Ahttps?:\/\/', '\Aftp:\/\/', '\A\/\w+'])
60   }
61
62   if $_server {
63     validate_re($_server,['\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$'])
64   }
65
66   if $_options {
67     validate_legacy(String, 'validate_string', $_options)
68   }
69
70   case $ensure {
71     present: {
72       if defined(Anchor["apt_key ${_id} absent"]){
73         fail("key with id ${_id} already ensured as absent")
74       }
75
76       if !defined(Anchor["apt_key ${_id} present"]) {
77         apt_key { $title:
78           ensure  => $ensure,
79           id      => $_id,
80           source  => $_source,
81           content => $_content,
82           server  => $_server,
83           options => $_options,
84         } -> anchor { "apt_key ${_id} present": }
85       }
86     }
87
88     absent: {
89       if defined(Anchor["apt_key ${_id} present"]){
90         fail("key with id ${_id} already ensured as present")
91       }
92
93       if !defined(Anchor["apt_key ${_id} absent"]){
94         apt_key { $title:
95           ensure  => $ensure,
96           id      => $_id,
97           source  => $_source,
98           content => $_content,
99           server  => $_server,
100           options => $_options,
101         } -> anchor { "apt_key ${_id} absent": }
102       }
103     }
104
105     default: {
106       fail "Invalid 'ensure' value '${ensure}' for apt::key"
107     }
108   }
109 }