From b68077e4c38c586cfc0eef1bceb55099f437909f Mon Sep 17 00:00:00 2001 From: Brian Wuchner Date: Tue, 20 Dec 2022 08:52:34 -0500 Subject: [PATCH] Updating module to resolve duplicate object bug When passing in objects to Get-SkylineAffectedObject, it was possible for duplicate queries to be invoked for the same product. This commit fixes that by moving some of the string manipulation inside the correct loop for this function. Additionally, the text replace lines were consolidated to reduce some confusion with variable assignment that led to this bug in the first place. Signed-off-by: Brian Wuchner --- .../VMware.Skyline.InsightsApi.psd1 | 2 +- .../VMware.Skyline.InsightsApi.psm1 | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Modules/VMware.Skyline.InsightsApi/VMware.Skyline.InsightsApi.psd1 b/Modules/VMware.Skyline.InsightsApi/VMware.Skyline.InsightsApi.psd1 index 2eb6425..d43065e 100644 --- a/Modules/VMware.Skyline.InsightsApi/VMware.Skyline.InsightsApi.psd1 +++ b/Modules/VMware.Skyline.InsightsApi/VMware.Skyline.InsightsApi.psd1 @@ -17,7 +17,7 @@ SPDX-License-Identifier: BSD-2-Clause RootModule = 'VMware.Skyline.InsightsApi.psm1' # Version number of this module. -ModuleVersion = '1.0.0' +ModuleVersion = '1.0.1' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/Modules/VMware.Skyline.InsightsApi/VMware.Skyline.InsightsApi.psm1 b/Modules/VMware.Skyline.InsightsApi/VMware.Skyline.InsightsApi.psm1 index 8349088..a03e159 100644 --- a/Modules/VMware.Skyline.InsightsApi/VMware.Skyline.InsightsApi.psm1 +++ b/Modules/VMware.Skyline.InsightsApi/VMware.Skyline.InsightsApi.psm1 @@ -237,10 +237,9 @@ Function Get-SkylineFinding { # Try to get results the first time $results = @() - $thisQueryBody = $queryBody -Replace 'filter: {}', "filter: { $filterString }" $thisIteration = 0 do { - $thisQueryBody = $thisQueryBody -Replace 'start: 0', "start: $thisIteration" + $thisQueryBody = $queryBody -Replace 'filter: {}', "filter: { $filterString }" -Replace 'start: 0', "start: $thisIteration" Write-Debug $thisQueryBody $thisResult = Invoke-SkylineInsightsApi -queryBody (@{'query' = $thisQueryBody} | ConvertTo-Json -Compress) $totalRecords = $thisResult.data.activeFindings.totalRecords @@ -325,13 +324,11 @@ Function Get-SkylineAffectedObject { } process { - $thisQueryBody = $queryBody -Replace 'findingId: "",', "findingId: `"$findingId`"," foreach ( $thisProduct in $products ) { $thisIteration = 0 $results = @() # reset results variable between products do { - $thisQueryBody = $thisQueryBody -Replace 'product: "",', "product: `"$thisProduct`"," - $thisQueryBody = $thisQueryBody -Replace 'start: 0', "start: $thisIteration" + $thisQueryBody = $queryBody -Replace 'product: "",', "product: `"$thisProduct`"," -Replace 'start: 0', "start: $thisIteration" -Replace 'findingId: "",', "findingId: `"$findingId`"," Write-Debug $thisQueryBody $thisResult = Invoke-SkylineInsightsApi -queryBody (@{'query' = $thisQueryBody} | ConvertTo-Json -Compress) $totalRecords = $thisResult.data.activeFindings.Findings.totalAffectedObjectsCount