-
-
Notifications
You must be signed in to change notification settings - Fork 90
/
Add-PASPTARule.ps1
141 lines (110 loc) · 3.51 KB
/
Add-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
# .ExternalHelp psPAS-help.xml
Function Add-PASPTARule {
[CmdletBinding()]
param(
[parameter(
Mandatory = $true,
ValueFromPipelinebyPropertyName = $true
)]
[ValidateSet('SSH', 'WINDOWS', 'SCP', 'KEYSTROKES', 'SQL')]
[string]$category,
[parameter(
Mandatory = $true,
ValueFromPipelinebyPropertyName = $true
)]
[string]$regex,
[parameter(
Mandatory = $true,
ValueFromPipelinebyPropertyName = $true
)]
[ValidateRange(1, 100)]
[int]$score,
[parameter(
Mandatory = $true,
ValueFromPipelinebyPropertyName = $true
)]
[string]$description,
[parameter(
Mandatory = $true,
ValueFromPipelinebyPropertyName = $true
)]
[ValidateSet('NONE', 'TERMINATE', 'SUSPEND')]
[string]$response,
[parameter(
Mandatory = $true,
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
#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 paramer 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()
#Add scope parameter vaultUsers & machines request values to boundParameters
$boundParameters['scope'][$scopeItem][$property] = $PSBoundParameters[$PSItem]
}
}
#Create body of request
#* Ensure JSON Depth of 3 to capture correct scope format
$Body = $boundParameters | Get-PASParameter -ParametersToRemove $scopeParams | ConvertTo-Json -Depth 3
#send request to PAS web service
$result = Invoke-PASRestMethod -Uri $URI -Method POST -Body $Body
If ($null -ne $result) {
#Return Results
$result | Add-ObjectDetail -typename 'psPAS.CyberArk.Vault.PTA.Rule'
}
}#process
END { }#end
}