Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function offloading #1058

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

Function Invoke-ExecOffloadFunctions {
<#
.FUNCTIONALITY
Entrypoint
.ROLE
CIPP.SuperAdmin.ReadWrite
#>
[CmdletBinding()]
param($Request, $TriggerMetadata)

$roles = ([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($request.headers.'x-ms-client-principal')) | ConvertFrom-Json).userRoles
if ('superadmin' -notin $roles) {
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::Forbidden
Body = @{ error = 'You do not have permission to perform this action.' }
})
return
} else {
$Table = Get-CippTable -tablename 'Config'

if ($Request.Query.Action -eq 'ListCurrent') {
$CurrentState = Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq 'OffloadFunctions' and RowKey eq 'OffloadFunctions'"
$CurrentState = if (!$CurrentState) {
[PSCustomObject]@{
OffloadFunctions = $false
}
} else {
[PSCustomObject]@{
OffloadFunctions = $CurrentState.state
}
}
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = $CurrentState
})
} else {
Add-CIPPAzDataTableEntity @Table -Entity @{
PartitionKey = 'OffloadFunctions'
RowKey = 'OffloadFunctions'
state = $request.Body.OffloadFunctions
} -Force

if ($Request.Body.OffloadFunctions) {
$Results = 'Enabled Offload Functions'
} else {
$Results = 'Disabled Offload Functions'
}
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::OK
Body = @{ results = $Results }
})
}

}
}
3 changes: 1 addition & 2 deletions Modules/CIPPCore/Public/GraphHelper/Write-LogMessage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ function Write-LogMessage {
if (!$tenant) { $tenant = 'None' }
if (!$username) { $username = 'CIPP' }
if ($sev -eq 'Debug' -and $env:DebugMode -ne $true) {
Write-Information 'Not writing to log file - Debug mode is not enabled.'
return
}
$PartitionKey = (Get-Date -UFormat '%Y%m%d').ToString()
Expand All @@ -48,4 +47,4 @@ function Write-LogMessage {

$Table.Entity = $TableRow
Add-CIPPAzDataTableEntity @Table | Out-Null
}
}
6 changes: 5 additions & 1 deletion Scheduler_GetQueue/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ $Tasks = foreach ($Tenant in $Tenants) {
}
}

if (($Tasks | Measure-Object).Count -eq 0) {
return
}

$Queue = New-CippQueueEntry -Name 'Scheduler' -TotalTasks ($Tasks | Measure-Object).Count

$Batch = foreach ($Task in $Tasks) {
Expand All @@ -49,4 +53,4 @@ $InputObject = [PSCustomObject]@{
#Write-Information ($InputObject | ConvertTo-Json)
$InstanceId = Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Depth 5 -Compress)
Write-Information "Started orchestration with ID = '$InstanceId'"
#$Orchestrator = New-OrchestrationCheckStatusResponse -Request $Request -InstanceId $InstanceId
#$Orchestrator = New-OrchestrationCheckStatusResponse -Request $Request -InstanceId $InstanceId
8 changes: 8 additions & 0 deletions Scheduler_PollAuditLogs/run.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
param($Timer)

try {
$ConfigTable = Get-CIPPTable -tablename Config
$Config = Get-CIPPAzDataTableEntity @ConfigTable -Filter "PartitionKey eq 'OffloadFunctions' and RowKey eq 'OffloadFunctions'"

if ($Config -and $Config.state -eq $true) {
Write-Host 'Offload functions are enabled. Exiting.'
return 0
}

$webhookTable = Get-CIPPTable -tablename webhookTable
$Webhooks = Get-CIPPAzDataTableEntity @webhookTable -Filter "Version eq '3'" | Where-Object { $_.Resource -match '^Audit' -and $_.Status -ne 'Disabled' }
if (($Webhooks | Measure-Object).Count -eq 0) {
Expand Down