Refactor for DRY

This commit is contained in:
Wes Carroll
2020-03-05 21:43:52 -05:00
parent 4c32bbe057
commit bc02e796d6
+11 -15
View File
@@ -160,7 +160,6 @@ function Get-ZertoVpg {
) )
begin { begin {
$baseUri = "vpgs" $baseUri = "vpgs"
$returnObject = @()
} }
Process { Process {
@@ -169,14 +168,13 @@ function Get-ZertoVpg {
# When called with no parameters, return all values # When called with no parameters, return all values
"main" { "main" {
$returnObject = Invoke-ZertoRestRequest -uri $baseUri $uri = $baseUri
} }
# When called with protectionGroupIdentifier, query for each id provided # When called with protectionGroupIdentifier, query for each id provided
"protectionGroupIdentifier" { "protectionGroupIdentifier" {
$returnObject = foreach ( $vpgId in $protectionGroupIdentifier ) { $uri = foreach ( $vpgId in $protectionGroupIdentifier ) {
$uri = "{0}/{1}" -f $baseUri, $vpgId "{0}/{1}" -f $baseUri, $vpgId
Invoke-ZertoRestRequest -uri $uri
} }
} }
@@ -193,21 +191,19 @@ function Get-ZertoVpg {
} }
$filter = Get-ZertoApiFilter -filterTable $filterTable $filter = Get-ZertoApiFilter -filterTable $filterTable
} }
$returnObject = foreach ( $id in $protectionGroupIdentifier ) { $uri = foreach ( $id in $protectionGroupIdentifier ) {
if ( $filter ) { if ( $filter ) {
$uri = "{0}/{1}/checkpoints{2}" -f $baseUri, $id, $filter "{0}/{1}/checkpoints{2}" -f $baseUri, $id, $filter
} else { } else {
$uri = "{0}/{1}/checkpoints" -f $baseUri, $id "{0}/{1}/checkpoints" -f $baseUri, $id
} }
Invoke-ZertoRestRequest -uri $uri
} }
} }
# When stats are requested # When stats are requested
"stats" { "stats" {
$returnObject = foreach ( $id in $protectionGroupIdentifier ) { $uri = foreach ( $id in $protectionGroupIdentifier ) {
$uri = "{0}/{1}/checkpoints/stats" -f $baseUri, $id "{0}/{1}/checkpoints/stats" -f $baseUri, $id
Invoke-ZertoRestRequest -uri $uri
} }
} }
@@ -215,18 +211,18 @@ function Get-ZertoVpg {
"filter" { "filter" {
$filter = Get-ZertoApiFilter -filterTable $PSBoundParameters $filter = Get-ZertoApiFilter -filterTable $PSBoundParameters
$uri = "{0}{1}" -f $baseUri, $filter $uri = "{0}{1}" -f $baseUri, $filter
$returnObject = Invoke-ZertoRestRequest -uri $uri
} }
# Default is to build URI based on ParameterSetName and return results. # Default is to build URI based on ParameterSetName and return results.
default { default {
$uri = "{0}/{1}" -f $baseUri, $PSCmdlet.ParameterSetName.ToLower() $uri = "{0}/{1}" -f $baseUri, $PSCmdlet.ParameterSetName.ToLower()
$returnObject = Invoke-ZertoRestRequest -uri $uri
} }
} }
foreach ($entry in $uri) {
Invoke-ZertoRestRequest -uri $entry
}
} }
End { End {
return $returnObject
} }
} }