From 995aea474b9b805f37b5d8e3c17636fcb1f6335f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Tarti=C3=A8re?= Date: Wed, 6 Oct 2021 15:45:39 -1000 Subject: [PATCH] Simplify some code duplication Latest refactoring make it possible to simplfy this code. --- manifests/server/iterate_access.pp | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/manifests/server/iterate_access.pp b/manifests/server/iterate_access.pp index 4dd86322..4d687c7b 100644 --- a/manifests/server/iterate_access.pp +++ b/manifests/server/iterate_access.pp @@ -14,26 +14,17 @@ fail('$access variable must be an array') } - if $position == 0 { # the first entry + $previous_position = $position - 1 - openldap::server::access { "${position} on ${suffix}" : - what => $what, - access => $access, - } - } elsif $position == $count { #the last entry - - $previous_position = $position - 1 - openldap::server::access { "${position} on ${suffix}" : - what => $what, - access => $access, - require => Openldap::Server::Access["${previous_position} on ${suffix}"], - } + if $previous_position < 0 { + $require = [] } else { - $previous_position = $position - 1 - openldap::server::access { "${position} on ${suffix}" : - what => $what, - access => $access, - require => Openldap::Server::Access["${previous_position} on ${suffix}"], - } + $require = Openldap::Server::Access["${previous_position} on ${suffix}"] + } + + openldap::server::access { "${position} on ${suffix}" : + what => $what, + access => $access, + require => $require, } }