diff --git a/RELEASE.md b/RELEASE.md index d0b052ae..06ad0bcc 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -1,3 +1,2 @@ -- Add parallel functionality to `Remove-VdcObject`. PS Core for now, Windows PowerShell coming soon. -- Fix invalid function reference with `New-VdcCapiApplication`, [#247](https://github.com/Venafi/VenafiPS/issues/247) -- Fix wilcard certificate not accepted with `New-VdcCapiApplication`, [#248](https://github.com/Venafi/VenafiPS/issues/248) +- Fix property not found error with `New-VenafiSession -AccessToken`, [#252](https://github.com/Venafi/VenafiPS/issues/252) +- Update `Invoke-VenafiRestMethod` to ensure parameter verbose output does not convert the body to json twice diff --git a/VenafiPS/Public/Invoke-VenafiRestMethod.ps1 b/VenafiPS/Public/Invoke-VenafiRestMethod.ps1 index 4aaa0d03..a35ff9a3 100644 --- a/VenafiPS/Public/Invoke-VenafiRestMethod.ps1 +++ b/VenafiPS/Public/Invoke-VenafiRestMethod.ps1 @@ -202,8 +202,15 @@ function Invoke-VenafiRestMethod { # in the case of inital authentication, eg, there won't be any if ( $allHeaders ) { $params.Headers = $allHeaders } + if ( $UseDefaultCredential.IsPresent -and $Certificate ) { + throw 'You cannot use UseDefaultCredential and Certificate parameters together' + } + + if ( $UseDefaultCredential.IsPresent ) { + $params.Add('UseDefaultCredentials', $true) + } + if ( $Body ) { - $restBody = $Body switch ($Method.ToLower()) { 'head' { # a head method requires the params be provided as a query string, not body @@ -211,30 +218,27 @@ function Invoke-VenafiRestMethod { $newUri = New-HttpQueryString -Uri $uri -QueryParameter $Body $params.Uri = $newUri $params.Body = $null - Write-Verbose $newUri } 'get' { - $params.Body = $restBody + $params.Body = $Body } Default { - $restBody = ConvertTo-Json $Body -Depth 20 -Compress - $params.Body = $restBody + $preJsonBody = $Body + $params.Body = (ConvertTo-Json $Body -Depth 20 -Compress) } } } - if ( $UseDefaultCredential.IsPresent -and $Certificate ) { - throw 'You cannot use UseDefaultCredential and Certificate parameters together' + if ( $preJsonBody ) { + $paramsToWrite = $params.Clone() + $paramsToWrite.Body = $preJsonBody + $paramsToWrite | Write-VerboseWithSecret + } else { + $params | Write-VerboseWithSecret } - if ( $UseDefaultCredential.IsPresent ) { - $params.Add('UseDefaultCredentials', $true) - } - - $params | Write-VerboseWithSecret - # ConvertTo-Json, used in Write-VerboseWithSecret, has an issue with certificates # add this param after if ( $Certificate ) { diff --git a/VenafiPS/Public/New-VenafiSession.ps1 b/VenafiPS/Public/New-VenafiSession.ps1 index 40f55380..82f5219f 100644 --- a/VenafiPS/Public/New-VenafiSession.ps1 +++ b/VenafiPS/Public/New-VenafiSession.ps1 @@ -353,12 +353,15 @@ function New-VenafiSession { # we don't have the expiry so create one # rely on the api call itself to fail if access token is invalid Expires = (Get-Date).AddMonths(12) + AccessToken = $null } $newSession.Token.AccessToken = if ( $AccessToken -is [string] ) { New-Object System.Management.Automation.PSCredential('AccessToken', ($AccessToken | ConvertTo-SecureString -AsPlainText -Force)) } elseif ($AccessToken -is [pscredential]) { $AccessToken } elseif ($AccessToken -is [securestring]) { New-Object System.Management.Automation.PSCredential('AccessToken', $AccessToken) } else { throw 'Unsupported type for -AccessToken. Provide either a String, SecureString, or PSCredential.' } + # validate token + $null = Invoke-VenafiRestMethod -UriRoot 'vedauth' -UriLeaf 'Authorize/Verify' -VenafiSession $newSession } 'VaultAccessToken' {