Merge pull request #37 from ZertoPublic/ZATokenCheck
Add a Token Check to the Invoke-ZARestRequest Private Function
This commit is contained in:
Vendored
+4
@@ -1,4 +1,8 @@
|
|||||||
{
|
{
|
||||||
"files.trimTrailingWhitespace": true,
|
"files.trimTrailingWhitespace": true,
|
||||||
|
"files.insertFinalNewline": true,
|
||||||
|
"editor.insertSpaces": true,
|
||||||
|
"editor.tabSize": 4,
|
||||||
|
"powershell.codeFormatting.preset": "OTBS",
|
||||||
"terminal.integrated.shell.windows": "c:/Program Files/PowerShell/6/pwsh.exe"
|
"terminal.integrated.shell.windows": "c:/Program Files/PowerShell/6/pwsh.exe"
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-4
@@ -1,11 +1,9 @@
|
|||||||
|
|
||||||
|
|
||||||
## Initial Release
|
|
||||||
|
|
||||||
### Zerto Virtual Manager
|
### Zerto Virtual Manager
|
||||||
|
|
||||||
* Updated `Invoke-ZertoRestRequest` to work in Powershell 5.1 as well as Powershell core
|
*
|
||||||
|
|
||||||
### Zerto Analytics
|
### Zerto Analytics
|
||||||
|
|
||||||
* Implemented Zerto Analytics Functionality. Please see [Getting Started with Zerto Analytics](https://github.com/ZertoPublic/ZertoApiWrapper/wiki/Getting-Started-with-Zerto-Analytics)
|
* Fixed an issue where the Zerto Analytics Rest Request function was not checking for the token before attempting a connection.
|
||||||
|
|||||||
@@ -7,14 +7,26 @@ function Invoke-ZARestRequest {
|
|||||||
[string]$contentType = "application/json"
|
[string]$contentType = "application/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Check to see if the required variables are present and currently valid
|
||||||
|
if ( -not ((Test-Path variable:script:zaLastActionTime) -and (Test-Path variable:script:zaHeaders)) ) {
|
||||||
|
Write-Error -Message "Zerto Analytics Connection does not Exist. Please run Connect-ZertoAnalytics first to establish a connection"
|
||||||
|
break
|
||||||
|
} elseif ( (Test-Path variable:script:zaHeaders) -and $([datetime]$script:zaLastActionTime).addMinutes(60) -lt $(get-date) ) {
|
||||||
|
Write-Error -Message "Authorization Token has Expired. Please re-authorize to the Zerto Analytics Portal"
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
# Update the last action time and submit the request based on PS Version.
|
||||||
|
Set-Variable -Name zaLastActionTime -Scope Script -Value $(Get-date).Ticks
|
||||||
$submittedUri = "https://analytics.api.zerto.com/v2/{0}" -f $uri
|
$submittedUri = "https://analytics.api.zerto.com/v2/{0}" -f $uri
|
||||||
if ($PSVersionTable.PSVersion.Major -ge 6) {
|
if ($PSVersionTable.PSVersion.Major -ge 6) {
|
||||||
Invoke-RestMethod -Uri $submittedUri -Method $method -Body $body -Headers $Script:zaHeaders -ContentType $contentType -TimeoutSec 100
|
Invoke-RestMethod -Uri $submittedUri -Method $method -Body $body -Headers $Script:zaHeaders -ContentType $contentType -TimeoutSec 100
|
||||||
} else {
|
} else {
|
||||||
|
# With PS 5, you cannot ship a $null body, check for $body variable and select correct Invoke request.
|
||||||
if ([String]::IsNullOrEmpty($body)) {
|
if ([String]::IsNullOrEmpty($body)) {
|
||||||
Invoke-RestMethod -Uri $submittedUri -Method $method -Headers $Script:zaHeaders -ContentType $contentType -TimeoutSec 100
|
Invoke-RestMethod -Uri $submittedUri -Method $method -Headers $Script:zaHeaders -ContentType $contentType -TimeoutSec 100
|
||||||
} else {
|
} else {
|
||||||
Invoke-RestMethod -Uri $submittedUri -Method $method -Headers $Script:zaHeaders -ContentType $contentType -TimeoutSec 100 -Body $body
|
Invoke-RestMethod -Uri $submittedUri -Method $method -Headers $Script:zaHeaders -ContentType $contentType -TimeoutSec 100 -Body $body
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -69,7 +69,7 @@
|
|||||||
# NestedModules = @()
|
# NestedModules = @()
|
||||||
|
|
||||||
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
|
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
|
||||||
FunctionsToExport = 'Add-ZertoPeerSite', 'Checkpoint-ZertoVpg', 'Connect-ZertoServer', 'Disconnect-ZertoServer', 'Edit-ZertoVra', 'Export-ZertoVpg', 'Get-ZertoAlert', 'Get-ZertoDatastore', 'Get-ZertoEvent', 'Get-ZertoLicense', 'Get-ZertoLocalSite', 'Get-ZertoPeerSite', 'Get-ZertoProtectedVm', 'Get-ZertoRecoveryReport', 'Get-ZertoResourcesReport', 'Get-ZertoServiceProfile', 'Get-ZertoTask', 'Get-ZertoUnprotectedVm', 'Get-ZertoVirtualizationSite', 'Get-ZertoVolume', 'Get-ZertoVpg', 'Get-ZertoVpgSetting', 'Get-ZertoVra', 'Get-ZertoZorg', 'Get-ZertoZsspSession', 'Import-ZertoVpg', 'Install-ZertoVra', 'Invoke-ZertoFailover', 'Invoke-ZertoFailoverCommit', 'Invoke-ZertoFailoverRollback', 'Invoke-ZertoForceSync', 'Invoke-ZertoMove', 'Invoke-ZertoMoveCommit', 'Invoke-ZertoMoveRollback', 'New-ZertoVpg', 'New-ZertoVpgSettingsIdentifier', 'Remove-ZertoPeerSite', 'Remove-ZertoVpg', 'Resume-ZertoVpg', 'Save-ZertoVpgSettings', 'Set-ZertoAlert', 'Set-ZertoLicense', 'Start-ZertoCloneVpg', 'Start-ZertoFailoverTest', 'Stop-ZertoCloneVpg', 'Stop-ZertoFailoverTest', 'Suspend-ZertoVpg', 'Uninstall-ZertoVra'
|
FunctionsToExport = '*'
|
||||||
|
|
||||||
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
|
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
|
||||||
CmdletsToExport = @()
|
CmdletsToExport = @()
|
||||||
|
|||||||
Reference in New Issue
Block a user