Update connection to work with expired token

This commit is contained in:
Wes Carroll
2019-02-22 13:29:38 -05:00
parent 94a54f013a
commit 9fd116b36f
2 changed files with 8 additions and 13 deletions
@@ -15,19 +15,14 @@ function Invoke-ZertoRestRequest {
Write-Error -Message "Zerto Connection does not Exist. Please run Connect-ZertoServer first to establish a connection"
break
}
if ( Test-Path variable:script:zvmHeaders ) {
$headers = $script:zvmHeaders
} else {
$headers = $null
}
if ( (Test-Path variable:script:zvmHeaders) -and $([datetime]$script:zvmLastAction).addMinutes(30) -lt $(get-date) ) {
Write-Error -Message "Authorization Token has Expired or Does not exist in Env variables. Please re-authorize to the Zerto Virtual Manager"
Write-Error -Message "Authorization Token has Expired. Please re-authorize to the Zerto Virtual Manager"
break
} else {
$submittedURI = "https://{0}:{1}/{2}/{3}" -f $script:zvmServer, $script:zvmPort, $apiVersion, $uri
try {
$script:zvmLastAction = (get-date).Ticks
$apiRequestResults = Invoke-RestMethod -Uri $submittedURI -Headers $headers -Method $method -Body $body -ContentType $contentType -Credential $credential -SkipCertificateCheck -ResponseHeadersVariable responseHeaders -TimeoutSec 100
$apiRequestResults = Invoke-RestMethod -Uri $submittedURI -Headers $script:zvmHeaders -Method $method -Body $body -ContentType $contentType -Credential $credential -SkipCertificateCheck -ResponseHeadersVariable responseHeaders -TimeoutSec 100
} catch {
Write-Error -ErrorRecord $_ -ErrorAction $callerErrorActionPreference
}