From 284c415076464268c4a977aa4526f8b3fb9da1db Mon Sep 17 00:00:00 2001 From: lub Date: Sat, 17 Aug 2019 21:46:10 +0200 Subject: [PATCH] implement Start-IptablesProcess this strips away some splatting boilerplate of the other iptables functions --- expose_forwards.ps1 | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/expose_forwards.ps1 b/expose_forwards.ps1 index 3b79a69..0fea1f9 100644 --- a/expose_forwards.ps1 +++ b/expose_forwards.ps1 @@ -1,6 +1,20 @@ #Requires -Modules powershell-yaml $ErrorActionPreference = 'Stop' +function Start-IptablesProcess { + param ( + [array]$ArgumentList + ) + + $splat = @{ + FilePath = 'iptables' + ArgumentList = $ArgumentList + Wait = $true + PassThru = $true + } + + Start-Process @splat +} function Test-IptablesChain { param ( [string]$Chain, @@ -41,14 +55,7 @@ function Test-IptablesRule { $Chain )+$Rule - $check_splat = @{ - FilePath = 'iptables' - ArgumentList = $argument_list - Wait = $true - PassThru = $true - } - - $check = Start-Process @check_splat + $check = Start-IptablesProcess -ArgumentList $argument_list Write-Output ($check.ExitCode -eq 0) } @@ -66,16 +73,11 @@ function Add-IptablesRule { $Chain )+$Rule - $add_splat = @{ - FilePath = 'iptables' - ArgumentList = $argument_list - Wait = $true - PassThru = $true - } - if(-not (Test-IptablesRule -Chain $Chain -Rule $Rule)) { - $add = Start-Process @add_splat - if(0 -ne $add.ExitCode) { + $add = Start-IptablesProcess -ArgumentList $argument_list + if(0 -eq $add.ExitCode) { + Write-Output $true + } else { Write-Error 'Adding iptables rule failed' } }