Skip to content

Commit c0e31e7

Browse files
authored
Merge pull request #660 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 2972a94 + d4e6b20 commit c0e31e7

File tree

10 files changed

+101
-8
lines changed

10 files changed

+101
-8
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Tests/Invoke-CIPPTestsRun.ps1 renamed to Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Tests/Invoke-CIPPTestsRun.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@ function Invoke-CIPPTestsRun {
7373
} catch {
7474
$ErrorMessage = Get-CippException -Exception $_
7575
Write-LogMessage -API 'Tests' -message "Failed to start tests orchestration: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage
76-
throw
76+
throw $ErrorMessage
7777
}
7878
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
function Push-CIPPTestsRun {
2+
<#
3+
.SYNOPSIS
4+
PostExecution function to run tests after data collection completes
5+
.FUNCTIONALITY
6+
Entrypoint
7+
#>
8+
param($Item)
9+
10+
try {
11+
$TenantFilter = $Item.Parameters.TenantFilter
12+
Write-Information "PostExecution: Starting tests for tenant: $TenantFilter after data collection completed"
13+
Write-LogMessage -API 'Tests' -tenant $TenantFilter -message 'Starting test run after data collection' -sev Info
14+
15+
# Call the test run function
16+
$Result = Invoke-CIPPTestsRun -TenantFilter $TenantFilter
17+
18+
Write-LogMessage -API 'Tests' -tenant $TenantFilter -message "Test run started. Instance ID: $($Result.InstanceId)" -sev Info
19+
Write-Information "PostExecution: Tests started with Instance ID: $($Result.InstanceId)"
20+
21+
return @{
22+
Success = $true
23+
InstanceId = $Result.InstanceId
24+
Message = $Result.Message
25+
}
26+
} catch {
27+
$ErrorMessage = Get-CippException -Exception $_
28+
Write-LogMessage -API 'Tests' -tenant $TenantFilter -message "Failed to start test run: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage
29+
Write-Warning "PostExecution: Error starting tests - $($ErrorMessage.NormalizedError)"
30+
31+
return @{
32+
Success = $false
33+
Error = $ErrorMessage.NormalizedError
34+
}
35+
}
36+
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecExchangeRoleRepair.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function Invoke-ExecExchangeRoleRepair {
8989
}
9090
}
9191

92-
Push-OutputBinding -Name 'Response' -Value ([HttpResponseContext]@{
92+
returns ([HttpResponseContext]@{
9393
StatusCode = [System.Net.HttpStatusCode]::OK
9494
Body = $Results
9595
})

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Endpoint/MEM/Invoke-ExecDevicePasscodeAction.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function Invoke-ExecDevicePasscodeAction {
4646
$Results = $Result
4747
}
4848

49-
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
49+
return ([HttpResponseContext]@{
5050
StatusCode = $StatusCode
5151
Body = @{Results = $Results }
5252
})

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Invoke-AddTestReport.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function Invoke-AddTestReport {
5353
$StatusCode = [HttpStatusCode]::BadRequest
5454
}
5555

56-
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
56+
return ([HttpResponseContext]@{
5757
StatusCode = $StatusCode
5858
Body = ConvertTo-Json -InputObject $Body -Depth 10
5959
})

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Invoke-DeleteTestReport.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function Invoke-DeleteTestReport {
3030
$StatusCode = [HttpStatusCode]::BadRequest
3131
}
3232

33-
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
33+
return ([HttpResponseContext]@{
3434
StatusCode = $StatusCode
3535
Body = ConvertTo-Json -InputObject $Body -Depth 10
3636
})
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
function Invoke-ExecTestRun {
2+
<#
3+
.FUNCTIONALITY
4+
Entrypoint
5+
.ROLE
6+
Tenant.Tests.ReadWrite
7+
#>
8+
param($Request, $TriggerMetadata)
9+
10+
$APIName = $TriggerMetadata.FunctionName
11+
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'
12+
13+
try {
14+
$TenantFilter = $Request.Query.tenantFilter ?? $Request.Body.tenantFilter
15+
Write-LogMessage -API $APIName -tenant $TenantFilter -message "Starting data collection and test run for tenant: $TenantFilter" -sev Info
16+
$Batch = @(
17+
@{
18+
FunctionName = 'CIPPDBCacheData'
19+
TenantFilter = $TenantFilter
20+
QueueId = $Queue.RowKey
21+
QueueName = "Cache - $TenantFilter"
22+
}
23+
)
24+
$InputObject = [PSCustomObject]@{
25+
OrchestratorName = 'TestDataCollectionAndRun'
26+
Batch = $Batch
27+
PostExecution = @{
28+
FunctionName = 'CIPPTestsRun'
29+
Parameters = @{
30+
TenantFilter = $TenantFilter
31+
}
32+
}
33+
SkipLog = $false
34+
}
35+
36+
$InstanceId = Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Depth 5 -Compress)
37+
38+
$StatusCode = [HttpStatusCode]::OK
39+
$Body = [PSCustomObject]@{
40+
Results = "Successfully started data collection and test run for $TenantFilter"
41+
InstanceId = $InstanceId
42+
}
43+
44+
Write-LogMessage -API $APIName -tenant $TenantFilter -message "Data collection and test run orchestration started. Instance ID: $InstanceId" -sev Info
45+
46+
} catch {
47+
$ErrorMessage = Get-CippException -Exception $_
48+
Write-LogMessage -API $APIName -tenant $TenantFilter -message "Failed to start data collection/test run: $($ErrorMessage.NormalizedError)" -sev Error -LogData $ErrorMessage
49+
$StatusCode = [HttpStatusCode]::BadRequest
50+
$Body = @{ Message = "Failed to start data collection/test run for $TenantFilter" }
51+
}
52+
53+
return ([HttpResponseContext]@{
54+
StatusCode = $StatusCode
55+
Body = $Body
56+
})
57+
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Invoke-ListAvailableTests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function Invoke-ListAvailableTests {
7979
$StatusCode = [HttpStatusCode]::BadRequest
8080
}
8181

82-
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
82+
return ([HttpResponseContext]@{
8383
StatusCode = $StatusCode
8484
Body = ConvertTo-Json -InputObject $Body -Depth 10
8585
})

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Invoke-ListTestReports.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function Invoke-ListTestReports {
6262
$Body = @{ Error = $ErrorMessage.NormalizedError }
6363
}
6464

65-
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
65+
return([HttpResponseContext]@{
6666
StatusCode = $StatusCode
6767
Body = ConvertTo-Json -InputObject $Body -Depth 10 -Compress
6868
})

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Invoke-ListTests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ function Invoke-ListTests {
156156
$Body = @{ Error = $ErrorMessage.NormalizedError }
157157
}
158158

159-
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
159+
return ([HttpResponseContext]@{
160160
StatusCode = $StatusCode
161161
Body = $Body
162162
})

0 commit comments

Comments
 (0)