Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable using nested arrays for parameter 'set' #49

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions manifests/set.pp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
# }
#
# @example setup multiple ipsets based on a hiera hash with multiple arrays and multiple IPv4/IPv6 prefixes. Use the voxpupuli/ferm module to create suitable iptables rules.
# $ip_ranges = lookup('ip_net_vlans').flatten.unique
# $ip_ranges = lookup('ip_net_vlans')
# $ip_ranges_ipv4 = $ip_ranges.filter |$ip_range| { $ip_range =~ Stdlib::IP::Address::V4 }
# $ip_ranges_ipv6 = $ip_ranges.filter |$ip_range| { $ip_range =~ Stdlib::IP::Address::V6 }
#
Expand Down Expand Up @@ -108,7 +108,7 @@
# content
case $set {
IPSet::Set::Array: { # lint:ignore:unquoted_string_in_case
$new_set = join($set, "\n")
$new_set = join(flatten($set).unique, "\n")
# create file with ipset, one record per line
file { "${config_path}/${title}.set":
ensure => file,
Expand Down
19 changes: 19 additions & 0 deletions spec/acceptance/ipset_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,25 @@
end
end

context 'with a nested array' do
it 'handles nested arrays with no errors' do
pp = <<-EOS
include ipset
ipset::set{'nested-set':
set => ['10.0.0.1', ['10.0.0.2', '10.0.0.42']],
type => 'hash:net',
}
EOS
# Run it twice and test for idempotency
apply_manifest(pp, catch_failures: true)
apply_manifest(pp, catch_changes: true)
end

describe command('ipset list basic-set') do
its(:stdout) { is_expected.to match %r{.*basic-set.*Type: hash:net.*10\.0\.0\.2.*}m }
end
end

context 'can delete ipsets' do
it 'works even here idempotently with no errors' do
pp = <<-EOS
Expand Down
4 changes: 2 additions & 2 deletions types/set/array.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#
# @summary type to allow an array of ip addresses
# @summary type to allow nested arrays of ip addresses
#
type IPSet::Set::Array = Array[String]
type IPSet::Set::Array = Variant[Array, String[1]]