Skip to content

Commit

Permalink
Get-FGTMonitorSystemConfigBackup: Add scope vdom (#272)
Browse files Browse the repository at this point in the history
Fix #271
  • Loading branch information
johan-kummeneje-complior authored Jan 3, 2025
1 parent bf72445 commit 1199398
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions PowerFGT/Public/monitor/system/config/backup.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#
#
# Copyright 2022, Alexis La Goutte <alexis dot lagoutte at gmail dot com>
#
# SPDX-License-Identifier: Apache-2.0
Expand Down Expand Up @@ -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(
Expand All @@ -34,33 +39,43 @@ 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
)

Begin {
}

Process {

$invokeParams = @{ }

if ( $PsBoundParameters.ContainsKey('skip') ) {
$invokeParams.add( 'skip', $skip )
$invokeParams.add('skip', $skip)
}
if ( $PsBoundParameters.ContainsKey('vdom') ) {
$invokeParams.add( 'vdom', $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=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"
}
}

Expand Down

0 comments on commit 1199398

Please sign in to comment.