FriedrichWeinmann / bConnect

PowerShell Module to interact with the Baramundi bConnect Rest API
MIT License
3 stars 1 forks source link

New-bConnectApplication.ps1 - ConsistencyChecks does not respect CR and/or LF #9

Open NickETH opened 5 years ago

NickETH commented 5 years ago

Hi Developers, the ConsistencyChecks field in the baramundi application object consists of a text object which has/allows CR and LF. If i read out an object with Get-bConnectApplication.ps1, those white spaces are read in a clean way as it should be. However, if i try to import a ConsistencyChecks field with CR, LF or any other special chars, they are not interpreted at all. Please check the code in the JSON implementation and tell us, if there is bug. And how to submit such characters the right way true bConnect.

BR, Nick

FriedrichWeinmann commented 5 years ago

Hi Nick,

apologies, but ... I do not know how to fix that :( Basically, what happens is that the ConsistencyChecks string will be added as a property to a hashtable which is passed straight to the Invoke-RestMethod's -Body parameter.

On general principle, I'd look into trying it on PowerShell Core (The Invoke-RestMethod has been significantly compared to 5.1).

This is the actual code running the rest call:

Invoke-RestMethod -Uri "$($script:_connectUri)/$($Version)/Applications" -Body $body -Credential $script:_connectCredentials -Method Post -ContentType "application/json"

It gets fed as $body the result of this:

$body = @{
    Name       = $Name;
    Vendor     = $Vendor;
    ValidForOS = $ValidForOS;
    Cost       = $Cost
}

if ($Comment) { $body['Comment'] = $Comment }
if ($ParentGuid) { $body['ParentId'] = $ParentId }
if ($Version) { $body['Version'] = $Version }
if ($Category) { $body['Category'] = $Category }
if ($InstallationData) { $body['Installation'] = $InstallationData }
if ($UninstallationData) { $body['Uninstallation'] = $UninstallationData }
if ($ConsistencyChecks) { $body['ConsistencyChecks'] = $ConsistencyChecks }
if ($SecurityContext) { $body['SecurityContext'] = $SecurityContext }
if ($Licenses) { $body['Licenses'] = $Licenses }
if ($AUT)
{
    $body['AUT'] = $AUT
    $body['EnableAUT'] = $true
}

I don't have any more access to a Baramundi system anymore, significantly hindering my ability to test things :( If you can make this call somehow work and fix it, I'll be happy to adopt it.

Cheers, Fred

NickETH commented 5 years ago

Hi Fred, no blaming at all! Was suspecting the BMS JSON implementation from the beginning. So, i will ask folks at bramundi about this problem. First, i should do some more tests with bConnect from a browser, i guess. Thanks for your time. BR, Nick

NickETH commented 5 years ago

It looks like, there is some kind of implementation... If one sends an XML-escape of LF ( ), it is respected in Application:Comment, but not on ConsistencyChecks. Doing the same with CR ( ) has no effect at all.

NickETH commented 5 years ago

Tested more... If using XML, it is really important to sort the elements alphabetically! With the right escapes, it works! You need to escape CR/LF like this: 
 And this works also with the JSON data format, as used in the bConnect PS module.

Therefore, this issue can be closed.