diff --git a/PowerArubaCX/Private/RestMethod.ps1 b/PowerArubaCX/Private/RestMethod.ps1 index 49555b1..3b61d80 100644 --- a/PowerArubaCX/Private/RestMethod.ps1 +++ b/PowerArubaCX/Private/RestMethod.ps1 @@ -40,9 +40,9 @@ function Invoke-ArubaCXRestMethod { Invoke-RestMethod with ArubaCX connection for get rest/vX/system with display only attributes hostname and dns_servers .EXAMPLE - Invoke-ArubaCXRestMethod -method "get" -uri "rest/v10.04/system" -noapiversion + Invoke-ArubaCXRestMethod -method "get" -uri "rest/v10.08/system" -noapiversion - Invoke-RestMethod with ArubaCX connection for get rest/v10.04/system (need to specify full uri with rest/vX) + Invoke-RestMethod with ArubaCX connection for get rest/v10.08/system (need to specify full uri with rest/vX) #> [CmdletBinding(DefaultParametersetname = "default")] diff --git a/PowerArubaCX/Public/Connection.ps1 b/PowerArubaCX/Public/Connection.ps1 index 8b16812..bcb00ef 100644 --- a/PowerArubaCX/Public/Connection.ps1 +++ b/PowerArubaCX/Public/Connection.ps1 @@ -92,28 +92,34 @@ function Connect-ArubaCX { } } - $postParams = @{username = $Credential.username; password = $Credential.GetNetworkCredential().Password } - $url = "https://${Server}:${Port}/rest/v1/login" + $url = "https://${Server}:${Port}/rest" try { - Invoke-RestMethod $url -Method POST -Body $postParams -SessionVariable arubacx @invokeParams | Out-Null + if ("Desktop" -eq $PSVersionTable.PsEdition) { + $rest = Invoke-RestMethod $url -Method "get" @invokeParams + } + else { + $rest = Invoke-RestMethod $url -Method "get" @invokeParams -SkipCertificateCheck + } } catch { - Show-ArubaCXException $_ - throw "Unable to connect" + throw "Unsupported release Need to use ArubaCX >= 10.06" } + $api_version = $rest.latest.version - $url = "https://${Server}:${Port}/rest" + $postParams = @{username = $Credential.username; password = $Credential.GetNetworkCredential().Password } + $url = "https://${Server}:${Port}/rest/${api_version}/login" try { - $rest = Invoke-RestMethod $url -Method "get" -WebSession $arubacx @invokeParams + Invoke-RestMethod $url -Method POST -Body $postParams -SessionVariable arubacx @invokeParams | Out-Null } catch { - throw "Unsupported release Need to use ArubaCX >= 10.04" + Show-ArubaCXException $_ + throw "Unable to connect" } $connection.server = $server $connection.session = $arubacx $connection.invokeParams = $invokeParams - $connection.api_version = $rest.latest.version + $connection.api_version = $api_version $current_version = (Get-ArubaCXFirmware -connection $connection).current_version.split(".") $connection.version = [version]"$($current_version[1]).$($current_version[2]).$($current_version[3])" $connection.platform_name = (Get-ArubaCXSystem -attributes platform_name -connection $connection).platform_name diff --git a/README.md b/README.md index 4043bf2..02ae297 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ There is some extra feature More functionality will be added later. -Tested with ArubaCX 8400 and 832x, 6x00 (using >= 10.04.xx firmware) on Windows/Linux/macOS +Tested with ArubaCX 8400 and 832x, 6x00 (using >= 10.06.xx firmware) on Windows/Linux/macOS # Usage @@ -38,8 +38,8 @@ For example, you can manage Vlans with the following commands: # Requirements -- Powershell 6 (Core) or 5 (If possible get the latest version) -- An ArubaCX Switch (with firmware >= 10.04.xx) and REST API enable +- Powershell 7 (Core) or 5 (If possible get the latest version) +- An ArubaCX Switch (with firmware >= 10.06.xx) and REST API enable # Instructions ### Install the module diff --git a/Tests/integration/Connection.Tests.ps1 b/Tests/integration/Connection.Tests.ps1 index 48ceae7..6ba3e7a 100644 --- a/Tests/integration/Connection.Tests.ps1 +++ b/Tests/integration/Connection.Tests.ps1 @@ -17,7 +17,7 @@ Describe "Connect to a switch (using HTTPS)" { $DefaultArubaCXConnection.api_version | Should -Not -BeNullOrEmpty $DefaultArubaCXConnection.version | Should -Not -BeNullOrEmpty $DefaultArubaCXConnection.version.major | Should -Be "10" - $DefaultArubaCXConnection.version.minor | Should -BeIn (4..11) + $DefaultArubaCXConnection.version.minor | Should -BeIn (6..12) $DefaultArubaCXConnection.version.revision | Should -Not -BeNullOrEmpty } It "Disconnect to a switch (using HTTPS) and check global variable" { @@ -42,12 +42,12 @@ Describe "Connect to a switch (using multi connection)" { $cx.api_version | Should -Not -BeNullOrEmpty $cx.version | Should -Not -BeNullOrEmpty $cx.version.major | Should -Be "10" - $cx.version.minor | Should -BeIn (4..11) + $cx.version.minor | Should -BeIn (6..12) $cx.version.revision | Should -Not -BeNullOrEmpty } It "Throw when try to use Invoke-ArubaCPRestMethod and not connected" { - { Invoke-ArubaCXRestMethod -uri "rest/v1/system" } | Should -Throw "Not Connected. Connect to the Switch with Connect-ArubaCX" + { Invoke-ArubaCXRestMethod -uri "rest/v10.08/system" } | Should -Throw "Not Connected. Connect to the Switch with Connect-ArubaCX" } Context "Use Multi connection for call some (Get) cmdlet (Vlan, System...)" {