(FM-7316) - i18n Process implemented and .pot file generated
[puppet-modules/puppetlabs-apt.git] / manifests / source.pp
index be743eb26ca207fc9a3c2b09f82a52caff3ae494..981933d0c21ce4d7b1b8664fa5f47b75d038c79f 100644 (file)
@@ -1,20 +1,19 @@
 # source.pp
 # add an apt source
 define apt::source(
-  Optional[String] $location           = undef,
-  String $comment                      = $name,
-  String $ensure                       = present,
-  Optional[String] $release            = undef,
-  String $repos                        = 'main',
-  Optional[Variant[Hash]] $include     = {},
-  Optional[Variant[String, Hash]] $key = undef,
-  $pin                                 = undef,
-  Optional[String] $architecture       = undef,
-  Boolean $allow_unsigned              = false,
-  Boolean $notify_update               = true,
+  Optional[String] $location                    = undef,
+  String $comment                               = $name,
+  String $ensure                                = present,
+  Optional[String] $release                     = undef,
+  String $repos                                 = 'main',
+  Optional[Variant[Hash]] $include              = {},
+  Optional[Variant[String, Hash]] $key          = undef,
+  Optional[Variant[Hash, Numeric, String]] $pin = undef,
+  Optional[String] $architecture                = undef,
+  Boolean $allow_unsigned                       = false,
+  Boolean $notify_update                        = true,
 ) {
 
-  # This is needed for compat with 1.8.x
   include ::apt
 
   $_before = Apt::Setting["list-${title}"]
@@ -23,27 +22,33 @@ define apt::source(
     if $facts['lsbdistcodename'] {
       $_release = $facts['lsbdistcodename']
     } else {
-      fail('lsbdistcodename fact not available: release parameter required')
+      fail(translate('lsbdistcodename fact not available: release parameter required'))
     }
   } else {
     $_release = $release
   }
 
-  if $ensure == 'present' and ! $location {
-    fail('cannot create a source entry without specifying a location')
+  if $ensure == 'present' {
+    if ! $location {
+      fail(translate('cannot create a source entry without specifying a location'))
+    }
+    # Newer oses, do not need the package for HTTPS transport.
+    $_transport_https_releases = [ 'wheezy', 'jessie', 'stretch', 'trusty', 'xenial' ]
+    if $_release in $_transport_https_releases and $location =~ /(?i:^https:\/\/)/ {
+      ensure_packages('apt-transport-https')
+    }
   }
 
   $includes = merge($::apt::include_defaults, $include)
 
   if $key {
-    if is_hash($key) {
+    if $key =~ Hash {
       unless $key['id'] {
-        fail('key hash must contain at least an id entry')
+        fail(translate('key hash must contain at least an id entry'))
       }
       $_key = merge($::apt::source_key_defaults, $key)
     } else {
-      validate_legacy(String, 'validate_string', $key)
-      $_key = { 'id' => $key }
+      $_key = { 'id' => assert_type(String[1], $key) }
     }
   }
 
@@ -66,9 +71,9 @@ define apt::source(
   }
 
   if $pin {
-    if is_hash($pin) {
+    if $pin =~ Hash {
       $_pin = merge($pin, { 'ensure' => $ensure, 'before' => $_before })
-    } elsif (is_numeric($pin) or is_string($pin)) {
+    } elsif ($pin =~ Numeric or $pin =~ String) {
       $url_split = split($location, '[:\/]+')
       $host      = $url_split[1]
       $_pin = {
@@ -78,14 +83,14 @@ define apt::source(
         'origin'   => $host,
       }
     } else {
-      fail('Received invalid value for pin parameter')
+      fail(translate('Received invalid value for pin parameter'))
     }
     create_resources('apt::pin', { "${name}" => $_pin })
   }
 
   # We do not want to remove keys when the source is absent.
   if $key and ($ensure == 'present') {
-    if is_hash($_key) {
+    if $_key =~ Hash {
       apt::key { "Add key: ${$_key['id']} from Apt::Source ${title}":
         ensure  => present,
         id      => $_key['id'],