Skip to content

Commit

Permalink
CPV Durable
Browse files Browse the repository at this point in the history
Cleanup queue output bindings
  • Loading branch information
JohnDuprey committed Mar 14, 2024
1 parent 06e7763 commit d321b8d
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function Push-UpdatePermissionsQueue {
# Input bindings are passed in via param block.
param($Item)
Write-Host "Applying permissions for $($Item.defaultDomainName)"
$Table = Get-CIPPTable -TableName cpvtenants
$CPVRows = Get-CIPPAzDataTableEntity @Table | Where-Object -Property Tenant -EQ $Item.customerId
if (!$CPVRows -or $ENV:ApplicationID -notin $CPVRows.applicationId) {
Write-LogMessage -tenant $Item.defaultDomainName -tenantId $Item.customerId -message 'A New tenant has been added, or a new CIPP-SAM Application is in use' -Sev 'Warn' -API 'NewTenant'
Write-Host 'Adding CPV permissions'
Set-CIPPCPVConsent -Tenantfilter $Item.defaultDomainName
}

Add-CIPPApplicationPermission -RequiredResourceAccess 'CippDefaults' -ApplicationId $ENV:ApplicationID -tenantfilter $Item.defaultDomainName
Add-CIPPDelegatedPermission -RequiredResourceAccess 'CippDefaults' -ApplicationId $ENV:ApplicationID -tenantfilter $Item.defaultDomainName

Write-LogMessage -tenant $Item.defaultDomainName -tenantId $Item.customerId -message "Updated permissions for $($Item.defaultDomainName)" -Sev 'Info' -API 'UpdatePermissionsQueue'
}
6 changes: 0 additions & 6 deletions Scheduler_GetQueue/function.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
"direction": "in",
"type": "timerTrigger"
},
{
"type": "queue",
"direction": "out",
"name": "QueueItem",
"queueName": "CIPPGenericQueue"
},
{
"name": "starter",
"type": "durableClient",
Expand Down
6 changes: 0 additions & 6 deletions Scheduler_Standards/function.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
"direction": "in",
"type": "timerTrigger"
},
{
"type": "queue",
"direction": "out",
"name": "QueueItem",
"queueName": "CIPPGenericQueue"
},
{
"name": "starter",
"type": "durableClient",
Expand Down
7 changes: 3 additions & 4 deletions UpdatePermissions/function.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
"schedule": "0 0 0 * * *"
},
{
"type": "queue",
"direction": "out",
"name": "Msg",
"queueName": "cpvqueue"
"name": "starter",
"type": "durableClient",
"direction": "in"
}
]
}
17 changes: 13 additions & 4 deletions UpdatePermissions/run.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
# Input bindings are passed in via param block.
param($Timer)

$Tenants = get-tenants -IncludeErrors | Where-Object { $_.customerId -ne $env:TenantId }
foreach ($Row in $Tenants) {
Push-OutputBinding -Name Msg -Value $row
}
try {
$Tenants = Get-Tenants -IncludeErrors | Where-Object { $_.customerId -ne $env:TenantId } | ForEach-Object { $_ | Add-Member -NotePropertyName FunctionName -NotePropertyValue 'UpdatePermissionsQueue'; $_ }

if (($Tenants | Measure-Object).Count -gt 0) {
$InputObject = [PSCustomObject]@{
OrchestratorName = 'UpdatePermissionsOrchestrator'
Batch = @($Tenants)
}
#Write-Host ($InputObject | ConvertTo-Json)
$InstanceId = Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Depth 5)
Write-Host "Started permissions orchestration with ID = '$InstanceId'"
}
} catch {}
10 changes: 0 additions & 10 deletions UpdatePermissionsQueue/function.json

This file was deleted.

15 changes: 0 additions & 15 deletions UpdatePermissionsQueue/run.ps1

This file was deleted.

0 comments on commit d321b8d

Please sign in to comment.