Update ZARestRequest and associated tests.
This commit is contained in:
@@ -12,7 +12,6 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
@{ParameterName = 'uri'; Type = 'String'; Mandatory = $true; TestName = 'URI' }
|
||||
@{ParameterName = 'method'; Type = 'String'; Mandatory = $false; TestName = 'Method' }
|
||||
@{ParameterName = 'body'; Type = 'String'; Mandatory = $false; TestName = 'Body' }
|
||||
@{ParameterName = 'contentType'; Type = 'String'; Mandatory = $false; TestName = 'contentType' }
|
||||
)
|
||||
|
||||
It "Parameter present and Type test for: <TestName> " -TestCases $testCases {
|
||||
@@ -29,14 +28,9 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' {
|
||||
Get-Command $global:function | Should -HaveParameter Method -DefaultValue "GET"
|
||||
}
|
||||
|
||||
It "ContentType parameter default is 'application/json'" {
|
||||
Get-Command $global:function | Should -HaveParameter contentType -DefaultValue "application/json"
|
||||
}
|
||||
|
||||
$NotNullOrEmptyTests = @(
|
||||
@{ParameterName = 'uri'; TestName = 'Uri' }
|
||||
@{ParameterName = 'body'; TestName = 'Body' }
|
||||
@{ParameterName = 'contentType'; TestName = 'ContentType' }
|
||||
)
|
||||
|
||||
It "<TestName> parameter does not accecpt a null or empty value" -TestCases $NotNullOrEmptyTests {
|
||||
|
||||
@@ -1,26 +1,38 @@
|
||||
<# .ExternalHelp ./en-us/ZertoApiWrapper-help.xml #>
|
||||
function Invoke-ZARestRequest {
|
||||
[cmdletbinding()]
|
||||
param(
|
||||
# Parameter help description
|
||||
[Parameter(Mandatory)]
|
||||
[Parameter(
|
||||
Mandatory,
|
||||
Helpmessage = "URI endpoint to be utilized. When submitting the URI, only the endpoint needs to be submitted. Please review the help documentation for examples."
|
||||
)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]$uri,
|
||||
[Parameter(
|
||||
Helpmessage = "API method to be used. GET, PUT, POST, or DELETE. Refer to documentation for the API endpoint to ensure the correct method is being used. If unspecified, defaults to GET"
|
||||
)]
|
||||
[ValidateSet("GET", "PUT", "POST", "DELETE")]
|
||||
[string]$method = "GET",
|
||||
[Parameter(
|
||||
Helpmessage = "Body to be submitted to the REST API endpoint. This needs to be submitted in JSON format"
|
||||
)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]$body,
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]$contentType = "application/json"
|
||||
[string]$body
|
||||
|
||||
)
|
||||
# While the API can use XML or JSON, this module is built on JSON functionality. Currently forcing all
|
||||
# content types and language to 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)) ) {
|
||||
Throw "Zerto Analytics Connection does not Exist. Please run Connect-ZertoAnalytics first to establish a connection"
|
||||
} elseif ( (Test-Path variable:script:zaHeaders) -and $([datetime]$script:zaLastActionTime).addMinutes(60) -lt $(get-date) ) {
|
||||
} elseif ( (Test-Path variable:script:zaHeaders) -and $([datetime]$script:zaLastActionTime).addMinutes(60) -lt $(Get-Date) ) {
|
||||
Throw "Authorization Token has Expired. Please re-authorize to the Zerto Analytics Portal"
|
||||
} else {
|
||||
# Update the last action time and submit the request based on PS Version.
|
||||
Set-Variable -Name zaLastActionTime -Scope Script -Value $(Get-date).Ticks
|
||||
Set-Variable -Name zaLastActionTime -Scope Script -Value $(Get-Date).Ticks
|
||||
$submittedUri = "https://analytics.api.zerto.com/v2/{0}" -f $uri
|
||||
if ($PSVersionTable.PSVersion.Major -ge 6) {
|
||||
Invoke-RestMethod -Uri $submittedUri -Method $method -Body $body -Headers $Script:zaHeaders -ContentType $contentType -TimeoutSec 100
|
||||
|
||||
Reference in New Issue
Block a user