Skip to content

Commit 4e885ba

Browse files
committed
Corrected issue with netscaler protocol scope
1 parent 20c4d80 commit 4e885ba

File tree

7 files changed

+34
-17
lines changed

7 files changed

+34
-17
lines changed

NetScaler/NetScaler.psm1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ limitations under the License.
1818
Set-StrictMode -Version 3
1919

2020
$script:session = $null
21-
$script:protocol = $null
2221

2322
# Load DLLs
2423
#$dll1 = Resolve-Path -Path "$PSScriptRoot\DLL\Newtonsoft.Json.dll"

NetScaler/Private/_InvokeNSRestApi.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ function _InvokeNSRestApi {
6363
)
6464

6565
if ($Stat) {
66-
$uri = "$($Script:protocol)://$($Session.Endpoint)/nitro/v1/stat/$Type"
66+
$uri = $Session.CreateUri("stat", $Type)
6767
} else {
68-
$uri = "$($Script:protocol)://$($Session.Endpoint)/nitro/v1/config/$Type"
68+
$uri = $Session.CreateUri("config", $Type)
6969
}
7070

7171
if (-not [string]::IsNullOrEmpty($Resource)) {

NetScaler/Public/Connect-NetScaler.ps1

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,28 @@ function Connect-NetScaler {
7171
$endpoint = $Hostname
7272
}
7373

74-
if ($PSBoundParameters.ContainsKey('Https')) {
75-
$Script:protocol = 'https'
74+
if ($Https) {
75+
$scheme = 'https'
7676
} else {
77-
$script:protocol = 'http'
77+
$scheme = 'http'
7878
}
7979

80-
Write-Verbose -Message "Connecting to $endpoint..."
80+
81+
$session = New-Object -TypeName PSObject
82+
$session | Add-Member -NotePropertyName Endpoint -NotePropertyValue $endpoint -TypeName String
83+
$session | Add-Member -NotePropertyName Scheme -NotePropertyValue $scheme -TypeName String
84+
$session | Add-Member -Name Uri -MemberType ScriptProperty -Value {
85+
"$($this.scheme)://$($this.endpoint)/nitro/v1"
86+
}
87+
$session | Add-Member -Name CreateUri -MemberType ScriptMethod -Value {
88+
Param(
89+
[String]$service,
90+
[String]$type
91+
)
92+
"$($this.Uri)/$service/$type"
93+
}
94+
95+
Write-Verbose -Message "Connecting to $($session.Uri)..."
8196

8297
try {
8398
$login = @{
@@ -91,7 +106,7 @@ function Connect-NetScaler {
91106

92107
$saveSession = @{}
93108
$params = @{
94-
Uri = "$($Script:protocol)://$endpoint/nitro/v1/config/login"
109+
Uri = "$($session.Uri)/config/login"
95110
Method = 'POST'
96111
Body = $loginJson
97112
SessionVariable = 'saveSession'
@@ -108,12 +123,10 @@ function Connect-NetScaler {
108123
throw $_
109124
}
110125

111-
$session = New-Object -TypeName PSObject
112-
$session | Add-Member -NotePropertyName Endpoint -NotePropertyValue $endpoint -TypeName String
113-
$session | Add-Member -NotePropertyName WebSession -NotePropertyValue $saveSession -TypeName Microsoft.PowerShell.Commands.WebRequestSession
114-
126+
$session | Add-Member -NotePropertyName WebSession -NotePropertyValue $saveSession -TypeName Microsoft.PowerShell.Commands.WebRequestSession
115127
$script:session = $session
116128

129+
117130
if ($PSBoundParameters.ContainsKey('PassThru')) {
118131
return $session
119132
}

NetScaler/Public/Disable-NSFeature.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ function Disable-NSFeature {
4848
param(
4949
$Session = $script:session,
5050

51-
[parameter(Mandatory,ValueFromPipeline = $true, ValueFromPipelineByPropertyName)]
52-
[string[]]$Name = (Read-Host -Prompt 'NetScaler feature'),
51+
[parameter(Mandatory, ValueFromPipeline = $true, ValueFromPipelineByPropertyName)]
52+
[string[]]$Name,
5353

5454
[switch]$Force,
5555

NetScaler/Public/Disconnect-NetScaler.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function Disconnect-NetScaler {
4545
try {
4646
Write-Verbose -Message 'Logging out of NetScaler'
4747
$params = @{
48-
Uri = "$($script:protocol)://$($Session.Endpoint)/nitro/v1/config/logout"
48+
Uri = $Session.CreateUri("config", "logout")
4949
Body = ConvertTo-Json -InputObject @{logout = @{}}
5050
Method = 'POST'
5151
ContentType = 'application/json'

NetScaler/Public/Restart-NetScaler.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function Restart-NetScaler {
119119
$response = $null
120120
try {
121121
$params = @{
122-
Uri = "$($script:protocol)://$ip/nitro/v1/config"
122+
Uri = $Session.CreateUri("config")
123123
Method = 'GET'
124124
ContentType = 'application/json'
125125
ErrorVariable = 'connectTestError'

Tests/Unit/Public/Connect-NetScaler.tests.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,14 @@ describe 'Connect-NetScaler' {
2929
$script:session | should not benullorempty
3030
}
3131

32+
it 'Connects via HTTP' {
33+
Connect-NetScaler -Hostname 'localhost' -Credential $credential
34+
$script:session.scheme | should be 'http'
35+
}
36+
3237
it 'Connects via HTTPs' {
3338
Connect-NetScaler -Hostname 'localhost' -Credential $credential -HTTPs
34-
$script:protocol | should be 'https'
39+
$script:session.scheme | should be 'https'
3540
}
3641
}
3742

0 commit comments

Comments
 (0)