Skip to content

Commit

Permalink
Merge pull request #172 from jfroche/enhancement/remove_validate
Browse files Browse the repository at this point in the history
Use types and remove validate
  • Loading branch information
crayfishx authored Jun 13, 2018
2 parents 77bbdca + 9faf3fd commit 3d70a1d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ fixtures:
forge_modules:
stdlib:
repo: puppetlabs/stdlib
ref: 4.12.0
ref: 4.25.1
symlinks:
firewalld: "#{source_dir}"

42 changes: 14 additions & 28 deletions manifests/custom_service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"dependencies": [
{
"name": "puppetlabs/stdlib",
"version_requirement": ">=4.2.0 <5.0.0"
"version_requirement": ">=4.25.0 <5.0.0"
}
]
}
Expand Down

0 comments on commit 3d70a1d

Please sign in to comment.