Skip to content

Commit 496632e

Browse files
committed
Feat: AllTenants stupport for ListTenantAllowBlockList
1 parent 4044746 commit 496632e

File tree

2 files changed

+107
-8
lines changed

2 files changed

+107
-8
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
function Push-ListTenantAllowBlockListAllTenants {
2+
<#
3+
.FUNCTIONALITY
4+
Entrypoint
5+
#>
6+
[CmdletBinding()]
7+
param($Item)
8+
9+
$Tenant = Get-Tenants -TenantFilter $Item.customerId
10+
$domainName = $Tenant.defaultDomainName
11+
$Table = Get-CIPPTable -TableName 'cacheTenantAllowBlockList'
12+
$ListTypes = 'Sender', 'Url', 'FileHash', 'IP'
13+
14+
try {
15+
foreach ($ListType in $ListTypes) {
16+
$Entries = New-ExoRequest -tenantid $domainName -cmdlet 'Get-TenantAllowBlockListItems' -cmdParams @{ ListType = $ListType }
17+
foreach ($Entry in $Entries) {
18+
$CleanEntry = $Entry | Select-Object -ExcludeProperty *'@data.type'*, *'(DateTime])'*
19+
$CleanEntry | Add-Member -MemberType NoteProperty -Name Tenant -Value $domainName -Force
20+
$CleanEntry | Add-Member -MemberType NoteProperty -Name ListType -Value $ListType -Force
21+
$Entity = @{
22+
Entry = [string]($CleanEntry | ConvertTo-Json -Depth 10 -Compress)
23+
RowKey = [string](New-Guid).Guid
24+
PartitionKey = 'TenantAllowBlockList'
25+
Tenant = [string]$domainName
26+
}
27+
Add-CIPPAzDataTableEntity @Table -Entity $Entity -Force | Out-Null
28+
}
29+
}
30+
} catch {
31+
$ErrorEntry = [pscustomobject]@{
32+
Tenant = $domainName
33+
ListType = 'Error'
34+
Identity = 'Error'
35+
DisplayName = "Could not retrieve tenant allow/block list: $($_.Exception.Message)"
36+
Timestamp = (Get-Date).ToString('s')
37+
}
38+
$Entity = @{
39+
Entry = [string]($ErrorEntry | ConvertTo-Json -Depth 10 -Compress)
40+
RowKey = [string](New-Guid).Guid
41+
PartitionKey = 'TenantAllowBlockList'
42+
Tenant = [string]$domainName
43+
}
44+
Add-CIPPAzDataTableEntity @Table -Entity $Entity -Force | Out-Null
45+
}
46+
}

Modules/CIPPCore/Public/Entrypoints/Invoke-ListTenantAllowBlockList.ps1

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,74 @@ function Invoke-ListTenantAllowBlockList {
1111
$TenantFilter = $Request.Query.tenantFilter
1212
$ListTypes = 'Sender', 'Url', 'FileHash', 'IP'
1313
try {
14-
$Results = $ListTypes | ForEach-Object -Parallel {
15-
Import-Module CIPPCore
16-
$TempResults = New-ExoRequest -tenantid $using:TenantFilter -cmdlet 'Get-TenantAllowBlockListItems' -cmdParams @{ListType = $_ }
17-
$TempResults | Add-Member -MemberType NoteProperty -Name ListType -Value $_
18-
$TempResults | Select-Object -ExcludeProperty *'@data.type'*, *'(DateTime])'*
19-
} -ThrottleLimit 5
20-
14+
if ($TenantFilter -ne 'AllTenants') {
15+
$Results = $ListTypes | ForEach-Object -Parallel {
16+
Import-Module CIPPCore
17+
$TempResults = New-ExoRequest -tenantid $using:TenantFilter -cmdlet 'Get-TenantAllowBlockListItems' -cmdParams @{ ListType = $_ }
18+
$TempResults | Add-Member -MemberType NoteProperty -Name ListType -Value $_ -Force
19+
$TempResults | Add-Member -MemberType NoteProperty -Name Tenant -Value $using:TenantFilter -Force
20+
$TempResults | Select-Object -ExcludeProperty *'@data.type'*, *'(DateTime])'*
21+
} -ThrottleLimit 5
22+
$Metadata = [PSCustomObject]@{}
23+
} else {
24+
$Table = Get-CIPPTable -TableName 'cacheTenantAllowBlockList'
25+
$PartitionKey = 'TenantAllowBlockList'
26+
$Filter = "PartitionKey eq '$PartitionKey'"
27+
$Rows = Get-CIPPAzDataTableEntity @Table -filter $Filter | Where-Object -Property Timestamp -GT (Get-Date).AddMinutes(-60)
28+
$QueueReference = '{0}-{1}' -f $TenantFilter, $PartitionKey
29+
$RunningQueue = Invoke-ListCippQueue -Reference $QueueReference | Where-Object { $_.Status -notmatch 'Completed' -and $_.Status -notmatch 'Failed' }
30+
if ($RunningQueue) {
31+
$Metadata = [PSCustomObject]@{
32+
QueueMessage = 'Still loading data for all tenants. Please check back in a few more minutes'
33+
QueueId = $RunningQueue.RowKey
34+
}
35+
$Results = @()
36+
} elseif (!$Rows -and !$RunningQueue) {
37+
$TenantList = Get-Tenants -IncludeErrors
38+
$Queue = New-CippQueueEntry -Name 'Tenant Allow/Block List - All Tenants' -Link '/tenant/administration/allow-block-list?customerId=AllTenants' -Reference $QueueReference -TotalTasks ($TenantList | Measure-Object).Count
39+
$Metadata = [PSCustomObject]@{
40+
QueueMessage = 'Loading data for all tenants. Please check back in a few minutes'
41+
QueueId = $Queue.RowKey
42+
}
43+
$InputObject = [PSCustomObject]@{
44+
OrchestratorName = 'TenantAllowBlockListOrchestrator'
45+
QueueFunction = @{
46+
FunctionName = 'GetTenants'
47+
QueueId = $Queue.RowKey
48+
TenantParams = @{
49+
IncludeErrors = $true
50+
}
51+
DurableName = 'ListTenantAllowBlockListAllTenants'
52+
}
53+
SkipLog = $true
54+
}
55+
Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Depth 5 -Compress) | Out-Null
56+
$Results = @()
57+
} else {
58+
$Metadata = [PSCustomObject]@{
59+
QueueId = $RunningQueue.RowKey ?? $null
60+
}
61+
$Results = foreach ($Row in $Rows) {
62+
$Row.Entry | ConvertFrom-Json
63+
}
64+
}
65+
}
2166
$StatusCode = [HttpStatusCode]::OK
2267
} catch {
2368
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
2469
$StatusCode = [HttpStatusCode]::Forbidden
2570
$Results = $ErrorMessage
2671
}
72+
73+
if (!$Body) {
74+
$Body = [PSCustomObject]@{
75+
Results = @($Results)
76+
Metadata = $Metadata
77+
}
78+
}
79+
2780
return [HttpResponseContext]@{
2881
StatusCode = $StatusCode
29-
Body = @($Results)
82+
Body = $Body
3083
}
3184
}

0 commit comments

Comments
 (0)