From 400f12d52e234b2e78ffa1480470d4bb63eedaf7 Mon Sep 17 00:00:00 2001 From: johan-kummeneje-complior <142219132+johan-kummeneje-complior@users.noreply.github.com> Date: Mon, 14 Oct 2024 21:47:01 +0200 Subject: [PATCH 1/2] Update backup.ps1 Fixing issue 271 --- PowerFGT/Public/monitor/system/config/backup.ps1 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/PowerFGT/Public/monitor/system/config/backup.ps1 b/PowerFGT/Public/monitor/system/config/backup.ps1 index 2ae22cd17..c9842f181 100644 --- a/PowerFGT/Public/monitor/system/config/backup.ps1 +++ b/PowerFGT/Public/monitor/system/config/backup.ps1 @@ -1,4 +1,4 @@ -# +# # Copyright 2022, Alexis La Goutte # # SPDX-License-Identifier: Apache-2.0 @@ -42,28 +42,29 @@ function Get-FGTMonitorSystemConfigBackup { Process { + $scope="global" $invokeParams = @{ } if ( $PsBoundParameters.ContainsKey('skip') ) { $invokeParams.add( 'skip', $skip ) } if ( $PsBoundParameters.ContainsKey('vdom') ) { $invokeParams.add( 'vdom', $vdom ) + $scope="vdom" } #before 7.6.x, config/backup is available with get method and using paramater if ($connection.version -lt "7.6.0") { $method = "get" - $uri = 'api/v2/monitor/system/config/backup?scope=global' + $uri = "api/v2/monitor/system/config/backup?scope=$scope" $body = "" } else { $method = "post" $uri = 'api/v2/monitor/system/config/backup' $body = @{ - "scope" = "global" + "scope" = "$scope" } } - $response = Invoke-FGTRestMethod -uri $uri -method $method -body $body -connection $connection @invokeParams $response } From 197c92a12c09fd76e98f679cee11ab8398a5dab7 Mon Sep 17 00:00:00 2001 From: johan-kummeneje-complior <142219132+johan-kummeneje-complior@users.noreply.github.com> Date: Sat, 26 Oct 2024 20:09:35 +0200 Subject: [PATCH 2/2] Update backup.ps1 Update accordingly with Alexis suggestion on scope param --- .../Public/monitor/system/config/backup.ps1 | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/PowerFGT/Public/monitor/system/config/backup.ps1 b/PowerFGT/Public/monitor/system/config/backup.ps1 index c9842f181..54f6bda02 100644 --- a/PowerFGT/Public/monitor/system/config/backup.ps1 +++ b/PowerFGT/Public/monitor/system/config/backup.ps1 @@ -26,6 +26,11 @@ function Get-FGTMonitorSystemConfigBackup { Get-FGTMonitorSystemConfigBackup -vdom vdomX Get System Config Backup on vdomX + + .EXAMPLE + Get-FGTMonitorSystemConfigBackup -scope global -vdom vdomX + + Get System Config Backup in global scope even if vdom is specified #> Param( @@ -34,6 +39,9 @@ function Get-FGTMonitorSystemConfigBackup { [Parameter(Mandatory = $false)] [String[]]$vdom, [Parameter(Mandatory = $false)] + [ValidateSet("global", "vdom")] + [string]$scope = "global", # Scope parameter with default "global" + [Parameter(Mandatory = $false)] [psobject]$connection = $DefaultFGTConnection ) @@ -41,18 +49,23 @@ function Get-FGTMonitorSystemConfigBackup { } Process { - - $scope="global" $invokeParams = @{ } + if ( $PsBoundParameters.ContainsKey('skip') ) { - $invokeParams.add( 'skip', $skip ) + $invokeParams.add('skip', $skip) } - if ( $PsBoundParameters.ContainsKey('vdom') ) { - $invokeParams.add( 'vdom', $vdom ) - $scope="vdom" + + # Add vdom to invokeParams if provided + if ($PsBoundParameters.ContainsKey('vdom')) { + $invokeParams.add('vdom', $vdom) + + # Only change scope to "vdom" if vdom is provided and scope was not explicitly set to "global" + if (-not $PsBoundParameters.ContainsKey('scope') -or $scope -eq "vdom") { + $scope = "vdom" + } } - #before 7.6.x, config/backup is available with get method and using paramater + # Prepare URI and request method based on connection version if ($connection.version -lt "7.6.0") { $method = "get" $uri = "api/v2/monitor/system/config/backup?scope=$scope" @@ -65,6 +78,7 @@ function Get-FGTMonitorSystemConfigBackup { "scope" = "$scope" } } + $response = Invoke-FGTRestMethod -uri $uri -method $method -body $body -connection $connection @invokeParams $response }