Update connection to work with expired token
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user