Skip to content

Commit

Permalink
Merge pull request #973 from JohnDuprey/dev
Browse files Browse the repository at this point in the history
Extensions
  • Loading branch information
JohnDuprey authored Jul 10, 2024
2 parents 0fa7ed6 + 301c474 commit 88be521
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using namespace System.Net

Function Invoke-ListExtensionSync {
<#
.FUNCTIONALITY
Entrypoint
.ROLE
CIPP.Extension.Read
#>
[CmdletBinding()]
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'

# Write to the Azure Functions log stream.
Write-Host 'PowerShell HTTP trigger function processed a request.'
$ScheduledTasksTable = Get-CIPPTable -TableName 'ScheduledTasks'
$ScheduledTasks = Get-CIPPAzDataTableEntity @ScheduledTasksTable -Filter 'Hidden eq true' | Where-Object { $_.Command -match 'CippExtension' }

$AllowedTenants = Test-CIPPAccess -Request $Request -TenantList
$TenantList = Get-Tenants -IncludeErrors
$AllTasksArrayList = [system.collections.generic.list[object]]::new()

foreach ($Task in $ScheduledTasks) {
if ($Task.Results -and (Test-Json -Json $Task.Results -ErrorAction SilentlyContinue)) {
$Results = $Task.Results | ConvertFrom-Json
} else {
$Results = $Task.Results
}

$TaskEntry = [PSCustomObject]@{
RowKey = $Task.RowKey
PartitionKey = $Task.PartitionKey
Tenant = $Task.Tenant
Name = $Task.Name
SyncType = $Task.SyncType
ScheduledTime = $Task.ScheduledTime
ExecutedTime = $Task.ExecutedTime
RepeatsEvery = $Task.Recurrence
Results = $Results
}

if ($AllowedTenants -notcontains 'AllTenants') {
$Tenant = $TenantList | Where-Object -Property defaultDomainName -EQ $Task.Tenant
if ($AllowedTenants -contains $Tenant.customerId) {
$AllTasksArrayList.Add($TaskEntry)
}
} else {
$AllTasksArrayList.Add($TaskEntry)
}
}
Write-Host ($AllTasksArrayList | ConvertTo-Json -Depth 5 -Compress)
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = ConvertTo-Json -Depth 5 -InputObject $($AllTasksArrayList)
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ function Sync-CippExtensionData {
} catch {
$LastSync.Status = 'Failed'
$LastSync.Error = [string](Get-CippException -Exception $_ | ConvertTo-Json -Compress)
throw "Failed to sync data: $($_.Exception.Message)"
throw "Failed to sync data: $(Get-NormalizedError -message $_.Exception.Message)"
} finally {
Add-CIPPAzDataTableEntity @Table -Entity $LastSync -Force
}
Expand Down
7 changes: 4 additions & 3 deletions Modules/CippExtensions/Public/New-CippExtAlert.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ function New-CippExtAlert {
$Table = Get-CIPPTable -TableName Extensionsconfig
$Configuration = (Get-CIPPAzDataTableEntity @Table).config | ConvertFrom-Json -Depth 10
$MappingTable = Get-CIPPTable -TableName CippMapping
$MappingFile = (Get-CIPPAzDataTableEntity @MappingTable)

foreach ($ConfigItem in $Configuration.psobject.properties.name) {
switch ($ConfigItem) {
'HaloPSA' {
If ($Configuration.HaloPSA.enabled) {
$MappingFile = Get-CIPPAzDataTableEntity @MappingTable -Filter 'PartitionKey eq HaloMapping'
$TenantId = (Get-Tenants | Where-Object defaultDomainName -EQ $Alert.TenantId).customerId
Write-Host "TenantId: $TenantId"
$MappedId = ($MappingFile | Where-Object { $_.PartitionKey -eq 'HaloMapping' -and $_.RowKey -eq $TenantId }).IntegrationId
$MappedId = ($MappingFile | Where-Object { $_.RowKey -eq $TenantId }).IntegrationId
Write-Host "MappedId: $MappedId"
if (!$mappedId) { $MappedId = 1 }
Write-Host "MappedId: $MappedId"
Expand All @@ -30,4 +31,4 @@ function New-CippExtAlert {
}
}

}
}

0 comments on commit 88be521

Please sign in to comment.