sailpoint-oss / powershell-sdk

PowerShell Module for accessing SailPoint IdentityNow APIs
https://developer.sailpoint.com/
MIT License
21 stars 15 forks source link

Invoke-PaginateSearch retrying on bad requests #5

Closed rob-buskens-sp closed 1 year ago

rob-buskens-sp commented 1 year ago

I imagine the retry functionality is configurable and will look into it. I'd expect 400's to not retry... as the results won't change.

The following example produces the debug output that follows:

`$DebugPreference = 'Continue'

try {

$Search = @{ 
    queryType = "SAILPOINT"
    indices = @('identities')
    query = @{
        query = 'pat.smith'
    }
    sort = @(
        'id'
    )
}

$Search | ConvertTo-Json | Write-Output

Invoke-PaginateSearch -Increment 50 -Limit 100 -Search $Search -Verbose

} catch {

Write-Host ("Exception occurred when calling Invoke-ListAccounts: {0}" -f ($_.ErrorDetails | ConvertFrom-Json))

Write-Host ("Exception occurred when calling Search-Post:" + $_.Exception)
Write-Host ("Response headers: {0}" -f ($_.Exception.Response.Headers | ConvertTo-Json))

}`

DEBUG: Getting Access Token DEBUG: https://company2825-poc.api.identitynow-demo.com/oauth/token DEBUG: DEBUG: DEBUG: Token Exp: 03/12/2023 22:07:28 DEBUG: Token is valid VERBOSE: HTTP/1.1 POST with 404-byte payload VERBOSE: Retrying after interval of 5 seconds. Status code for previous attempt: BadRequest VERBOSE: Retrying after interval of 5 seconds. Status code for previous attempt: BadRequest VERBOSE: Retrying after interval of 5 seconds. Status code for previous attempt: BadRequest VERBOSE: Retrying after interval of 5 seconds. Status code for previous attempt: BadRequest VERBOSE: Retrying after interval of 5 seconds. Status code for previous attempt: BadRequest VERBOSE: Retrying after interval of 5 seconds. Status code for previous attempt: BadRequest VERBOSE: Retrying after interval of 5 seconds. Status code for previous attempt: BadRequest VERBOSE: Retrying after interval of 5 seconds. Status code for previous attempt: BadRequest VERBOSE: Retrying after interval of 5 seconds. Status code for previous attempt: BadRequest VERBOSE: Retrying after interval of 5 seconds. Status code for previous attempt: BadRequest

