-
-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathSet-PASPTARule.ps1
178 lines (143 loc) · 4.77 KB
/
Set-PASPTARule.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# .ExternalHelp psPAS-help.xml
Function Set-PASPTARule {
[CmdletBinding(SupportsShouldProcess)]
param(
[parameter(
Mandatory = $true,
ValueFromPipelinebyPropertyName = $true
)]
[ValidateRange(1, [int]::MaxValue)]
[string]$id,
[parameter(
Mandatory = $false,
ValueFromPipelinebyPropertyName = $true
)]
[ValidateSet('SSH', 'WINDOWS', 'SCP', 'KEYSTROKES', 'SQL')]
[string]$category,
[parameter(
Mandatory = $false,
ValueFromPipelinebyPropertyName = $true
)]
[string]$regex,
[parameter(
Mandatory = $false,
ValueFromPipelinebyPropertyName = $true
)]
[ValidateRange(1, 100)]
[int]$score,
[parameter(
Mandatory = $false,
ValueFromPipelinebyPropertyName = $true
)]
[string]$description,
[parameter(
Mandatory = $false,
ValueFromPipelinebyPropertyName = $true
)]
[ValidateSet('NONE', 'TERMINATE', 'SUSPEND')]
[string]$response,
[parameter(
Mandatory = $false,
ValueFromPipelinebyPropertyName = $true
)]
[boolean]$active,
[parameter(
Mandatory = $false,
ValueFromPipelinebyPropertyName = $true
)]
[ValidateSet('EXCLUDE', 'INCLUDE')]
[string]$vaultUsersMode,
[parameter(
Mandatory = $false,
ValueFromPipelinebyPropertyName = $true
)]
[string[]]$vaultUsersList,
[parameter(
Mandatory = $false,
ValueFromPipelinebyPropertyName = $true
)]
[ValidateSet('EXCLUDE', 'INCLUDE')]
[string]$machinesMode,
[parameter(
Mandatory = $false,
ValueFromPipelinebyPropertyName = $true
)]
[string[]]$machinesList
)
BEGIN {
Assert-VersionRequirement -SelfHosted
Assert-VersionRequirement -RequiredVersion 10.4
$userScopeParams = [Collections.Generic.List[String]]@('vaultUsersMode', 'vaultUsersList')
$machineScopeParams = [Collections.Generic.List[String]]@('machinesMode', 'machinesList')
$scopeParams = [Collections.Generic.List[String]]@($userScopeParams + $machineScopeParams)
}#begin
PROCESS {
#Get all parameters that will be sent in the request
$boundParameters = $PSBoundParameters | Get-PASParameter
$PTARule = (Get-PASPTARule).Where({ $PSitem.ID -eq $id })
if ($null -ne $PTARule) {
Format-PutRequestObject -InputObject $PTARule -boundParameters $BoundParameters -ParametersToRemove mode, list
}
#Create URL for Request
$URI = "$($psPASSession.BaseURI)/API/pta/API/Settings/RiskyActivity/"
switch ($PSBoundParameters.keys) {
{ $scopeParams -contains $PSItem } {
#Current parameter relates to scope section of request object
if (-not($boundParameters.ContainsKey('scope'))) {
#create the scope key
$boundParameters.Add('scope', @{})
}
#determine whether vaultUsers or machines scope item
if ($userScopeParams -contains $PSItem) {
$scopeItem = 'vaultUsers'
} elseif ( $machineScopeParams -contains $PSItem) {
$scopeItem = 'machines'
}
#add scope item key to bond parameters
if (-not($boundParameters['scope'].ContainsKey($scopeItem))) {
$boundParameters['scope'].Add($scopeItem, @{})
}
#translate parameter names into request property name
#* Return only last 4 characters of parametername in lowercase
#*vaultUsersMode & machinesMode translate to "mode"
#*vaultUsersList & machinesList translate to "list"
$property = ($PSItem).Substring(($PSItem).length - 4, 4).ToLower()
if ($null -ne $PSBoundParameters[$PSItem]) {
#Add scope parameter vaultUsers & machines request values to boundParameters
$boundParameters['scope'][$scopeItem][$property] = $PSBoundParameters[$PSItem]
} else {
#clear vaultUsers/machine scope if null value specified
$boundParameters['scope'][$scopeItem] = $null
}
}
}
switch ($boundParameters) {
{ $PSItem.keys -contains 'scope' } {
#BoundParameteters Contains Scope Key
switch ($boundParameters['scope']) {
{ $PSItem.ContainsKey('vaultUsers') -and (-not($PSItem.ContainsKey('machines'))) } {
#vaultUser Scope is being updated - copy existing machines scope
$boundParameters['scope']['machines'] = $PTARule.scope.machines
}
{ $PSItem.ContainsKey('machines') -and (-not($PSItem.ContainsKey('vaultUsers'))) } {
#machines Scope is being updated - copy existing vaultUsers scope
$boundParameters['scope']['vaultUsers'] = $PTARule.scope.vaultUsers
}
}
}
default {
#No updated scope specified - Use existing scope copied from rule
'third'
$boundParameters['scope'] = $PTARule.scope
}
}
#Create body of request
#* Ensure JSON Depth of 3 to capture correct scope format
$Body = $boundParameters | Get-PASParameter -ParametersToRemove $scopeParams | ConvertTo-Json -Depth 3
if ($PSCmdlet.ShouldProcess($id, 'Update Risky Activity Rule')) {
#send request to PAS web service
Invoke-PASRestMethod -Uri $URI -Method PUT -Body $Body
}
}#process
END { }#end
}