Skip to content

Commit ff48a6b

Browse files
authored
Merge pull request #563 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 5d4febc + 53c35e6 commit ff48a6b

File tree

5 files changed

+68
-49
lines changed

5 files changed

+68
-49
lines changed

Modules/CIPPCore/Public/Clear-CippDurables.ps1

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
function Clear-CippDurables {
22
[CmdletBinding(SupportsShouldProcess = $true)]
3-
Param()
3+
param()
44
# Collect info
55
$StorageContext = New-AzStorageContext -ConnectionString $env:AzureWebJobsStorage
66
$FunctionName = $env:WEBSITE_SITE_NAME -replace '-', ''
77

88
# Get orchestrators
99
$InstancesTable = Get-CippTable -TableName ('{0}Instances' -f $FunctionName)
1010
$HistoryTable = Get-CippTable -TableName ('{0}History' -f $FunctionName)
11+
$QueueTable = Get-CippTable -TableName 'CippQueue'
12+
$CippQueueTasks = Get-CippTable -TableName 'CippQueueTasks'
13+
14+
Remove-AzDataTable @InstancesTable
15+
Remove-AzDataTable @HistoryTable
16+
Remove-AzDataTable @QueueTable
17+
Remove-AzDataTable @CippQueueTasks
1118

1219
$Queues = Get-AzStorageQueue -Context $StorageContext -Name ('{0}*' -f $FunctionName) | Select-Object -Property Name, ApproximateMessageCount, QueueClient
1320

@@ -19,8 +26,6 @@ function Clear-CippDurables {
1926
}
2027
}
2128

22-
Remove-AzDataTable @InstancesTable
23-
Remove-AzDataTable @HistoryTable
2429
$BlobContainer = '{0}-largemessages' -f $FunctionName
2530
if (Get-AzStorageContainer -Name $BlobContainer -Context $StorageContext -ErrorAction SilentlyContinue) {
2631
Write-Information "- Removing blob container: $BlobContainer"
@@ -29,32 +34,6 @@ function Clear-CippDurables {
2934
}
3035
}
3136

32-
$QueueTable = Get-CippTable -TableName 'CippQueue'
33-
$CippQueue = Invoke-ListCippQueue
34-
$QueueEntities = foreach ($Queue in $CippQueue) {
35-
if ($Queue.Status -eq 'Running') {
36-
$Queue.TotalTasks = $Queue.CompletedTasks
37-
$Queue | Select-Object -Property PartitionKey, RowKey, TotalTasks
38-
}
39-
}
40-
if (($QueueEntities | Measure-Object).Count -gt 0) {
41-
if ($PSCmdlet.ShouldProcess('Queues', 'Mark Failed')) {
42-
Update-AzDataTableEntity -Force @QueueTable -Entity $QueueEntities
43-
}
44-
}
45-
46-
$CippQueueTasks = Get-CippTable -TableName 'CippQueueTasks'
47-
$RunningTasks = Get-CIPPAzDataTableEntity @CippQueueTasks -Filter "PartitionKey eq 'Task' and Status eq 'Running'" -Property RowKey, PartitionKey, Status
48-
if (($RunningTasks | Measure-Object).Count -gt 0) {
49-
if ($PSCmdlet.ShouldProcess('Tasks', 'Mark Failed')) {
50-
$UpdatedTasks = foreach ($Task in $RunningTasks) {
51-
$Task.Status = 'Failed'
52-
$Task
53-
}
54-
Update-AzDataTableEntity -Force @CippQueueTasks -Entity $UpdatedTasks
55-
}
56-
}
57-
5837
$null = Get-CippTable -TableName ('{0}History' -f $FunctionName)
5938
Write-Information 'Durable Orchestrators and Queues have been cleared'
6039
return $true

Modules/CIPPCore/Public/GraphHelper/New-GraphPOSTRequest.ps1

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11

