Skip to content

Commit 4c3ea7b

Browse files
authored
Merge pull request #59 from dbroeglin/feature/new-nsrewrite
Added New-RewriteAction and New-RewritePolicy
2 parents 4af61cf + e495aaf commit 4c3ea7b

File tree

3 files changed

+232
-0
lines changed

3 files changed

+232
-0
lines changed

NetScaler/NetScaler.psd1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ FunctionsToExport = @(
167167
'New-NSNTPServer',
168168
'New-NSResponderAction',
169169
'New-NSResponderPolicy',
170+
'New-NSRewriteAction',
171+
'New-NSRewritePolicy',
170172
'New-NSNTPServer',
171173
'New-NSSSLProfile',
172174
'New-NSVPNSessionPolicy',
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<#
2+
Copyright 2016 Dominique Broeglin
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
#>
16+
17+
function New-NSRewriteAction {
18+
<#
19+
.SYNOPSIS
20+
Adds a rewrite action.
21+
22+
.DESCRIPTION
23+
Adds a rewrite action.
24+
25+
.EXAMPLE
26+
New-NSRewriteAction -Name 'act-rewrite' -Type Replace `
27+
-Target 'HTTP.REQ.HOSTNAME' -Expression '"www.lab.local"'
28+
29+
Creates a new rewrite action which rewrites the 'Host' header with the value 'www.lab.local'
30+
31+
.PARAMETER Session
32+
The NetScaler session object.
33+
34+
.PARAMETER Name
35+
The name of rewrite action.
36+
37+
.PARAMETER Type
38+
The type of rewrite action to create.
39+
40+
Possible values = Replace
41+
42+
.PARAMETER Target
43+
The target expression for the rewrite action.
44+
45+
Minimum length: 0
46+
Maximum length: 8191
47+
48+
.PARAMETER Expression
49+
The expression value used by the rewrite target. Its exact meaning depends on the type.
50+
51+
Minimum length: 0
52+
Maximum length: 8191
53+
54+
.PARAMETER Comment
55+
Any information about the rewrite action.
56+
57+
Minimum length: 0
58+
Maximum length: 256
59+
60+
.PARAMETER Passthru
61+
Return the newly created rewrite action.
62+
#>
63+
[cmdletbinding(SupportsShouldProcess = $true, ConfirmImpact='Low')]
64+
param(
65+
$Session = $script:session,
66+
67+
[Parameter(Mandatory, ValueFromPipeline = $true, Position = 0, ValueFromPipelineByPropertyName = $true)]
68+
[string[]]$Name,
69+
70+
[Parameter(Mandatory)]
71+
[ValidateSet('Replace')]
72+
[string]$Type,
73+
74+
[Parameter(Mandatory)]
75+
[ValidateLength(0, 8191)]
76+
[string]$Target,
77+
78+
[Parameter(Mandatory)]
79+
[ValidateLength(0, 8191)]
80+
[string]$Expression,
81+
82+
[ValidateLength(0, 256)]
83+
[string]$Comment = [string]::Empty,
84+
85+
[Switch]$PassThru
86+
)
87+
88+
begin {
89+
_AssertSessionActive
90+
}
91+
92+
process {
93+
foreach ($Item in $Name) {
94+
if ($PSCmdlet.ShouldProcess($Item, 'Create rewrite action')) {
95+
try {
96+
$params = @{
97+
name = $Item
98+
type = $Type.ToLower()
99+
comment = $Comment
100+
target = $Target
101+
stringbuilderexpr = $Expression
102+
}
103+
_InvokeNSRestApi -Session $Session -Method POST -Type rewriteaction -Payload $params -Action add
104+
105+
if ($PSBoundParameters.ContainsKey('PassThru')) {
106+
return Get-NSRewriteAction -Session $Session -Name $Item
107+
}
108+
} catch {
109+
throw $_
110+
}
111+
}
112+
}
113+
}
114+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<#
2+
Copyright 2016 Dominique Broeglin
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
#>
16+
17+
function New-NSRewritePolicy {
18+
<#
19+
.SYNOPSIS
20+
Adds a rewrite porlicy.
21+
22+
.DESCRIPTION
23+
Adds a rewrite policy.
24+
25+
.EXAMPLE
26+
New-NSRewritePolicy -Name 'pol-rewrite' -ActionName 'act-rewrite' -Expression 'true'
27+
28+
Creates a new rewrite policy which always applies the 'act-rewrite' action.
29+
30+
.PARAMETER Session
31+
The NetScaler session object.
32+
33+
.PARAMETER Name
34+
The name of rewrite policy.
35+
36+
.PARAMETER ActionName
37+
The name of the action to execute when this policy is matched.
38+
39+
.PARAMETER LogActionName
40+
The name of the log action to execute when this policy is matched.
41+
42+
Default value: ""
43+
44+
.PARAMETER Rule
45+
The rule/expression that has to be matched for this policy to apply.
46+
47+
Minimum length: 0
48+
Maximum length: 8191
49+
Alias: Expression
50+
51+
.PARAMETER Expression
52+
The rule/expression that has to be matched for this policy to apply.
53+
54+
Minimum length: 0
55+
Maximum length: 8191
56+
Alias for: Rule
57+
58+
.PARAMETER Comment
59+
Any information about the rewrite policy.
60+
61+
Minimum length: 0
62+
Maximum length: 256
63+
64+
.PARAMETER Passthru
65+
Return the newly created rewrite policy.
66+
#>
67+
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact='Low')]
68+
param(
69+
$Session = $script:session,
70+
71+
[Parameter(Mandatory, ValueFromPipeline = $true, Position = 0, ValueFromPipelineByPropertyName = $true)]
72+
[string[]]$Name,
73+
74+
[Parameter(Mandatory)]
75+
[string]$ActionName,
76+
77+
[string]$LogActionName = "",
78+
79+
[Parameter(Mandatory)]
80+
[ValidateLength(0, 8191)]
81+
[Alias('Expression')]
82+
[string]$Rule,
83+
84+
[ValidateLength(0, 256)]
85+
[string]$Comment = "",
86+
87+
[Switch]$PassThru
88+
)
89+
90+
begin {
91+
_AssertSessionActive
92+
}
93+
94+
process {
95+
foreach ($Item in $Name) {
96+
if ($PSCmdlet.ShouldProcess($Item, 'Create rewrite policy')) {
97+
try {
98+
$params = @{
99+
name = $Item
100+
action = $ActionName
101+
comment = $Comment
102+
logaction = $LogActionName
103+
rule = $Rule
104+
}
105+
_InvokeNSRestApi -Session $Session -Method POST -Type rewritepolicy -Payload $params -Action add
106+
107+
if ($PSBoundParameters.ContainsKey('PassThru')) {
108+
return Get-NSRewritePolicy -Session $Session -Name $Item
109+
}
110+
} catch {
111+
throw $_
112+
}
113+
}
114+
}
115+
}
116+
}

0 commit comments

Comments
 (0)