diff --git a/PowerFGT/Public/cmdb/system/zone.ps1 b/PowerFGT/Public/cmdb/system/zone.ps1 index b37b72d5..81e6d6cd 100644 --- a/PowerFGT/Public/cmdb/system/zone.ps1 +++ b/PowerFGT/Public/cmdb/system/zone.ps1 @@ -144,6 +144,8 @@ function Add-FGTSystemZone { [string[]]$interfaces, [Parameter(Mandatory = $false)] [string]$description, + [Parameter (Mandatory = $false)] + [hashtable]$data, [Parameter(Mandatory = $false)] [String[]]$vdom, [Parameter(Mandatory = $false)] @@ -193,6 +195,12 @@ function Add-FGTSystemZone { } } + if ( $PsBoundParameters.ContainsKey('data') ) { + $data.GetEnumerator() | ForEach-Object { + $zone | Add-member -name $_.key -membertype NoteProperty -Value $_.value + } + } + Invoke-FGTRestMethod -uri 'api/v2/cmdb/system/zone' -method 'POST' -body $zone -connection $connection @invokeParams | Out-Null Get-FGTSystemZone -name $name -connection $connection @invokeParams @@ -246,6 +254,8 @@ function Set-FGTSystemZone { [string]$description, [Parameter(Mandatory = $false)] [string[]]$interfaces, + [Parameter (Mandatory = $false)] + [hashtable]$data, [Parameter(Mandatory = $false)] [String[]]$vdom, [Parameter(Mandatory = $false)] @@ -301,6 +311,12 @@ function Set-FGTSystemZone { } } + if ( $PsBoundParameters.ContainsKey('data') ) { + $data.GetEnumerator() | ForEach-Object { + $zone_body | Add-member -name $_.key -membertype NoteProperty -Value $_.value + } + } + if ($PSCmdlet.ShouldProcess($zone.name, 'Set zone')) { Invoke-FGTRestMethod -uri "api/v2/cmdb/system/zone" -uri_escape $zone.name -method 'PUT' -body $zone_body -connection $connection @invokeParams | Out-Null Get-FGTSystemZone -name $name -connection $connection @invokeParams diff --git a/Tests/integration/SystemZone.Tests.ps1 b/Tests/integration/SystemZone.Tests.ps1 index 2fab5414..596db069 100644 --- a/Tests/integration/SystemZone.Tests.ps1 +++ b/Tests/integration/SystemZone.Tests.ps1 @@ -125,6 +125,16 @@ Describe "Add zone" { $zone.interface."interface-name" | Should -BeIn $pester_port1, $pester_port2 } + It "Add zone $pester_zone1 with -data" { + $data = @{ 'intrazone' = "allow" } + Add-FGTSystemZone -name $pester_zone1 -interfaces $pester_port1 -data $data + $zone = Get-FGTSystemZone -name $pester_zone1 + $zone.name | Should -Be $pester_zone1 + $zone.intrazone | Should -Be "allow" + $zone.interface.count | Should -Be 1 + $zone.interface."interface-name" | Should -BeIn $pester_port1 + } + It "Try to add zone $pester_zone1 (but there is already an object with same name)" { #Add first zone Add-FGTSystemZone -name $pester_zone1 -interfaces $pester_port1 @@ -174,6 +184,13 @@ Describe "Set zone" { $zone.interface."interface-name" | Should -BeIn $pester_port3, $pester_port4 } + It "Change with -data " { + $data = @{ 'intrazone' = "allow" } + Get-FGTSystemZone -name $pester_zone1 | Set-FGTSystemZone -data $data + $zone = Get-FGTSystemZone -name $pester_zone1 + $zone.intrazone | Should -Be "allow" + } + It "Remove interfaces" -Skip:$VersionIs64 { Get-FGTSystemZone -name $pester_zone1 | Set-FGTSystemZone -interfaces none $zone = Get-FGTSystemZone -name $pester_zone1