Skip to content

Commit 5169c66

Browse files
committed
Validate JSON before parsing config in Invoke-ListExtensionsConfig
Added a check using Test-Json to ensure the config is valid JSON before attempting to parse it. This prevents errors when the config is not in JSON format and returns an empty object if validation fails.
1 parent 51ff626 commit 5169c66

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed
Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Function Invoke-ListExtensionsConfig {
1+
function Invoke-ListExtensionsConfig {
22
<#
33
.FUNCTIONALITY
44
Entrypoint,AnyTenant
@@ -9,27 +9,32 @@ Function Invoke-ListExtensionsConfig {
99
param($Request, $TriggerMetadata)
1010
$Table = Get-CIPPTable -TableName Extensionsconfig
1111
try {
12-
$Body = (Get-CIPPAzDataTableEntity @Table).config | ConvertFrom-Json -Depth 10 -ErrorAction Stop
13-
if ($Body.HaloPSA.TicketType -and !$Body.HaloPSA.TicketType.value) {
14-
# translate ticket type to autocomplete format
15-
Write-Information "Ticket Type: $($Body.HaloPSA.TicketType)"
16-
$Types = Get-HaloTicketType
17-
$Type = $Types | Where-Object { $_.id -eq $Body.HaloPSA.TicketType }
18-
#Write-Information ($Type | ConvertTo-Json)
19-
if ($Type) {
20-
$Body.HaloPSA.TicketType = @{
21-
label = $Type.name
22-
value = $Type.id
12+
$Config = (Get-CIPPAzDataTableEntity @Table).config
13+
if (Test-Json -Json $Config) {
14+
$Body = $Config | ConvertFrom-Json -Depth 10 -ErrorAction Stop
15+
if ($Body.HaloPSA.TicketType -and !$Body.HaloPSA.TicketType.value) {
16+
# translate ticket type to autocomplete format
17+
Write-Information "Ticket Type: $($Body.HaloPSA.TicketType)"
18+
$Types = Get-HaloTicketType
19+
$Type = $Types | Where-Object { $_.id -eq $Body.HaloPSA.TicketType }
20+
#Write-Information ($Type | ConvertTo-Json)
21+
if ($Type) {
22+
$Body.HaloPSA.TicketType = @{
23+
label = $Type.name
24+
value = $Type.id
25+
}
2326
}
2427
}
28+
} else {
29+
$Body = @{}
2530
}
2631
} catch {
2732
Write-Information (Get-CippException -Exception $_ | ConvertTo-Json)
2833
$Body = @{}
2934
}
3035
return [HttpResponseContext]@{
31-
StatusCode = [HttpStatusCode]::OK
32-
Body = $body
33-
}
36+
StatusCode = [HttpStatusCode]::OK
37+
Body = $body
38+
}
3439

3540
}

0 commit comments

Comments
 (0)