|
1 | 1 | using namespace System.Net |
2 | 2 |
|
3 | 3 | Function Invoke-ExecExtensionMapping { |
4 | | - <# |
| 4 | + <# |
5 | 5 | .FUNCTIONALITY |
6 | 6 | Entrypoint |
7 | 7 | .ROLE |
8 | 8 | CIPP.Extension.ReadWrite |
9 | 9 | #> |
10 | | - [CmdletBinding()] |
11 | | - param($Request, $TriggerMetadata) |
| 10 | + [CmdletBinding()] |
| 11 | + param($Request, $TriggerMetadata) |
12 | 12 |
|
13 | | - $APIName = $Request.Params.CIPPEndpoint |
14 | | - $Headers = $Request.Headers |
15 | | - Write-LogMessage -headers $Headers -API $APIName -message 'Accessed this API' -Sev 'Debug' |
| 13 | + $APIName = $Request.Params.CIPPEndpoint |
| 14 | + $Headers = $Request.Headers |
| 15 | + Write-LogMessage -headers $Headers -API $APIName -message 'Accessed this API' -Sev 'Debug' |
16 | 16 |
|
17 | | - $Table = Get-CIPPTable -TableName CippMapping |
| 17 | + $Table = Get-CIPPTable -TableName CippMapping |
18 | 18 |
|
19 | | - if ($Request.Query.List) { |
20 | | - switch ($Request.Query.List) { |
21 | | - 'HaloPSA' { |
22 | | - $Result = Get-HaloMapping -CIPPMapping $Table |
23 | | - } |
24 | | - 'NinjaOne' { |
25 | | - $Result = Get-NinjaOneOrgMapping -CIPPMapping $Table |
26 | | - } |
27 | | - 'NinjaOneFields' { |
28 | | - $Result = Get-NinjaOneFieldMapping -CIPPMapping $Table |
29 | | - } |
30 | | - 'Hudu' { |
31 | | - $Result = Get-HuduMapping -CIPPMapping $Table |
32 | | - } |
33 | | - 'HuduFields' { |
34 | | - $Result = Get-HuduFieldMapping -CIPPMapping $Table |
35 | | - } |
36 | | - 'Sherweb' { |
37 | | - $Result = Get-SherwebMapping -CIPPMapping $Table |
38 | | - } |
39 | | - 'HaloPSAFields' { |
40 | | - $TicketTypes = Get-HaloTicketType |
41 | | - $Result = @{'TicketTypes' = $TicketTypes } |
42 | | - } |
43 | | - 'PWPushFields' { |
44 | | - $Accounts = Get-PwPushAccount |
45 | | - $Result = @{ |
46 | | - 'Accounts' = $Accounts |
47 | | - } |
48 | | - } |
| 19 | + if ($Request.Query.List) { |
| 20 | + switch ($Request.Query.List) { |
| 21 | + 'HaloPSA' { |
| 22 | + $Result = Get-HaloMapping -CIPPMapping $Table |
| 23 | + } |
| 24 | + 'NinjaOne' { |
| 25 | + $Result = Get-NinjaOneOrgMapping -CIPPMapping $Table |
| 26 | + } |
| 27 | + 'NinjaOneFields' { |
| 28 | + $Result = Get-NinjaOneFieldMapping -CIPPMapping $Table |
| 29 | + } |
| 30 | + 'Hudu' { |
| 31 | + $Result = Get-HuduMapping -CIPPMapping $Table |
| 32 | + } |
| 33 | + 'HuduFields' { |
| 34 | + $Result = Get-HuduFieldMapping -CIPPMapping $Table |
| 35 | + } |
| 36 | + 'Sherweb' { |
| 37 | + $Result = Get-SherwebMapping -CIPPMapping $Table |
| 38 | + } |
| 39 | + 'HaloPSAFields' { |
| 40 | + $TicketTypes = Get-HaloTicketType |
| 41 | + $Outcomes = Get-HaloTicketOutcome |
| 42 | + $Result = @{ |
| 43 | + 'TicketTypes' = $TicketTypes |
| 44 | + 'Outcomes' = $Outcomes |
49 | 45 | } |
| 46 | + } |
| 47 | + 'PWPushFields' { |
| 48 | + $Accounts = Get-PwPushAccount |
| 49 | + $Result = @{ |
| 50 | + 'Accounts' = $Accounts |
| 51 | + } |
| 52 | + } |
50 | 53 | } |
| 54 | + } |
51 | 55 |
|
52 | | - try { |
53 | | - if ($Request.Query.AddMapping) { |
54 | | - switch ($Request.Query.AddMapping) { |
55 | | - 'Sherweb' { |
56 | | - $Result = Set-SherwebMapping -CIPPMapping $Table -APIName $APIName -Request $Request |
57 | | - } |
58 | | - 'HaloPSA' { |
59 | | - $Result = Set-HaloMapping -CIPPMapping $Table -APIName $APIName -Request $Request |
60 | | - } |
61 | | - 'NinjaOne' { |
62 | | - $Result = Set-NinjaOneOrgMapping -CIPPMapping $Table -APIName $APIName -Request $Request |
63 | | - Register-CIPPExtensionScheduledTasks |
64 | | - } |
65 | | - 'NinjaOneFields' { |
66 | | - $Result = Set-NinjaOneFieldMapping -CIPPMapping $Table -APIName $APIName -Request $Request -TriggerMetadata $TriggerMetadata |
67 | | - Register-CIPPExtensionScheduledTasks |
68 | | - } |
69 | | - 'Hudu' { |
70 | | - $Result = Set-HuduMapping -CIPPMapping $Table -APIName $APIName -Request $Request |
71 | | - Register-CIPPExtensionScheduledTasks |
72 | | - } |
73 | | - 'HuduFields' { |
74 | | - $Result = Set-ExtensionFieldMapping -CIPPMapping $Table -APIName $APIName -Request $Request -Extension 'Hudu' |
75 | | - Register-CIPPExtensionScheduledTasks |
76 | | - } |
77 | | - } |
| 56 | + try { |
| 57 | + if ($Request.Query.AddMapping) { |
| 58 | + switch ($Request.Query.AddMapping) { |
| 59 | + 'Sherweb' { |
| 60 | + $Result = Set-SherwebMapping -CIPPMapping $Table -APIName $APIName -Request $Request |
| 61 | + } |
| 62 | + 'HaloPSA' { |
| 63 | + $Result = Set-HaloMapping -CIPPMapping $Table -APIName $APIName -Request $Request |
| 64 | + } |
| 65 | + 'NinjaOne' { |
| 66 | + $Result = Set-NinjaOneOrgMapping -CIPPMapping $Table -APIName $APIName -Request $Request |
| 67 | + Register-CIPPExtensionScheduledTasks |
| 68 | + } |
| 69 | + 'NinjaOneFields' { |
| 70 | + $Result = Set-NinjaOneFieldMapping -CIPPMapping $Table -APIName $APIName -Request $Request -TriggerMetadata $TriggerMetadata |
| 71 | + Register-CIPPExtensionScheduledTasks |
78 | 72 | } |
79 | | - $StatusCode = [HttpStatusCode]::OK |
80 | | - } catch { |
81 | | - $ErrorMessage = Get-CippException -Exception $_ |
82 | | - $Result = "Mapping API failed. $($ErrorMessage.NormalizedError)" |
83 | | - Write-LogMessage -API $APIName -headers $Headers -message $Result -Sev 'Error' -LogData $ErrorMessage |
84 | | - $StatusCode = [HttpStatusCode]::InternalServerError |
| 73 | + 'Hudu' { |
| 74 | + $Result = Set-HuduMapping -CIPPMapping $Table -APIName $APIName -Request $Request |
| 75 | + Register-CIPPExtensionScheduledTasks |
| 76 | + } |
| 77 | + 'HuduFields' { |
| 78 | + $Result = Set-ExtensionFieldMapping -CIPPMapping $Table -APIName $APIName -Request $Request -Extension 'Hudu' |
| 79 | + Register-CIPPExtensionScheduledTasks |
| 80 | + } |
| 81 | + } |
85 | 82 | } |
| 83 | + $StatusCode = [HttpStatusCode]::OK |
| 84 | + } |
| 85 | + catch { |
| 86 | + $ErrorMessage = Get-CippException -Exception $_ |
| 87 | + $Result = "Mapping API failed. $($ErrorMessage.NormalizedError)" |
| 88 | + Write-LogMessage -API $APIName -headers $Headers -message $Result -Sev 'Error' -LogData $ErrorMessage |
| 89 | + $StatusCode = [HttpStatusCode]::InternalServerError |
| 90 | + } |
86 | 91 |
|
87 | | - try { |
88 | | - if ($Request.Query.AutoMapping) { |
89 | | - switch ($Request.Query.AutoMapping) { |
90 | | - 'NinjaOne' { |
91 | | - $Batch = [PSCustomObject]@{ |
92 | | - 'NinjaAction' = 'StartAutoMapping' |
93 | | - 'FunctionName' = 'NinjaOneQueue' |
94 | | - } |
95 | | - $InputObject = [PSCustomObject]@{ |
96 | | - OrchestratorName = 'NinjaOneOrchestrator' |
97 | | - Batch = @($Batch) |
98 | | - } |
99 | | - #Write-Host ($InputObject | ConvertTo-Json) |
100 | | - $InstanceId = Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Depth 5 -Compress) |
101 | | - Write-Host "Started permissions orchestration with ID = '$InstanceId'" |
102 | | - $Result = 'AutoMapping Request has been queued. Exact name matches will appear first and matches on device names and serials will take longer. Please check the CIPP Logbook and refresh the page once complete.' |
103 | | - } |
104 | | - |
105 | | - } |
| 92 | + try { |
| 93 | + if ($Request.Query.AutoMapping) { |
| 94 | + switch ($Request.Query.AutoMapping) { |
| 95 | + 'NinjaOne' { |
| 96 | + $Batch = [PSCustomObject]@{ |
| 97 | + 'NinjaAction' = 'StartAutoMapping' |
| 98 | + 'FunctionName' = 'NinjaOneQueue' |
| 99 | + } |
| 100 | + $InputObject = [PSCustomObject]@{ |
| 101 | + OrchestratorName = 'NinjaOneOrchestrator' |
| 102 | + Batch = @($Batch) |
| 103 | + } |
| 104 | + #Write-Host ($InputObject | ConvertTo-Json) |
| 105 | + $InstanceId = Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Depth 5 -Compress) |
| 106 | + Write-Host "Started permissions orchestration with ID = '$InstanceId'" |
| 107 | + $Result = 'AutoMapping Request has been queued. Exact name matches will appear first and matches on device names and serials will take longer. Please check the CIPP Logbook and refresh the page once complete.' |
106 | 108 | } |
107 | | - $StatusCode = [HttpStatusCode]::OK |
108 | | - } catch { |
109 | | - $ErrorMessage = Get-CippException -Exception $_ |
110 | | - $Result = "Mapping API failed. $($ErrorMessage.NormalizedError)" |
111 | | - Write-LogMessage -API $APIName -headers $Headers -message $Result -Sev 'Error' -LogData $ErrorMessage |
112 | | - $StatusCode = [HttpStatusCode]::InternalServerError |
| 109 | + |
| 110 | + } |
113 | 111 | } |
| 112 | + $StatusCode = [HttpStatusCode]::OK |
| 113 | + } |
| 114 | + catch { |
| 115 | + $ErrorMessage = Get-CippException -Exception $_ |
| 116 | + $Result = "Mapping API failed. $($ErrorMessage.NormalizedError)" |
| 117 | + Write-LogMessage -API $APIName -headers $Headers -message $Result -Sev 'Error' -LogData $ErrorMessage |
| 118 | + $StatusCode = [HttpStatusCode]::InternalServerError |
| 119 | + } |
114 | 120 |
|
115 | | - # Associate values to output bindings by calling 'Push-OutputBinding'. |
116 | | - Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ |
117 | | - StatusCode = $StatusCode |
118 | | - Body = $Result |
119 | | - }) |
| 121 | + # Associate values to output bindings by calling 'Push-OutputBinding'. |
| 122 | + Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ |
| 123 | + StatusCode = $StatusCode |
| 124 | + Body = $Result |
| 125 | + }) |
120 | 126 |
|
121 | 127 | } |
0 commit comments