Skip to content

Commit 941c28d

Browse files
authored
Merge pull request #386 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 5a162db + 41cb7f9 commit 941c28d

10 files changed

+545
-11
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using namespace System.Net
2+
3+
function Invoke-ExecUpdateDriftDeviation {
4+
<#
5+
.FUNCTIONALITY
6+
Entrypoint
7+
.ROLE
8+
Tenant.Standards.ReadWrite
9+
#>
10+
[CmdletBinding()]
11+
param($Request, $TriggerMetadata)
12+
13+
$APIName = $TriggerMetadata.FunctionName
14+
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug'
15+
16+
try {
17+
$TenantFilter = $Request.Body.TenantFilter
18+
19+
if ($Request.Body.RemoveDriftCustomization) {
20+
$Table = Get-CippTable -tablename 'tenantDrift'
21+
$Filter = "PartitionKey eq '$TenantFilter'"
22+
$ExistingDeviations = Get-CIPPAzDataTableEntity @Table -Filter $Filter
23+
foreach ($Deviation in $ExistingDeviations) {
24+
Remove-AzDataTableEntity @Table -Entity $Deviation
25+
}
26+
$Results = @([PSCustomObject]@{
27+
success = $true
28+
result = "All drift customizations removed for tenant $TenantFilter"
29+
})
30+
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Removed all drift customizations for tenant $TenantFilter" -Sev 'Info'
31+
} else {
32+
$Deviations = $Request.Body.deviations
33+
$Results = foreach ($Deviation in $Deviations) {
34+
try {
35+
$Result = Set-CIPPDriftDeviation -TenantFilter $TenantFilter -StandardName $Deviation.standardName -Status $Deviation.status
36+
[PSCustomObject]@{
37+
success = $true
38+
result = $Result
39+
}
40+
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Updated drift deviation status for $($Deviation.standardName) to $($Deviation.status)" -Sev 'Info'
41+
} catch {
42+
[PSCustomObject]@{
43+
standardName = $Deviation.standardName
44+
success = $false
45+
error = $_.Exception.Message
46+
}
47+
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Failed to update drift deviation for $($Deviation.standardName): $($_.Exception.Message)" -Sev 'Error'
48+
}
49+
}
50+
}
51+
52+
$Body = @{ Results = @($Results) }
53+
54+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
55+
StatusCode = [HttpStatusCode]::OK
56+
Body = $Body
57+
})
58+
59+
} catch {
60+
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Failed to update drift deviation: $($_.Exception.Message)" -Sev 'Error'
61+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
62+
StatusCode = [HttpStatusCode]::BadRequest
63+
Body = @{error = $_.Exception.Message }
64+
})
65+
}
66+
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Standards/Invoke-ListTenantAlignment.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function Invoke-ListTenantAlignment {
2222
[PSCustomObject]@{
2323
tenantFilter = $_.TenantFilter
2424
standardName = $_.StandardName
25+
standardType = $_.StandardType ? $_.StandardType : 'Classic Standard'
2526
standardId = $_.StandardId
2627
alignmentScore = $_.AlignmentScore
2728
LicenseMissingPercentage = $_.LicenseMissingPercentage
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using namespace System.Net
2+
3+
function Invoke-ListTenantDrift {
4+
<#
5+
.FUNCTIONALITY
6+
Entrypoint
7+
.ROLE
8+
Tenant.Standards.Read
9+
#>
10+
[CmdletBinding()]
11+
param($Request, $TriggerMetadata)
12+
13+
$APIName = $Request.Params.CIPPEndpoint
14+
15+
try {
16+
# Use the new Get-CIPPTenantAlignment function to get alignment data
17+
if ($Request.Query.TenantFilter) {
18+
$TenantFilter = $Request.Query.TenantFilter
19+
$Results = Get-CIPPDrift -TenantFilter $TenantFilter
20+
} else {
21+
$Tenants = Get-Tenants
22+
$Results = $Tenants | ForEach-Object { Get-CIPPDrift -AllTenants -TenantFilter $_.defaultDomainName }
23+
}
24+
25+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
26+
StatusCode = [HttpStatusCode]::OK
27+
Body = @($Results)
28+
})
29+
} catch {
30+
Write-LogMessage -API $APIName -message "Failed to get tenant alignment data: $($_.Exception.Message)" -sev Error
31+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
32+
StatusCode = [HttpStatusCode]::InternalServerError
33+
Body = @{ error = "Failed to get tenant alignment data: $($_.Exception.Message)" }
34+
})
35+
}
36+
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Standards/Invoke-listStandardTemplates.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ function Invoke-listStandardTemplates {
1515
Write-LogMessage -Headers $Headers -API $APIName -message 'Accessed this API' -Sev 'Debug'
1616
# Interact with query parameters or the body of the request.
1717
$ID = $Request.Query.id
18-
1918
$Table = Get-CippTable -tablename 'templates'
2019
$Filter = "PartitionKey eq 'StandardsTemplateV2'"
2120
$Templates = (Get-CIPPAzDataTableEntity @Table -Filter $Filter) | ForEach-Object {

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Tools/Invoke-ExecGraphExplorerPreset.ps1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,31 +41,31 @@ function Invoke-ExecGraphExplorerPreset {
4141
$params.'$select' = ($params.'$select').value -join ','
4242
}
4343

44-
if (!$Request.Body.preset.name) {
44+
if (!$Request.Body.preset.name -and $Action -ne 'Delete') {
4545
$Message = 'Error: Preset name is required'
4646
$StatusCode = [HttpStatusCode]::BadRequest
4747
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
4848
StatusCode = $StatusCode
4949
Body = @{
50-
Results = @{
50+
Results = @(@{
5151
resultText = $Message
5252
state = 'error'
53-
}
53+
})
5454
}
5555
})
5656
return
5757
}
5858

59-
if (!$Request.Body.preset.endpoint) {
59+
if (!$Request.Body.preset.endpoint -and $Action -ne 'Delete') {
6060
$Message = 'Error: Preset endpoint is required'
6161
$StatusCode = [HttpStatusCode]::BadRequest
6262
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
6363
StatusCode = $StatusCode
6464
Body = @{
65-
Results = @{
65+
Results = @(@{
6666
resultText = $Message
6767
state = 'error'
68-
}
68+
})
6969
}
7070
})
7171
return
@@ -114,10 +114,10 @@ function Invoke-ExecGraphExplorerPreset {
114114
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
115115
StatusCode = $StatusCode
116116
Body = @{
117-
Results = @{
117+
Results = @(@{
118118
resultText = $Message
119119
state = if ($Success) { 'success' } else { 'error' }
120-
}
120+
})
121121
}
122122
})
123123
}

Modules/CIPPCore/Public/Functions/Get-CIPPTenantAlignment.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ function Get-CIPPTenantAlignment {
236236
TenantFilter = $TenantName
237237
StandardName = $Template.templateName
238238
StandardId = $Template.GUID
239+
standardType = $Template.type
240+
standardSettings = $Template.Standards
239241
AlignmentScore = $AlignmentPercentage
240242
LicenseMissingPercentage = $LicenseMissingPercentage
241243
CombinedScore = $AlignmentPercentage + $LicenseMissingPercentage

0 commit comments

Comments
 (0)