Skip to content

Commit

Permalink
Issue okta#61 - Move the fixes to the mustache and openapi3 generation
Browse files Browse the repository at this point in the history
  • Loading branch information
TriggerAu committed Nov 1, 2024
1 parent a560d16 commit 66d2c05
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
13 changes: 9 additions & 4 deletions openapi3/codegen-templates/api_client.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ function Invoke-{{{apiNamePrefix}}}ApiClient {
-ErrorAction Stop `
-UseBasicParsing `
-SkipCertificateCheck `
-UserAgent $OktaUserAgent
-UserAgent $OktaUserAgent `
-SkipHttpErrorCheck
} else {
# skip certification check, use proxy
$RawResponse = Invoke-WebRequest -Uri $UriBuilder.Uri `
Expand All @@ -175,7 +176,8 @@ function Invoke-{{{apiNamePrefix}}}ApiClient {
-SkipCertificateCheck `
-Proxy $Configuration["Proxy"].GetProxy($UriBuilder.Uri) `
-ProxyUseDefaultCredentials `
-UserAgent $OktaUserAgent
-UserAgent $OktaUserAgent `
-SkipHttpErrorCheck
}
} else {
if ($null -eq $Configuration["Proxy"]) {
Expand All @@ -186,7 +188,8 @@ function Invoke-{{{apiNamePrefix}}}ApiClient {
-Body $RequestBody `
-ErrorAction Stop `
-UseBasicParsing `
-UserAgent $OktaUserAgent
-UserAgent $OktaUserAgent `
-SkipHttpErrorCheck
} else {
# perform certification check, use proxy
$RawResponse = Invoke-WebRequest -Uri $UriBuilder.Uri `
Expand All @@ -197,7 +200,8 @@ function Invoke-{{{apiNamePrefix}}}ApiClient {
-UseBasicParsing `
-Proxy $Configuration["Proxy"].GetProxy($UriBuilder.Uri) `
-ProxyUseDefaultCredentials `
-UserAgent $OktaUserAgent
-UserAgent $OktaUserAgent `
-SkipHttpErrorCheck
}

$Response = $null
Expand All @@ -217,6 +221,7 @@ function Invoke-{{{apiNamePrefix}}}ApiClient {
$RetryCount = $RetryCount + 1
$RequestId = $Headers['X-Okta-Request-Id'][0]
AddRetryHeaders -Headers $HeaderParameters -RequestId $RequestId -RetryCount $RetryCount
Write-Verbose "Hit Rate limit: Retrying request after $WaitInMilliseconds milliseconds"
Start-Sleep -Milliseconds $WaitInMilliseconds
}
else {
Expand Down
11 changes: 7 additions & 4 deletions openapi3/codegen-templates/okta_retryApi.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,15 @@ function CalculateDelay {
$Configuration = Get-OktaConfiguration
if ($null -eq $Headers['X-Rate-Limit-Reset']) {
throw "Error! The required header `X-Rate-Limit-Reset` missing when calling CalculateDelay."
if ($null -eq $Headers['x-rate-limit-reset']) {
throw "Error! The required header `x-rate-limit-reset` missing when calling CalculateDelay."
}

$RateLimitReset = Get-Date -Date $Headers["X-Rate-Limit-Reset"][0]
$RetryAtUtcTime = $RateLimitReset.ToUniversalTime()
$RateLimitResetEpoch = $Headers["x-rate-limit-reset"][0]
# this is a unich seconds since epoch time, so we convert to date
$RateLimitResetUTC = New-Object DateTime(1970, 1, 1, 0, 0, 0, 0)
$RateLimitResetUTC = $RateLimitResetUTC.addSeconds($RateLimitResetEpoch)
$RetryAtUtcTime = $RateLimitResetUTC


if ($null -eq $Headers["Date"]) {
Expand Down

0 comments on commit 66d2c05

Please sign in to comment.