From 6daf14857efdd4fbd7b08b61d8fbcd8bd23b05cf Mon Sep 17 00:00:00 2001 From: Elle <10051455+BatmanAMA@users.noreply.github.com> Date: Wed, 15 May 2019 12:57:47 -0500 Subject: [PATCH] v2.3.3 * Add debugging. Remove fancy error stuff. * Modify PATCH property value tests (#25) (thanks Makwa) --- README.md | 1 + appveyor.yml | 2 +- module/Public/Invoke-nbApi.ps1 | 21 +++++++++------------ module/Public/Set-nbObject.ps1 | 12 ++++++++++-- module/Version | 2 +- module/powerbox.psd1 | 2 +- 6 files changed, 23 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 8087ea4..69197a7 100644 --- a/README.md +++ b/README.md @@ -40,3 +40,4 @@ Imports powerbox into the current session. We would love to incorporate community contributions into this project. If you would like to contribute code, documentation, tests, or bug reports, please read our [Contribution Guide](https://github.com/batmanama/powerbox/tree/master/docs/CONTRIBUTING.md) to learn more. + diff --git a/appveyor.yml b/appveyor.yml index 834dd53..adbc54b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -40,7 +40,7 @@ deploy: - provider: Environment name: prerelease on: - branch: /update.*/ + branch: /(update|patch).*/ after_deploy: diff --git a/module/Public/Invoke-nbApi.ps1 b/module/Public/Invoke-nbApi.ps1 index d5009a7..327170d 100644 --- a/module/Public/Invoke-nbApi.ps1 +++ b/module/Public/Invoke-nbApi.ps1 @@ -73,6 +73,11 @@ function Invoke-nbApi { ) $PSCmdlet.ThrowTerminatingError($errorRecord) } + if ($Body.GetType().FullName -eq [hashtable].FullName) + { + Write-Verbose -Message "Converting the hashtable body into an object" + $Body = [PSCustomObject]$Body + } } } process { @@ -119,6 +124,7 @@ function Invoke-nbApi { ###MaximumRedirection ###TransferEncoding } + Write-Debug -Message ($params | ConvertTo-Json) if ($Script:Token) { $unmanagedString = $marshal::SecureStringToGlobalAllocUnicode($Script:Token) $Params['Headers'] = @{ @@ -135,18 +141,9 @@ function Invoke-nbApi { $Response } catch { - $message = $_.Exception.Message - if ($_.ErrorDetails) { - $message += " Detail: " + ($_.ErrorDetails.Message | ConvertFrom-Json).detail - } - $PSCmdlet.ThrowTerminatingError( - [System.Management.Automation.ErrorRecord]::new( - ([exception]::new($message)), ###([system.web.httpunhandledexception]::CreateFromLastError($_)), - 'Netbox.Unhandled', - [System.Management.Automation.ErrorCategory]::NotSpecified, - $Resource - ) - ) + ## I'm going to stop trying to be fancy. + ## The error that irm throws is better then what I was trying to do. + $PSCmdlet.ThrowTerminatingError($_) } finally { if ($null -ne $unmanagedString) { diff --git a/module/Public/Set-nbObject.ps1 b/module/Public/Set-nbObject.ps1 index f8fab40..9994a33 100644 --- a/module/Public/Set-nbObject.ps1 +++ b/module/Public/Set-nbObject.ps1 @@ -98,8 +98,15 @@ function Set-nbObject { :maploop foreach ($property in $object.psobject.properties) { $Name = $Property.name -replace '-' -replace ':' $value = $Property.value - if ($Patch.IsPresent -and $OldObject."$name" -eq $value) { - continue :maploop + if ($Patch.IsPresent) { + if( [string]::IsNullOrEmpty( $($OldObject."$name") ) -and [string]::IsNullOrEmpty($value) ) { + Write-Verbose "Bypassing property $name (values are empty)" + continue :maploop + } + If( ($OldObject."$name" -eq $value) -and ( $object."$name" -isnot [System.Array]) ) { + Write-Verbose "Bypassing property $name (Values are similar and object isn't an array)" + continue :maploop + } } if ($name -in $lookup.keys) { $value = ConvertTo-nbID -source $value -value $name @@ -109,6 +116,7 @@ function Set-nbObject { } elseif ($name -eq 'custom_fields') { $mapObject.custom_fields += $value } else { + Write-Verbose "Adding property $name" $mapObject[$name] = $value } } diff --git a/module/Version b/module/Version index f90b1af..0bee604 100644 --- a/module/Version +++ b/module/Version @@ -1 +1 @@ -2.3.2 +2.3.3 diff --git a/module/powerbox.psd1 b/module/powerbox.psd1 index 0a5e629..9ca2919 100644 --- a/module/powerbox.psd1 +++ b/module/powerbox.psd1 @@ -12,7 +12,7 @@ RootModule = 'powerbox.psm1' # Version number of this module. - ModuleVersion = '2.3.2' + ModuleVersion = '2.3.3' # Supported PSEditions # CompatiblePSEditions = @()