-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.ps1
More file actions
65 lines (61 loc) · 2.88 KB
/
action.ps1
File metadata and controls
65 lines (61 loc) · 2.88 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
62
63
64
65
# HelloID-Task-SA-Target-HelloID-GroupCreate
###########################################################
# Form mapping
$formObject = @{
name = $form.name
isEnabled = [bool]$form.isEnabled
isDefault = [bool]$form.isDefault
userNames = $form.userNames
userGuids = $form.userGuids
managedByUserGuid = $form.managedByUserGuid
applicationNames = $form.applicationNames
applicationGUIDs = $form.applicationGUIDs
}
try {
Write-Information "Executing HelloID action: [CreateResource] for Group: [$($formObject.name)]"
Write-Verbose "Creating authorization headers"
# Create authorization headers with HelloID API key
$pair = "${portalApiKey}:${portalApiSecret}"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
$key = "Basic $base64"
$headers = @{"authorization" = $Key }
Write-Verbose "Creating HelloIDGroup for: [$($formObject.name)]"
$splatCreateUserParams = @{
Uri = "$($portalBaseUrl)/api/v1/groups"
Method = "POST"
Body = ([System.Text.Encoding]::UTF8.GetBytes(($formObject | ConvertTo-Json -Depth 10)))
Verbose = $false
Headers = $headers
ContentType = "application/json"
}
$response = Invoke-RestMethod @splatCreateUserParams
$auditLog = @{
Action = "CreateResource"
System = "HelloID"
TargetIdentifier = [String]$response.userGUID
TargetDisplayName = [String]$response.userName
Message = "HelloID action: [CreateResource] for Group: [$($formObject.name)] executed successfully"
IsError = $false
}
Write-Information -Tags "Audit" -MessageData $auditLog
Write-Information "HelloID action: [CreateResource] for Group: [$($formObject.name)] executed successfully"
}
catch {
$ex = $_
$auditLog = @{
Action = "CreateResource"
System = "HelloID"
TargetIdentifier = ""
TargetDisplayName = [String]$formObject.userName
Message = "Could not execute HelloID action: [CreateResource] for Group: [$($formObject.name)], error: $($ex.Exception.Message)"
IsError = $true
}
if ($($ex.Exception.GetType().FullName -eq "Microsoft.PowerShell.Commands.HttpResponseException")) {
$auditLog.Message = "Could not execute HelloID action: [CreateResource] for Group: [$($formObject.name)]"
Write-Error "Could not execute HelloID action: [CreateResource] for Group: [$($formObject.name)], error: $($ex.ErrorDetails)"
}
Write-Information -Tags "Audit" -MessageData $auditLog
Write-Error "Could not execute HelloID action: [CreateResource] for Group: [$($formObject.name)], error: $($ex.Exception.Message)"
}
###########################################################