]> review.fuel-infra Code Review - puppet-modules/puppetlabs-apt.git/commitdiff
Merge pull request #773 from ekohl/apt-proxy-type
authorHelen <helen@puppetlabs.com>
Fri, 24 Aug 2018 14:53:23 +0000 (15:53 +0100)
committerGitHub <noreply@github.com>
Fri, 24 Aug 2018 14:53:23 +0000 (15:53 +0100)
Introduce an Apt::Proxy type to validate the hash

README.md
manifests/init.pp
types/proxy.pp [new file with mode: 0644]

index 9af6b9af8b32935fe99c436a46ef152b2fcf7b59..ef9989412ddf6b78beb0a0ab15d68aca3b53e17c 100644 (file)
--- a/README.md
+++ b/README.md
@@ -280,6 +280,7 @@ class { 'apt':
 * [`apt::ppa`](#defined-type-aptppa)
 * [`apt::setting`](#defined-type-aptsetting)
 * [`apt::source`](#defined-type-aptsource)
+* [`apt::proxy`](#defined-type-aptproxy)
 
 ### Types
 
@@ -321,17 +322,7 @@ All parameters are optional unless specified.
 
 * `ppas`: Creates new `apt::ppa` resources. Valid options: a hash to be passed to the [`create_resources` function](https://docs.puppetlabs.com/references/latest/function.html#createresources). Default: {}.
 
-* `proxy`: Configures Apt to connect to a proxy server. Valid options: a hash made up from the following keys:
-
-  * `host`: Specifies a proxy host to be stored in `/etc/apt/apt.conf.d/01proxy`. Valid options: a string containing a hostname. Default: undef.
-
-  * `port`: Specifies a proxy port to be stored in `/etc/apt/apt.conf.d/01proxy`. Valid options: an integer containing a port number. Default: 8080.
-
-  * `https`: Specifies whether to enable https proxies. Valid options: `true` and `false`. Default: `false`.
-
-  * `ensure`: Optional parameter. Valid options: 'file', 'present', and 'absent'. Default: `undef`. Prefer 'file' over 'present'.
-
-  * `direct`: Specifies whether or not to use a 'DIRECT' https proxy if http proxy is used but https is not. Valid options: `true` and `false`. Default: `false`.
+* `proxy`: Configures Apt to connect to a proxy server. Valid options: a hash matching the locally defined type [`apt::proxy`](#defined-type-aptproxy).
 
 * `purge`: Specifies whether to purge any existing settings that aren't managed by Puppet. Valid options: a hash made up from the following keys:
 
@@ -546,13 +537,31 @@ Manages the GPG keys that Apt uses to authenticate packages.
 
 All parameters are optional.
 
-* `content`: Supplies the entire GPG key. Useful in case the key can't be fetched from a remote location and using a file resource is inconvenient. Cannot be used in combination with `source`. Valid options: a string. Default: undef.
+* `content`: Supplies the entire GPG key. Useful in case the key can't be fetched from a remote location and using a file resource is inconvenient. Cannot be used in combination with `source`. Valid options: a string. Default: `undef`.
 
-* `options`: Passes additional options to `apt-key adv --keyserver-options`. Valid options: a string. Default: undef.
+* `options`: Passes additional options to `apt-key adv --keyserver-options`. Valid options: a string. Default: `undef`.
+
+* `server`: Specifies a keyserver to provide Puppet's GPG key. Valid options: a string containing a domain name or a full URL. Default: `keyserver.ubuntu.com`.
+
+* `source`: Specifies the location of an existing GPG key file to copy. Cannot be used in combination with `content`. Valid options: a string containing a URL (ftp://, http://, or https://) or an absolute path. Default: `undef`.
+
+#### Defined Type: `apt::proxy`
+
+Configures Apt to connect to a proxy server.
+
+##### Parameters
+
+All parameters are optional.
+
+* `host`: *Optional.* Specifies a proxy host to be stored in `/etc/apt/apt.conf.d/01proxy`. Valid options: a string containing a hostname. Default: `undef`.
+
+* `port`: *Optional.* Specifies a proxy port to be stored in `/etc/apt/apt.conf.d/01proxy`. Valid options: an integer containing a port number. Default: `8080`.
+
+* `https`: *Optional.* Specifies whether to enable https proxies. Valid options: `true` and `false`. Default: `false`.
 
-* `server`: Specifies a keyserver to provide Puppet's GPG key. Valid options: a string containing a domain name or a full URL. Default: 'keyserver.ubuntu.com'.
+* `direct`: *Optional.* Specifies whether or not to use a `DIRECT` https proxy if http proxy is used but https is not. Valid options: `true` and `false`. Default: `false`.
 
-* `source`: Specifies the location of an existing GPG key file to copy. Cannot be used in combination with `content`. Valid options: a string containing a URL (ftp://, http://, or https://) or an absolute path. Default: undef.
+* `ensure`: *Optional.* Specifies whether the proxy should exist. Valid options: 'file', 'present', and 'absent'. Default: undef. Prefer 'file' over 'present'.
 
 ## Limitations
 
index 06dc0acf458e07155db933198999552340489467..8aa8c6bb660367a61b3486eb2ada0f06901bb64f 100644 (file)
@@ -15,7 +15,7 @@ class apt (
   Hash $confs                   = $apt::params::confs,
   Hash $update                  = $apt::params::update,
   Hash $purge                   = $apt::params::purge,
-  Hash $proxy                   = $apt::params::proxy,
+  Apt::Proxy $proxy             = $apt::params::proxy,
   Hash $sources                 = $apt::params::sources,
   Hash $keys                    = $apt::params::keys,
   Hash $ppas                    = $apt::params::ppas,
@@ -67,23 +67,6 @@ class apt (
   }
 
   $_purge = merge($::apt::purge_defaults, $purge)
-
-  if $proxy['ensure'] {
-    assert_type(Enum['file', 'present', 'absent'], $proxy['ensure'])
-  }
-  if $proxy['host'] {
-    assert_type(String, $proxy['host'])
-  }
-  if $proxy['port'] {
-    assert_type(Integer, $proxy['port'])
-  }
-  if $proxy['https']{
-    assert_type(Boolean, $proxy['https'])
-  }
-  if $proxy['direct']{
-    assert_type(Boolean, $proxy['direct'])
-  }
-
   $_proxy = merge($apt::proxy_defaults, $proxy)
 
   $confheadertmp = epp('apt/_conf_header.epp')
diff --git a/types/proxy.pp b/types/proxy.pp
new file mode 100644 (file)
index 0000000..297bf1b
--- /dev/null
@@ -0,0 +1,9 @@
+type Apt::Proxy = Struct[
+  {
+    ensure => Optional[Enum['file', 'present', 'absent']],
+    host   => Optional[String],
+    port   => Optional[Integer[0, 65535]],
+    https  => Optional[Boolean],
+    direct => Optional[Boolean],
+  }
+]