+# == Define: apt::key
define apt::key (
- $key = $title,
- $ensure = present,
- $key_content = false,
- $key_source = false,
- $key_server = "keyserver.ubuntu.com"
-) {
+ Variant[String, Stdlib::Compat::String] $id = $title,
+ Enum['present', 'absent'] $ensure = present,
+ Optional[Variant[String, Stdlib::Compat::String]] $content = undef,
+ Optional[Variant[String, Stdlib::Compat::String]] $source = undef,
+ Variant[String, Stdlib::Compat::String] $server = $::apt::keyserver,
+ Optional[Variant[String, Stdlib::Compat::String]] $options = undef,
+ Optional[Variant[String, Stdlib::Compat::String, Hash, Stdlib::Compat::Hash]] $key = undef,
+ Optional[Variant[String, Stdlib::Compat::String]] $key_content = undef,
+ Optional[Variant[String, Stdlib::Compat::String]] $key_source = undef,
+ Optional[Variant[String, Stdlib::Compat::String]] $key_server = undef,
+ Optional[Variant[String, Stdlib::Compat::String]] $key_options = undef,
+ ) {
- include apt::params
+ if $key != undef {
+ deprecation('apt $key', '$key is deprecated and will be removed in the next major release. Please use $id instead.')
+ $_id = $key
+ } else {
+ $_id = $id
+ }
- if $key_content {
- $method = "content"
- } elsif $key_source {
- $method = "source"
- } elsif $key_server {
- $method = "server"
+ if $key_content != undef {
+ deprecation('apt $key_content', '$key_content is deprecated and will be removed in the next major release. Please use $content instead.')
+ $_content = $key_content
+ } else {
+ $_content = $content
}
- # This is a hash of the parts of the key definition that we care about.
- # It is used as a unique identifier for this instance of apt::key. It gets
- # hashed to ensure that the resource name doesn't end up being pages and
- # pages (e.g. in the situation where key_content is specified).
- $digest = sha1("${key}/${key_content}/${key_source}/${key_server}/")
+ if $key_source != undef {
+ deprecation('apt $key_source', '$key_source is deprecated and will be removed in the next major release. Please use $source instead.')
+ $_source = $key_source
+ } else {
+ $_source = $source
+ }
- # Allow multiple ensure => present for the same key to account for many
- # apt::source resources that all reference the same key.
- case $ensure {
- present: {
+ if $key_server != undef {
+ deprecation('apt $key_server', '$key_server is deprecated and will be removed in the next major release. Please use $server instead.')
+ $_server = $key_server
+ } else {
+ $_server = $server
+ }
- anchor { "apt::key/$title":; }
+ if $key_options != undef {
+ deprecation('apt $key_options', '$key_options is deprecated and will be removed in the next major release. Please use $options instead.')
+ $_options = $key_options
+ } else {
+ $_options = $options
+ }
- if defined(Exec["apt::key $key absent"]) {
- fail ("Cannot ensure Apt::Key[$key] present; $key already ensured absent")
- }
+ 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'])
+ validate_re($ensure, ['\A(absent|present)\Z',])
- if !defined(Anchor["apt::key $key present"]) {
- anchor { "apt::key $key present":; }
- }
+ if $_content {
+ validate_legacy(String, 'validate_string', $_content)
+ }
- if !defined(Exec[$digest]) {
- exec { $digest:
- path => "/bin:/usr/bin",
- unless => "/usr/bin/apt-key list | /bin/grep '${key}'",
- before => Anchor["apt::key $key present"],
- command => $method ? {
- "content" => "echo '${key_content}' | /usr/bin/apt-key add -",
- "source" => "wget -q '${key_source}' -O- | apt-key add -",
- "server" => "apt-key adv --keyserver '${key_server}' --recv-keys '${key}'",
- };
- }
- }
+ if $_source {
+ validate_re($_source, ['\Ahttps?:\/\/', '\Aftp:\/\/', '\A\/\w+'])
+ }
- Anchor["apt::key $key present"] -> Anchor["apt::key/$title"]
+ if $_server {
+ validate_re($_server,['\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$'])
+ }
+
+ if $_options {
+ validate_legacy(String, 'validate_string', $_options)
+ }
+
+ case $ensure {
+ present: {
+ if defined(Anchor["apt_key ${_id} absent"]){
+ fail("key with id ${_id} already ensured as absent")
+ }
+ if !defined(Anchor["apt_key ${_id} present"]) {
+ apt_key { $title:
+ ensure => $ensure,
+ id => $_id,
+ source => $_source,
+ content => $_content,
+ server => $_server,
+ options => $_options,
+ } -> anchor { "apt_key ${_id} present": }
+ }
}
- absent: {
- if defined(Anchor["apt::key $key present"]) {
- fail ("Cannot ensure Apt::Key[$key] absent; $key already ensured present")
+ absent: {
+ if defined(Anchor["apt_key ${_id} present"]){
+ fail("key with id ${_id} already ensured as present")
}
- exec { "apt::key $key absent":
- path => "/bin:/usr/bin",
- onlyif => "apt-key list | grep '$key'",
- command => "apt-key del '$key'",
- user => "root",
- group => "root",
+ if !defined(Anchor["apt_key ${_id} absent"]){
+ apt_key { $title:
+ ensure => $ensure,
+ id => $_id,
+ source => $_source,
+ content => $_content,
+ server => $_server,
+ options => $_options,
+ } -> anchor { "apt_key ${_id} absent": }
}
}
default: {
- fail "Invalid 'ensure' value '$ensure' for aptkey"
+ fail "Invalid 'ensure' value '${ensure}' for apt::key"
}
}
}