Skip to content

Commit

Permalink
Merge branch 'KelvinTegelaar:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
BNWEIN authored Nov 9, 2023
2 parents c802db8 + 2a5fd7d commit 9da472b
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 43 deletions.
33 changes: 29 additions & 4 deletions ListMailboxes/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,37 @@ try {
$users = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/users/?`$top=999&`$select=id,userPrincipalName,assignedLicenses" -Tenantid $tenantfilter

$ExoRequest = @{
tenantid = $TenantFilter
cmdlet = 'Get-Mailbox'
tenantid = $TenantFilter
cmdlet = 'Get-Mailbox'
cmdParams = @{}
}

if ([bool]$Request.Query.SoftDeletedMailbox -eq $true) {
$ExoRequest.cmdParams = @{ SoftDeletedMailbox = $true }
$AllowedParameters = @(
@{Parameter = 'Anr'; Type = 'String' }
@{Parameter = 'Archive'; Type = 'Bool' }
@{Parameter = 'Filter'; Type = 'String' }
@{Parameter = 'GroupMailbox'; Type = 'Bool' }
@{Parameter = 'PublicFolder'; Type = 'Bool' }
@{Parameter = 'RecipientTypeDetails'; Type = 'String' }
@{Parameter = 'SoftDeletedMailbox'; Type = 'Bool' }
)

foreach ($Param in $Request.Query.Keys) {
$CmdParam = $AllowedParameters | Where-Object { $_.Parameter -eq $Param }
if ($CmdParam) {
switch ($CmdParam.Type) {
'String' {
if (![string]::IsNullOrEmpty($Request.Query.$Param)) {
$ExoRequest.cmdParams.$Param = $Request.Query.$Param
}
}
'Bool' {
if ([bool]$Request.Query.$Param -eq $true) {
$ExoRequest.cmdParams.$Param = $true
}
}
}
}
}

Write-Host ($ExoRequest | ConvertTo-Json)
Expand Down
28 changes: 28 additions & 0 deletions Modules/CIPPCore/Public/Entrypoints/Invoke-Z_CIPPHttpTrigger.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function Invoke-Z_CIPPHttpTrigger {
<#
.FUNCTIONALITY
Entrypoint
#>
Param(
$Request,
$TriggerMetadata
)

$FunctionName = 'Invoke-{0}' -f $Request.Params.CIPPEndpoint

Write-Host "Function: $($Request.Params.CIPPEndpoint)"

$HttpTrigger = @{
Request = $Request
TriggerMetadata = $TriggerMetadata
}

if (Get-Command -Name $FunctionName -ErrorAction SilentlyContinue) {
& $FunctionName @HttpTrigger
} else {
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = [HttpStatusCode]::NotFound
Body = 'Endpoint not found'
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ function Push-ListGraphRequestQueue {
# Write out the queue message and metadata to the information log.
Write-Host "PowerShell queue trigger function processed work item: $($QueueItem.Endpoint) - $($QueueItem.Tenant)"

#Write-Host ($QueueItem | ConvertTo-Json -Depth 5)

$TenantQueueName = '{0} - {1}' -f $QueueItem.QueueName, $QueueItem.Tenant
Update-CippQueueEntry -RowKey $QueueItem.QueueId -Status 'Processing' -Name $TenantQueueName

Expand Down Expand Up @@ -41,8 +39,7 @@ function Push-ListGraphRequestQueue {

$RawGraphRequest = try {
Get-GraphRequestList @GraphRequestParams
}
catch {
} catch {
[PSCustomObject]@{
Tenant = $QueueItem.Tenant
CippStatus = "Could not connect to tenant. $($_.Exception.message)"
Expand All @@ -63,8 +60,7 @@ function Push-ListGraphRequestQueue {
try {
Add-CIPPAzDataTableEntity @Table -Entity $GraphResults -Force | Out-Null
Update-CippQueueEntry -RowKey $QueueItem.QueueId -Status 'Completed'
}
catch {
} catch {
Write-Host "Queue Error: $($_.Exception.Message)"
Update-CippQueueEntry -RowKey $QueueItem.QueueId -Status 'Failed'
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function Push-Z_CIPPQueueTrigger {
Param($QueueItem, $TriggerMetadata)
$APIName = $QueueItem.FunctionName

$FunctionName = 'Push-{0}' -f $APIName
if (Get-Command -Name $FunctionName -ErrorAction SilentlyContinue) {
& $FunctionName -QueueItem $QueueItem -TriggerMetadata $TriggerMetadata
}
}
47 changes: 19 additions & 28 deletions Modules/CIPPCore/Public/GraphRequests/Get-GraphRequestList.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ function Get-GraphRequestList {

if ($QueueNameOverride) {
$QueueName = $QueueNameOverride
}
else {
} else {
$TextInfo = (Get-Culture).TextInfo
$QueueName = $TextInfo.ToTitleCase($DisplayName -csplit '(?=[A-Z])' -ne '' -join ' ')
}
Expand All @@ -94,20 +93,17 @@ function Get-GraphRequestList {
$Filter = "QueueId eq '{0}'" -f $QueueId
$Rows = Get-CIPPAzDataTableEntity @Table -Filter $Filter
$Type = 'Queue'
}
elseif ($TenantFilter -eq 'AllTenants' -or (!$SkipCache.IsPresent -and !$ClearCache.IsPresent -and !$CountOnly.IsPresent)) {
} elseif ($TenantFilter -eq 'AllTenants' -or (!$SkipCache.IsPresent -and !$ClearCache.IsPresent -and !$CountOnly.IsPresent)) {
$Table = Get-CIPPTable -TableName $TableName
if ($TenantFilter -eq 'AllTenants') {
$Filter = "PartitionKey eq '{0}' and QueueType eq 'AllTenants'" -f $PartitionKey
}
else {
} else {
$Filter = "PartitionKey eq '{0}' and Tenant eq '{1}'" -f $PartitionKey, $TenantFilter
}
#Write-Host $Filter
$Rows = Get-CIPPAzDataTableEntity @Table -Filter $Filter | Where-Object { $_.Timestamp.DateTime -gt (Get-Date).ToUniversalTime().AddHours(-1) }
$Type = 'Cache'
}
else {
} else {
$Type = 'None'
$Rows = @()
}
Expand All @@ -134,16 +130,14 @@ function Get-GraphRequestList {

try {
Get-GraphRequestList @GraphRequestParams | Select-Object *, @{l = 'Tenant'; e = { $_.defaultDomainName } }, @{l = 'CippStatus'; e = { 'Good' } }
}
catch {
} catch {
[PSCustomObject]@{
Tenant = $_.defaultDomainName
CippStatus = "Could not connect to tenant. $($_.Exception.message)"
}
}
}
}
else {
} else {
if ($RunningQueue) {
Write-Host 'Queue currently running'
Write-Host ($RunningQueue | ConvertTo-Json)
Expand All @@ -152,8 +146,7 @@ function Get-GraphRequestList {
QueueId = $RunningQueue.RowKey
Queued = $true
}
}
else {
} else {
$Queue = New-CippQueueEntry -Name "$QueueName (All Tenants)" -Link $CippLink -Reference $QueueReference
[PSCustomObject]@{
QueueMessage = 'Loading data for all tenants. Please check back after the job completes'
Expand All @@ -164,7 +157,8 @@ function Get-GraphRequestList {
try {
Get-Tenants -IncludeErrors | ForEach-Object {
$TenantFilter = $_.defaultDomainName
$QueueTenant = @{
$QueueTenant = [PSCustomObject]@{
FunctionName = 'ListGraphRequestQueue'
TenantFilter = $TenantFilter
Endpoint = $Endpoint
QueueId = $Queue.RowKey
Expand All @@ -176,12 +170,11 @@ function Get-GraphRequestList {
NoAuthCheck = $NoAuthCheck.IsPresent
ReverseTenantLookupProperty = $ReverseTenantLookupProperty
ReverseTenantLookup = $ReverseTenantLookup.IsPresent
} | ConvertTo-Json -Depth 5 -Compress
}

Push-OutputBinding -Name QueueItem -Value $QueueTenant
}
}
catch {
} catch {
Write-Host "QUEUE ERROR: $($_.Exception.Message)"
}
}
Expand Down Expand Up @@ -222,10 +215,10 @@ function Get-GraphRequestList {
QueueId = $RunningQueue.RowKey
Queued = $true
}
}
else {
} else {
$Queue = New-CippQueueEntry -Name $QueueName -Link $CippLink -Reference $QueueReference
$QueueTenant = @{
$QueueTenant = [PSCustomObject]@{
FunctionName = 'ListGraphRequestQueue'
TenantFilter = $TenantFilter
Endpoint = $Endpoint
QueueId = $Queue.RowKey
Expand All @@ -236,9 +229,10 @@ function Get-GraphRequestList {
NoAuthCheck = $NoAuthCheck.IsPresent
ReverseTenantLookupProperty = $ReverseTenantLookupProperty
ReverseTenantLookup = $ReverseTenantLookup.IsPresent
} | ConvertTo-Json -Depth 5 -Compress
}

Push-OutputBinding -Name QueueItem -Value $QueueTenant

[PSCustomObject]@{
QueueMessage = ('Loading {0} rows for {1}. Please check back after the job completes' -f $Count, $TenantFilter)
QueueId = $Queue.RowKey
Expand All @@ -257,20 +251,17 @@ function Get-GraphRequestList {
foreach ($Result in $GraphRequestResults) {
$Result | Select-Object @{n = 'TenantInfo'; e = { $TenantInfo | Where-Object { $Result.$ReverseTenantLookupProperty -eq $_.tenantId } } }, *
}
}
else {
} else {
$GraphRequestResults
}
}

}
catch {
} catch {
throw $_.Exception
}
}
}
}
else {
} else {
$Rows | ForEach-Object {
$_.Data | ConvertFrom-Json
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"scriptFile": "../Modules/CippEntryPoints/CippEntryPoints.psm1",
"scriptFile": "../Modules/CippEntrypoints/CippEntrypoints.psm1",
"entryPoint": "Receive-CippHttpTrigger",
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "Request",
"methods": ["get", "post"]
"methods": ["get", "post"],
"route": "{CIPPEndpoint}"
},
{
"type": "http",
Expand All @@ -18,7 +19,12 @@
"type": "queue",
"direction": "out",
"name": "QueueItem",
"queueName": "GraphRequestQueue"
"queueName": "CIPPGenericQueue"
},
{
"name": "starter",
"type": "durableClient",
"direction": "in"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
{
"scriptFile": "../Modules/CippEntryPoints/CippEntryPoints.psm1",
"entryPoint": "Receive-CippQueueTrigger",
"bindings": [
{
"name": "QueueItem",
"type": "queueTrigger",
"direction": "in",
"queueName": "GraphRequestQueue"
"queueName": "CIPPGenericQueue"
}
]
}

0 comments on commit 9da472b

Please sign in to comment.