2-
function New-GraphPOSTRequest ($uri, $tenantid, $body, $type, $scope, $AsApp, $NoAuthCheck, $skipTokenCache, $AddedHeaders, $contentType, $IgnoreErrors = $false, $returnHeaders = $false) {
2+
function New-GraphPOSTRequest {
33
<#
44
.FUNCTIONALITY
55
Internal
66
#>
7+
param(
8+
$uri,
9+
$tenantid,
10+
$body,
11+
$type = 'POST',
12+
$scope,
13+
$AsApp,
14+
$NoAuthCheck,
15+
$skipTokenCache,
16+
$AddedHeaders,
17+
$contentType,
18+
$IgnoreErrors = $false,
19+
$returnHeaders = $false,
20+
$maxRetries = 1
21+
)
22+
723
if ($NoAuthCheck -or (Get-AuthorisedRequest -Uri $uri -TenantID $tenantid)) {
824
$headers = Get-GraphToken -tenantid $tenantid -scope $scope -AsApp $asapp -SkipCache $skipTokenCache
925
if ($AddedHeaders) {
@@ -12,27 +28,35 @@ function New-GraphPOSTRequest ($uri, $tenantid, $body, $type, $scope, $AsApp, $N
1228
}
1329
}
1430

15-
if (!$type) {
16-
$type = 'POST'
17-
}
18-
19-
Write-Information "$($type.ToUpper()) [ $uri ] | tenant: $tenantid"
20-
2131
if (!$contentType) {
2232
$contentType = 'application/json; charset=utf-8'
2333
}
24-
try {
25-
$body = Get-CIPPTextReplacement -TenantFilter $tenantid -Text $body -EscapeForJson
26-
$ReturnedData = (Invoke-RestMethod -Uri $($uri) -Method $TYPE -Body $body -Headers $headers -ContentType $contentType -SkipHttpErrorCheck:$IgnoreErrors -ResponseHeadersVariable responseHeaders)
27-
} catch {
28-
$Message = if ($_.ErrorDetails.Message) {
29-
Get-NormalizedError -Message $_.ErrorDetails.Message
30-
} else {
31-
$_.Exception.message
34+
35+
$body = Get-CIPPTextReplacement -TenantFilter $tenantid -Text $body -EscapeForJson
36+
37+
$x = 0
38+
do {
39+
try {
40+
Write-Information "$($type.ToUpper()) [ $uri ] | tenant: $tenantid | attempt: $($x + 1) of $maxRetries"
41+
$success = $false
42+
$ReturnedData = (Invoke-RestMethod -Uri $($uri) -Method $TYPE -Body $body -Headers $headers -ContentType $contentType -SkipHttpErrorCheck:$IgnoreErrors -ResponseHeadersVariable responseHeaders)
43+
$success = $true
44+
} catch {
45+
46+
$Message = if ($_.ErrorDetails.Message) {
47+
Get-NormalizedError -Message $_.ErrorDetails.Message
48+
} else {
49+
$_.Exception.message
50+
}
51+
$x++
52+
Start-Sleep -Seconds (2 * $x)
3253
}
54+
} while (($x -lt $maxRetries) -and ($success -eq $false))
3355

56+
if ($success -eq $false) {
3457
throw $Message
3558
}
59+
3660
if ($returnHeaders) {
3761
return $responseHeaders
3862
} else {

Modules/CIPPCore/Public/Send-CIPPAlert.ps1

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ function Send-CIPPAlert {
1818
$Table = Get-CIPPTable -TableName SchedulerConfig
1919
$Filter = "RowKey eq 'CippNotifications' and PartitionKey eq 'CippNotifications'"
2020
$Config = [pscustomobject](Get-CIPPAzDataTableEntity @Table -Filter $Filter)
21+
22+
if ($HTMLContent) {
23+
$HTMLContent = Get-CIPPTextReplacement -TenantFilter $TenantFilter -Text $HTMLContent
24+
}
25+
2126
if ($Type -eq 'email') {
2227
Write-Information 'Trying to send email'
2328
try {
@@ -39,6 +44,7 @@ function Send-CIPPAlert {
3944
}
4045
}
4146
}
47+
4248
$PowerShellBody = [PSCustomObject]@{
4349
message = @{
4450
subject = $Title
@@ -52,6 +58,7 @@ function Send-CIPPAlert {
5258
}
5359

5460
$JSONBody = ConvertTo-Json -Compress -Depth 10 -InputObject $PowerShellBody
61+
5562
if ($PSCmdlet.ShouldProcess($($Recipients.EmailAddress.Address -join ', '), 'Sending email')) {
5663
$null = New-GraphPostRequest -uri 'https://graph.microsoft.com/v1.0/me/sendMail' -tenantid $env:TenantID -NoAuthCheck $true -type POST -body ($JSONBody)
5764
}
@@ -93,7 +100,7 @@ function Send-CIPPAlert {
93100

94101
if ($Type -eq 'webhook') {
95102
Write-Information 'Trying to send webhook'
96-
103+
$JSONBody = Get-CIPPTextReplacement -TenantFilter $TenantFilter -Text $JSONContent -EscapeForJson
97104
try {
98105
if (![string]::IsNullOrWhiteSpace($Config.webhook) -or ![string]::IsNullOrWhiteSpace($AltWebhook)) {
99106
if ($PSCmdlet.ShouldProcess($Config.webhook, 'Sending webhook')) {

Modules/CIPPCore/Public/TenantGroups/Update-CIPPDynamicTenantGroups.ps1

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,17 @@ function Update-CIPPDynamicTenantGroups {
173173
$TenantVariables = Get-CIPPTenantVariables -TenantFilter $_.customerId -IncludeGlobal
174174
} catch {
175175
Write-Information "Error fetching custom variables for tenant $($_.defaultDomainName): $($_.Exception.Message)"
176+
Write-LogMessage -API 'TenantGroups' -message 'Error getting tenant variables' -Tenant $_.defaultDomainName -sev Warning -LogData (Get-CippException -Exception $_)
176177
}
177178
}
178179

179-
$SKUId = $LicenseInfo.SKUId ?? @()
180-
$ServicePlans = (Get-CIPPTenantCapabilities -TenantFilter $_.defaultDomainName).psobject.properties.name
180+
try {
181+
$SKUId = $LicenseInfo.SKUId ?? @()
182+
$ServicePlans = (Get-CIPPTenantCapabilities -TenantFilter $_.defaultDomainName).psobject.properties.name
183+
} catch {
184+
Write-Information "Error fetching capabilities for tenant $($_.defaultDomainName): $($_.Exception.Message)"
185+
Write-LogMessage -API 'TenantGroups' -message 'Error getting tenant capabilities' -Tenant $_.defaultDomainName -sev Warning -LogData (Get-CippException -Exception $_)
186+
}
181187
[pscustomobject]@{
182188
customerId = $_.customerId
183189
defaultDomainName = $_.defaultDomainName

host.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
},
66
"extensionBundle": {
77
"id": "Microsoft.Azure.Functions.ExtensionBundle",
8-
"version": "[4.*, 5.0.0)"
8+
"version": "[4.26.0, 5.0.0)"
99
},
1010
"functionTimeout": "00:10:00",
1111
"extensions": {
@@ -15,7 +15,10 @@
1515
"tracing": {
1616
"distributedTracingEnabled": false,
1717
"version": "None"
18-
}
18+
},
19+
"defaultVersion": "8.7.0",
20+
"versionMatchStrategy": "Strict",
21+
"versionFailureStrategy": "Fail"
1922
}
2023
}
2124
}

0 commit comments

Comments
 (0)