{"detailCode":"400.1.0 Required data missing or empty","trackingId":"7e8b3213dbb441208d62f9ff6557e135","messages":[{"locale":"und","localeOrigin":"REQUEST","text":"At least one of the fields \"query, aggregations\" must be specified."},{"locale":"en-US","localeOrigin":"DEFAULT","text":"At least one of the fields \"query, aggregations\" must be specified."}],"causes":[]} Exception occurred when calling : @{detailCode=400.1.0 Required data missing or empty; trackingId=7e8b3213dbb441208d62f9ff6557e135; messages=System.Object[]; causes=System.Object[]} Response headers: [ { "Key": "Date", "Value": [ "Sun, 12 Mar 2023 15:40:48 GMT" ] }, { "Key": "Connection", "Value": [ "keep-alive" ] }, { "Key": "Server", "Value": [ "nginx" ] }, { "Key": "Vary", "Value": [ "Origin", "Access-Control-Request-Method", "Access-Control-Request-Headers" ] }, { "Key": "SLPT-Request-ID", "Value": [ "7e8b3213dbb441208d62f9ff6557e135" ] }, { "Key": "Access-Control-Expose-Headers", "Value": [ "SLPT-Request-ID", "Content-Type" ] }, { "Key": "X-Robots-Tag", "Value": [ "noindex" ] }

tyler-mairose-sp commented 1 year ago

Hello @rob-buskens-sp,

The library that our SDK generator is using relies on the Invoke-WebRequest Cmdlet. We are taking advantage of the built in retry logic with the two variables to configure retries, MaximumRetryCount and RetryIntervalSec. In looking closer at the functionality it appears that the Invoke-WebRequest Cmdlet will retry on status code 304 and status codes between 400-599.

https://github.com/PowerShell/PowerShell/blob/master/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs#L1828

rob-buskens-sp commented 1 year ago

Tyler,

Fair enough, I find it curious though. Why retry things that won’t work ever? (rhetorical). Bad requests would mostly be caught in testing. TCP has data integrity checks Seems inefficient. Not particularly configurable.

Good enough, I understand the behavior.

Thanks.

Rob Buskens Solution Architect SailPoint Certified IdentityNow Professional @. @.> Join the #SailPointCrew https://www.sailpoint.com/company/careers/

[https://i.xink.io/Images/Get/N9791/s481.png]https://www.sailpoint.com/

From: Tyler Mairose @.> Date: Wednesday, March 22, 2023 at 12:09 PM To: sailpoint-oss/powershell-sdk @.> Cc: Rob Buskens @.>, Mention @.> Subject: Re: [sailpoint-oss/powershell-sdk] Invoke-PaginateSearch retrying on bad requests (Issue #5) Hello @rob-buskens-sp, The library that our SDK generator is using relies on the Invoke-WebRequest Cmdlet. We are taking advantage of the built in retry logic with the two variables to configure retries, MaximumRetryCount and RetryIntervalSec.  ZjQcmQRYFpfptBannerStart This Message Is From an External Sender This message came from outside your organization. ZjQcmQRYFpfptBannerEnd

Hello @rob-buskens-sphttps://urldefense.com/v3/__https:/github.com/rob-buskens-sp__;!!MsNKLpFGsw!LP2BOaM02IudbIP4OkZB_59Z1pvRgTaoMFhTEyxnL8zhNyCCt6Dgl3bwj4O897vASkILWQzMzj-6hjgEpTPRGH9bD7yM$,

The library that our SDK generator is using relies on the Invoke-WebRequest Cmdlet. We are taking advantage of the built in retry logic with the two variables to configure retries, MaximumRetryCount and RetryIntervalSec. In looking closer at the functionality it appears that the Invoke-WebRequest Cmdlet will retry on status code 304 and status codes between 400-599.

https://github.com/PowerShell/PowerShell/blob/master/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs#L1828https://urldefense.com/v3/__https:/github.com/PowerShell/PowerShell/blob/master/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/WebRequestPSCmdlet.Common.cs*L1828__;Iw!!MsNKLpFGsw!LP2BOaM02IudbIP4OkZB_59Z1pvRgTaoMFhTEyxnL8zhNyCCt6Dgl3bwj4O897vASkILWQzMzj-6hjgEpTPRGBYS2bX8$

— Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https:/github.com/sailpoint-oss/powershell-sdk/issues/5*issuecomment-1479952537__;Iw!!MsNKLpFGsw!LP2BOaM02IudbIP4OkZB_59Z1pvRgTaoMFhTEyxnL8zhNyCCt6Dgl3bwj4O897vASkILWQzMzj-6hjgEpTPRGKhYf4_E$, or unsubscribehttps://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/AZH2GPNV6F23CLHNDRKVM4LW5MW3RANCNFSM6AAAAAAVYF4N6E__;!!MsNKLpFGsw!LP2BOaM02IudbIP4OkZB_59Z1pvRgTaoMFhTEyxnL8zhNyCCt6Dgl3bwj4O897vASkILWQzMzj-6hjgEpTPRGKZhu_ts$. You are receiving this because you were mentioned.Message ID: @.***>

jordan-violet-sp commented 1 year ago

Closed as won't do. See https://github.com/sailpoint-oss/powershell-sdk/issues/5#issuecomment-1479952537