From 9faf3fd332f6b64619d23b726015e84bad643fa2 Mon Sep 17 00:00:00 2001 From: Jean-Francois Roche Date: Fri, 6 Apr 2018 14:28:45 +0200 Subject: [PATCH] Use types and remove validate --- .fixtures.yml | 2 +- manifests/custom_service.pp | 42 +++++++++++++------------------------ metadata.json | 2 +- 3 files changed, 16 insertions(+), 30 deletions(-) diff --git a/.fixtures.yml b/.fixtures.yml index aaf34f25..05aef480 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -3,7 +3,7 @@ fixtures: forge_modules: stdlib: repo: puppetlabs/stdlib - ref: 4.12.0 + ref: 4.25.1 symlinks: firewalld: "#{source_dir}" diff --git a/manifests/custom_service.pp b/manifests/custom_service.pp index f986488d..dcd49156 100644 --- a/manifests/custom_service.pp +++ b/manifests/custom_service.pp @@ -32,36 +32,22 @@ # # define firewalld::custom_service ( - $short = $name, - $description = undef, - $port = undef, # Should be an array of hashes - $module = undef, # Should be an array of strings - $destination = undef, - $filename = undef, - $config_dir = '/etc/firewalld/services', - $ensure = 'present', + String $short = $name, + Optional[String] $description = undef, + Optional[Array[Hash]] $port = undef, + Optional[Array[String]] $module = undef, + Optional[Hash[ + Enum['ipv4', 'ipv6'], + String + ]] $destination = undef, + String $filename = $short, + Stdlib::Unixpath $config_dir = '/etc/firewalld/services', + Enum['present', + 'absent' + ] $ensure = 'present', ) { - validate_string($short) - - $x_filename = $filename ? { - undef => $short, - default => $filename, - } - - if $description != undef {validate_string($description)} - if $module != undef {validate_array($module)} - if $port != undef {validate_array($port)} - if $destination != undef { - validate_hash($destination) - - if !has_key($destination, 'ipv4') and !has_key($destination, 'ipv6'){ - fail('Parameter destination must contain at least one of "ipv4" and/or "ipv6" as keys in the hash') - } - } - validate_absolute_path($config_dir) - - file{"${config_dir}/${x_filename}.xml": + file{"${config_dir}/${filename}.xml": ensure => $ensure, content => template('firewalld/service.xml.erb'), mode => '0644', diff --git a/metadata.json b/metadata.json index b897daa3..15f177be 100644 --- a/metadata.json +++ b/metadata.json @@ -27,7 +27,7 @@ "dependencies": [ { "name": "puppetlabs/stdlib", - "version_requirement": ">=4.2.0 <5.0.0" + "version_requirement": ">=4.25.0 <5.0.0" } ] }