vchrisb / Isilon-POSH

EMC Isilon Platform API implementation in PowerShell
MIT License
25 stars 13 forks source link

Not properly sanitizing $BoundParameters before converting to JSON and sending in request body #7

Closed devblackops closed 8 years ago

devblackops commented 8 years ago

In your functions, you are taking $PSBoundParameters and converting it to a JSON string then sending it to the API. This causes unneeded properties to be sent with the request when the function is called with common parameters such as -Verbose or -Debug. The Isilon API responds with an error when these properties are sent.

Might I suggest you sanitize your properties before sending to the API? The function below will remove common properties.

function SanitizeBoundParameters {
    [cmdletbinding()]
    param(
        [parameter(Mandatory, ValueFromPipeline)]
        [hashtable]$Parameters
    )

    $commonParameters = @('Verbose', 'Debug', 'ErrorAction', 'ErrorVariable', 'WarningAction', 'WarningVariable',
        'OutBuffer', 'PipelineVariable', 'OutVariable')

    $commonParameters | % {
        $Parameters.Remove($_)
    }

    return $Parameters
}

This function could then be called like so:

$boundParameters = $PSBoundParameters | SanitizeBoundParameters
$body = ConvertTo-Json -Depth 40 $BoundParameters
$ISIObject = Send-isiAPI -Method POST -Resource ("/platform/1/quota/quotas" + "$queryArguments") -body $body -Cluster $Cluster
vchrisb commented 8 years ago

Great! I'll work the enhancement into Isilon-POSH-Generator and recreate all functions.

vchrisb commented 8 years ago

merged enhancement with Sanitize BoundParameters