Skip to content

Commit

Permalink
v2.3.3
Browse files Browse the repository at this point in the history
* Add debugging. Remove fancy error stuff.
* Modify PATCH property value tests (#25) (thanks Makwa)
  • Loading branch information
BatmanAMA authored May 15, 2019
1 parent 518a266 commit 6daf148
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 17 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ deploy:
- provider: Environment
name: prerelease
on:
branch: /update.*/
branch: /(update|patch).*/


after_deploy:
Expand Down
21 changes: 9 additions & 12 deletions module/Public/Invoke-nbApi.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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'] = @{
Expand All @@ -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) {
Expand Down
12 changes: 10 additions & 2 deletions module/Public/Set-nbObject.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion module/Version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.2
2.3.3
2 changes: 1 addition & 1 deletion module/powerbox.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'powerbox.psm1'

# Version number of this module.
ModuleVersion = '2.3.2'
ModuleVersion = '2.3.3'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down

0 comments on commit 6daf148

Please sign in to comment.