forked from OneIdentity/SafeguardCustomPlatform
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTestTool.ps1
More file actions
61 lines (47 loc) · 2.44 KB
/
TestTool.ps1
File metadata and controls
61 lines (47 loc) · 2.44 KB
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
# This tiny script uploads the CustomPlatform connector script to SPP which is useful for testing.
# It requires the Custom Platform created earlier with a base script.
# It currently supports: Restore|Elevate|Demote|Suspend
# Base parameters
$appliance = "<spp-address>"
$username = "<spp-user-to-upload-the-script-and-run-the-task>"
# Script Upload parameters
$customPlatformScriptPath = "<path-of-custom-platform-script.json>"
$customPlatformName = "<name-of-platform-as-configured-in-spp>"
# Test parameters
$uploadScript = $true
$accountid = <id-of-test-account>
$restore = $true
$elevate = $false
$demote = $false
$suspend = $true
if (-not($AccessToken)) {
$AccessToken = Connect-Safeguard -Insecure -Appliance $appliance -Username $username -NoSessionVariable
}
if ($uploadScript) {
$customPlatform = Get-SafeguardPlatform -AccessToken $AccessToken -Appliance $appliance -Fields "id" -Insecure -Platform $customPlatformName
$script = Get-Content $customPlatformScriptPath
$bytesScript = [System.Text.Encoding]::UTF8.GetBytes($script)
$base64Script = [Convert]::ToBase64String($bytesScript)
echo "Uploading script to SPP..."
$scriptupdate = Invoke-SafeguardMethod -Method Put -RelativeUrl $("Platforms/" + $customPlatform.Id + "/Script") -Service Core -AccessToken $AccessToken -Appliance $appliance -Body $base64Script
}
if ($restore) {
sleep 4
$tasklog = Invoke-SafeguardMethod -Method Post -RelativeUrl $("AssetAccounts/" + $accountid + "/RestoreAccount?extendedLogging=true") -Service Core -AccessToken $AccessToken -Appliance $appliance
write-host "Restore task log id: " $tasklog.id
}
if ($elevate) {
sleep 4
$tasklog = Invoke-SafeguardMethod -Method Post -RelativeUrl $("AssetAccounts/" + $accountid + "/ElevateAccount?extendedLogging=true") -Service Core -AccessToken $AccessToken -Appliance $appliance
write-host "Elevate task log id: " $tasklog.id
}
if ($demote) {
sleep 4
$tasklog = Invoke-SafeguardMethod -Method Post -RelativeUrl $("AssetAccounts/" + $accountid + "/DemoteAccount?extendedLogging=true") -Service Core -AccessToken $AccessToken -Appliance $appliance
write-host "Demote task log id: " $tasklog.id
}
if ($suspend) {
sleep 4
$tasklog = Invoke-SafeguardMethod -Method Post -RelativeUrl $("AssetAccounts/" + $accountid + "/SuspendAccount?extendedLogging=true") -Service Core -AccessToken $AccessToken -Appliance $appliance
write-host "Suspend task log id: " $tasklog.id
}