From 7213b4cf2258edde8489cbb7d3ac62a7af7ae712 Mon Sep 17 00:00:00 2001 From: Pepe Rivera Date: Wed, 12 Jun 2024 16:27:50 -0700 Subject: [PATCH 1/4] Revert "Follow-up fixes for 257 (#260)" This reverts commit ae96fc2300621d0cd5b19eee2d9a55156393167c. --- StoreBroker.psd1 | 2 +- StoreBroker/Helpers.ps1 | 34 +++++++++++++--------------------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/StoreBroker.psd1 b/StoreBroker.psd1 index a1ae6d5..98ee237 100644 --- a/StoreBroker.psd1 +++ b/StoreBroker.psd1 @@ -7,7 +7,7 @@ CompanyName = 'Microsoft Corporation' Copyright = 'Copyright (C) Microsoft Corporation. All rights reserved.' - ModuleVersion = '2.1.21' + ModuleVersion = '2.1.20' Description = 'Provides command-line access to the Windows Store Submission REST API.' RootModule = 'StoreBroker/StoreIngestionApi.psm1' diff --git a/StoreBroker/Helpers.ps1 b/StoreBroker/Helpers.ps1 index 3b32065..2071202 100644 --- a/StoreBroker/Helpers.ps1 +++ b/StoreBroker/Helpers.ps1 @@ -691,39 +691,31 @@ function Copy-InputObjectForLogging if ($InputObject -is [hashtable]) { - $replacedInputObject = DeepCopy-Object -InputObject $InputObject # Get a new instance, not a reference + $ReplacedInputObject = $InputObject.Clone() # Get a new instance, not a reference - foreach ($key in @($replacedInputObject.Keys)) + foreach ($key in @($ReplacedInputObject.keys)) { if ($key -in $script:alwaysRedactHashPropertiesForLogging) { - $replacedInputObject[$key] = "" - } - elseif (($replacedInputObject.$key -is [PSCustomObject]) -or ($replacedInputObject.$key -is [hashtable])) - { - $replacedInputObject[$key] = Copy-InputObjectForLogging -InputObject $replacedInputObject.$key + $ReplacedInputObject[$key] = "" } } - return $replacedInputObject; + return $ReplacedInputObject; } elseif ($InputObject -is [PSCustomObject]) { - $replacedInputObject = DeepCopy-Object -InputObject $InputObject # Get a new instance, not a reference + $ReplacedInputObject = $InputObject.PSObject.Copy() # Get a new instance, not a reference - foreach ($key in $replacedInputObject.PSObject.Properties.Name) + foreach ($key in $script:alwaysRedactHashPropertiesForLogging) { - if ($key -in $script:alwaysRedactHashPropertiesForLogging) - { - $replacedInputObject.$key = "" - } - elseif (($replacedInputObject.$key -is [PSCustomObject]) -or ($replacedInputObject.$key -is [hashtable])) + if ($null -ne (Get-Member -InputObject $ReplacedInputObject -Name $key -MemberType Properties)) { - $replacedInputObject.$key = Copy-InputObjectForLogging -InputObject $replacedInputObject.$key + $ReplacedInputObject.$key = "" } } - return $replacedInputObject; + return $ReplacedInputObject; } else { @@ -762,18 +754,18 @@ function Write-InputObject if ($null -eq $InputObject) { - Write-Log -Message "$($Description): `$null" -Level Verbose + Write-Log -Message "$($Description): $null" -Level Verbose return } - $replacedObject = Copy-InputObjectForLogging -InputObject $InputObject + $ReplacedObject = Copy-InputObjectForLogging -InputObject $InputObject - if ($null -eq $replacedObject) + if ($null -eq $ReplacedObject) { return; } - $objectAsString = Get-JsonBody -InputObject $replacedObject + $objectAsString = Get-JsonBody -InputObject $ReplacedObject Write-Log -Message "$($Description): $objectAsString" -Level Verbose } From e7fa20b991598adecb85fff2810412614c8aad91 Mon Sep 17 00:00:00 2001 From: Pepe Rivera Date: Wed, 12 Jun 2024 16:29:53 -0700 Subject: [PATCH 2/4] Fix version --- StoreBroker.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/StoreBroker.psd1 b/StoreBroker.psd1 index 98ee237..1a53a54 100644 --- a/StoreBroker.psd1 +++ b/StoreBroker.psd1 @@ -7,7 +7,7 @@ CompanyName = 'Microsoft Corporation' Copyright = 'Copyright (C) Microsoft Corporation. All rights reserved.' - ModuleVersion = '2.1.20' + ModuleVersion = '2.1.22' Description = 'Provides command-line access to the Windows Store Submission REST API.' RootModule = 'StoreBroker/StoreIngestionApi.psm1' From 79b7d4980ca6cc5695699abf603b47e67c0c2692 Mon Sep 17 00:00:00 2001 From: Pepe Rivera Date: Thu, 13 Jun 2024 10:47:01 -0700 Subject: [PATCH 3/4] Reintroduce deep copy --- StoreBroker/Helpers.ps1 | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/StoreBroker/Helpers.ps1 b/StoreBroker/Helpers.ps1 index 2071202..37157a1 100644 --- a/StoreBroker/Helpers.ps1 +++ b/StoreBroker/Helpers.ps1 @@ -669,13 +669,10 @@ function Copy-InputObjectForLogging <# .SYNOPSIS Creates a copy of the InputObject and redacts some of its contents for logging. - .DESCRIPTION Creates a copy of the InputObject and redacts some of its contents for logging. - .PARAMETER InputObject Object to replace. - .EXAMPLE $redactedObject = Copy-InputObjectForLogging -InputObject $MyObject @@ -691,34 +688,42 @@ function Copy-InputObjectForLogging if ($InputObject -is [hashtable]) { - $ReplacedInputObject = $InputObject.Clone() # Get a new instance, not a reference + $replacedInputObject = $InputObject.Clone() # Get a new instance, not a reference - foreach ($key in @($ReplacedInputObject.keys)) + foreach ($key in @($replacedInputObject.Keys)) { if ($key -in $script:alwaysRedactHashPropertiesForLogging) { - $ReplacedInputObject[$key] = "" + $replacedInputObject[$key] = "" + } + elseif (($replacedInputObject.$key -is [PSCustomObject]) -or ($replacedInputObject.$key -is [hashtable])) + { + $replacedInputObject[$key] = Copy-InputObjectForLogging -InputObject $replacedInputObject.$key } } - return $ReplacedInputObject; + return $replacedInputObject; } elseif ($InputObject -is [PSCustomObject]) { - $ReplacedInputObject = $InputObject.PSObject.Copy() # Get a new instance, not a reference - - foreach ($key in $script:alwaysRedactHashPropertiesForLogging) + $replacedInputObject = $InputObject.PSObject.Copy() + + foreach ($key in $replacedInputObject.PSObject.Properties.Name) { - if ($null -ne (Get-Member -InputObject $ReplacedInputObject -Name $key -MemberType Properties)) + if ($key -in $script:alwaysRedactHashPropertiesForLogging) { - $ReplacedInputObject.$key = "" + $replacedInputObject.$key = "" + } + elseif (($replacedInputObject.$key -is [PSCustomObject]) -or ($replacedInputObject.$key -is [hashtable])) + { + $replacedInputObject.$key = Copy-InputObjectForLogging -InputObject $replacedInputObject.$key } } - return $ReplacedInputObject; + return $replacedInputObject; } else - { + { # Unsupported object type, return null; return $null; } @@ -754,18 +759,18 @@ function Write-InputObject if ($null -eq $InputObject) { - Write-Log -Message "$($Description): $null" -Level Verbose + Write-Log -Message "$($Description): `$null" -Level Verbose return } - $ReplacedObject = Copy-InputObjectForLogging -InputObject $InputObject + $replacedObject = Copy-InputObjectForLogging -InputObject $InputObject - if ($null -eq $ReplacedObject) + if ($null -eq $replacedObject) { return; } - $objectAsString = Get-JsonBody -InputObject $ReplacedObject + $objectAsString = Get-JsonBody -InputObject $replacedObject Write-Log -Message "$($Description): $objectAsString" -Level Verbose } From d7e744905cfd0bb4f6f6df30276e572183d0e7a5 Mon Sep 17 00:00:00 2001 From: Pepe Rivera Date: Thu, 13 Jun 2024 10:51:11 -0700 Subject: [PATCH 4/4] clean up --- StoreBroker/Helpers.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/StoreBroker/Helpers.ps1 b/StoreBroker/Helpers.ps1 index 37157a1..76f869c 100644 --- a/StoreBroker/Helpers.ps1 +++ b/StoreBroker/Helpers.ps1 @@ -669,10 +669,13 @@ function Copy-InputObjectForLogging <# .SYNOPSIS Creates a copy of the InputObject and redacts some of its contents for logging. + .DESCRIPTION Creates a copy of the InputObject and redacts some of its contents for logging. + .PARAMETER InputObject Object to replace. + .EXAMPLE $redactedObject = Copy-InputObjectForLogging -InputObject $MyObject @@ -723,7 +726,7 @@ function Copy-InputObjectForLogging return $replacedInputObject; } else - { + { # Unsupported object type, return null; return $null; }