From d38f20682497e02c8b1c8fd556fe9ed541a6c57e Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Thu, 30 Apr 2020 11:11:29 -0400 Subject: [PATCH] Update ZVM Headers --- Tests/Public/Connect-ZertoServer.Tests.ps1 | 4 ++-- ZertoApiWrapper/Public/Connect-ZertoServer.ps1 | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Tests/Public/Connect-ZertoServer.Tests.ps1 b/Tests/Public/Connect-ZertoServer.Tests.ps1 index da0ab18..6d6e185 100644 --- a/Tests/Public/Connect-ZertoServer.Tests.ps1 +++ b/Tests/Public/Connect-ZertoServer.Tests.ps1 @@ -89,7 +89,7 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { It "Module Scope zvmHeaders variable tests" { $script:zvmHeaders | Should -Not -BeNullOrEmpty $script:zvmHeaders | Should -BeOfType PSCustomObject - $script:zvmHeaders.keys.count | Should -BeExactly 2 + $script:zvmHeaders.keys.count | Should -BeExactly 3 $script:zvmHeaders.ContainsKey('x-zerto-session') | Should -BeTrue $script:zvmHeaders.ContainsKey('Accept') | Should -BeTrue $script:zvmHeaders['x-zerto-session'] | Should -BeOfType String @@ -105,7 +105,7 @@ Describe $global:function -Tag 'Unit', 'Source', 'Built' { $headers = Connect-ZertoServer -zertoServer $Server -credential $credential -returnHeaders It "returns a Hashtable with 2 keys" { $headers | Should -BeOfType Hashtable - $headers.keys.count | Should -Be 2 + $headers.keys.count | Should -Be 3 } It "return value has a key called 'x-zerto-session'" { diff --git a/ZertoApiWrapper/Public/Connect-ZertoServer.ps1 b/ZertoApiWrapper/Public/Connect-ZertoServer.ps1 index 5c7b3b0..177374c 100644 --- a/ZertoApiWrapper/Public/Connect-ZertoServer.ps1 +++ b/ZertoApiWrapper/Public/Connect-ZertoServer.ps1 @@ -32,9 +32,12 @@ function Connect-ZertoServer { Set-Variable -Name zvmServer -Scope Script -Value $zertoServer Set-Variable -Name zvmPort -Scope Script -Value $zertoPort # Set zvmLastAction Variable to keep track when the API token expires - Set-Variable -Name zvmLastAction -Scope Script -Value $(get-date).Ticks + Set-Variable -Name zvmLastAction -Scope Script -Value $(Get-Date).Ticks # Set / Clear the zvmHeaders to clear any existing token - Set-Variable -Name zvmHeaders -Scope Script -Value $null + Set-Variable -Name zvmHeaders -Scope Script -Value @{ + "Accept" = "application/json" + "zerto-triggered-by" = "PowershellWes" + } } process { @@ -44,14 +47,14 @@ function Connect-ZertoServer { end { # Build Headers Hashtable with Authorization Token - $zertoAuthorizationHeaders = @{"x-zerto-session" = $results.Headers['x-zerto-session'][0].ToString(); "Accept" = "application/json"} + $Script:zvmHeaders['x-zerto-session'] = $results.Headers['x-zerto-session'][0].ToString() # Set common Script Scope Variables to be used other functions (Headers and Local Site Info) - Set-Variable -Name zvmHeaders -Scope Script -Value $zertoAuthorizationHeaders + # Set-Variable -Name zvmHeaders -Scope Script -Value $zertoAuthorizationHeaders Set-Variable -Name zvmLocalInfo -Scope Script -Value (Get-ZertoLocalSite) # Have the option to return the headers to a variable if ($returnHeaders) { - return $zertoAuthorizationHeaders + return $Script:zvmHeaders } } }