Skip to content

Commit ff3fbf6

Browse files
implements drift standards
1 parent 15cd3bb commit ff3fbf6

File tree

7 files changed

+528
-1
lines changed

7 files changed

+528
-1
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/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)