Skip to content

Commit ff2e169

Browse files
authored
Merge pull request #143 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 992a0dc + bc780d7 commit ff2e169

File tree

6 files changed

+114
-55
lines changed

6 files changed

+114
-55
lines changed

Modules/CIPPCore/Public/Authentication/Get-CippApiClient.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function Get-CippApiClient {
1818
if ($AppId) {
1919
$Table.Filter = "RowKey eq '$AppId'"
2020
}
21-
$Apps = Get-CIPPAzDataTableEntity @Table
21+
$Apps = Get-CIPPAzDataTableEntity @Table | Where-Object { ![string]::IsNullOrEmpty($_.RowKey) }
2222
$Apps = foreach ($Client in $Apps) {
2323
$Client = $Client | Select-Object -Property @{Name = 'ClientId'; Expression = { $_.RowKey } }, AppName, Role, IPRange, Enabled
2424

Modules/CIPPCore/Public/Authentication/New-CIPPAPIConfig.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ function New-CIPPAPIConfig {
99
[string]$AppId
1010
)
1111

12+
$Permissions = Get-GraphToken -tenantid $env:TenantID -scope 'https://graph.microsoft.com/.default' -AsApp $true -SkipCache $true -ReturnRefresh $true
13+
$Token = Read-JwtAccessDetails -Token $Permissions.access_token
14+
$Permissions = $Token.Roles | Where-Object { $_ -match 'Application.ReadWrite.All' -or $_ -match 'Directory.ReadWrite.All' }
15+
if (!$Permissions -or $Permissions.Count -lt 2) {
16+
Write-LogMessage -headers $Headers -API $APINAME -tenant 'None '-message 'Insufficient permissions to create API App' -Sev 'Error'
17+
throw 'Insufficient permissions to create API App. This integration requires the following Application permissions in the partner tenant. Application.ReadWrite.All, Directory.ReadWrite.All'
18+
}
19+
1220
try {
1321
if ($AppId) {
1422
$APIApp = New-GraphGetRequest -uri "https://graph.microsoft.com/v1.0/applications(appid='$($AppId)')" -NoAuthCheck $true

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-SchedulerCIPPNotifications.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function Push-SchedulerCIPPNotifications {
5353
}
5454
}
5555
if ($CurrentStandardsLogs) {
56-
foreach ($tenant in ($CurrentLog.Tenant | Sort-Object -Unique)) {
56+
foreach ($tenant in ($CurrentStandardsLogs.Tenant | Sort-Object -Unique)) {
5757
$Data = ($CurrentStandardsLogs | Where-Object -Property tenant -EQ $tenant)
5858
$Subject = "$($Tenant): Standards are out of sync for $tenant"
5959
$HTMLContent = New-CIPPAlertTemplate -Data $Data -Format 'html' -InputObject 'standards'

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

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function Invoke-ExecApiClient {
1313

1414
switch ($Action) {
1515
'List' {
16-
$Apps = Get-CIPPAzDataTableEntity @Table
16+
$Apps = Get-CIPPAzDataTableEntity @Table | Where-Object { ![string]::IsNullOrEmpty($_.RowKey) }
1717
if (!$Apps) {
1818
$Apps = @()
1919
} else {
@@ -31,6 +31,7 @@ function Invoke-ExecApiClient {
3131
'AddUpdate' {
3232
if ($Request.Body.ClientId -or $Request.Body.AppName) {
3333
$ClientId = $Request.Body.ClientId.value ?? $Request.Body.ClientId
34+
$AddUpdateSuccess = $false
3435
try {
3536
$ApiConfig = @{
3637
Headers = $Request.Headers
@@ -46,8 +47,9 @@ function Invoke-ExecApiClient {
4647

4748
$ClientId = $APIConfig.ApplicationID
4849
$AddedText = $APIConfig.Results
50+
$AddUpdateSuccess = $true
4951
} catch {
50-
$AddedText = 'Could not modify App Registrations. Check the CIPP documentation for API requirements.'
52+
$AddedText = "Could not modify App Registrations. Check the CIPP documentation for API requirements. Error: $($_.Exception.Message)"
5153
$Body = $Body | Select-Object * -ExcludeProperty CIPPAPI
5254
}
5355
}
@@ -64,32 +66,38 @@ function Invoke-ExecApiClient {
6466
$IpRange = @()
6567
}
6668

67-
$ExistingClient = Get-CIPPAzDataTableEntity @Table -Filter "RowKey eq '$($ClientId)'"
68-
if ($ExistingClient) {
69-
$Client = $ExistingClient
70-
$Client.Role = [string]$Request.Body.Role.value
71-
$Client.IPRange = "$(@($IpRange) | ConvertTo-Json -Compress)"
72-
$Client.Enabled = $Request.Body.Enabled ?? $false
73-
Write-LogMessage -headers $Request.Headers -API 'ExecApiClient' -message "Updated API client $($Request.Body.ClientId)" -Sev 'Info'
74-
$Results = 'API client updated'
75-
} else {
76-
$Client = @{
77-
'PartitionKey' = 'ApiClients'
78-
'RowKey' = "$($ClientId)"
79-
'AppName' = "$($APIConfig.AppName ?? $Request.Body.ClientId.addedFields.displayName)"
80-
'Role' = [string]$Request.Body.Role.value
81-
'IPRange' = "$(@($IpRange) | ConvertTo-Json -Compress)"
82-
'Enabled' = $Request.Body.Enabled ?? $false
69+
if (!$AddUpdateSuccess -and !$ClientId) {
70+
$Body = @{
71+
Results = $AddedText
8372
}
84-
$Results = @{
85-
resultText = "API Client created with the name '$($Client.AppName)'. Use the Copy to Clipboard button to retrieve the secret."
86-
copyField = $APIConfig.ApplicationSecret
87-
state = 'success'
73+
} else {
74+
$ExistingClient = Get-CIPPAzDataTableEntity @Table -Filter "RowKey eq '$($ClientId)'"
75+
if ($ExistingClient) {
76+
$Client = $ExistingClient
77+
$Client.Role = [string]$Request.Body.Role.value
78+
$Client.IPRange = "$(@($IpRange) | ConvertTo-Json -Compress)"
79+
$Client.Enabled = $Request.Body.Enabled ?? $false
80+
Write-LogMessage -headers $Request.Headers -API 'ExecApiClient' -message "Updated API client $($Request.Body.ClientId)" -Sev 'Info'
81+
$Results = 'API client updated'
82+
} else {
83+
$Client = @{
84+
'PartitionKey' = 'ApiClients'
85+
'RowKey' = "$($ClientId)"
86+
'AppName' = "$($APIConfig.AppName ?? $Request.Body.ClientId.addedFields.displayName)"
87+
'Role' = [string]$Request.Body.Role.value
88+
'IPRange' = "$(@($IpRange) | ConvertTo-Json -Compress)"
89+
'Enabled' = $Request.Body.Enabled ?? $false
90+
}
91+
$Results = @{
92+
resultText = "API Client created with the name '$($Client.AppName)'. Use the Copy to Clipboard button to retrieve the secret."
93+
copyField = $APIConfig.ApplicationSecret
94+
state = 'success'
95+
}
8896
}
89-
}
9097

91-
Add-CIPPAzDataTableEntity @Table -Entity $Client -Force | Out-Null
92-
$Body = @($Results)
98+
Add-CIPPAzDataTableEntity @Table -Entity $Client -Force | Out-Null
99+
$Body = @($Results)
100+
}
93101
}
94102
'GetAzureConfiguration' {
95103
$RGName = $ENV:WEBSITE_RESOURCE_GROUP
@@ -110,7 +118,7 @@ function Invoke-ExecApiClient {
110118
$TenantId = $ENV:TenantId
111119
$RGName = $ENV:WEBSITE_RESOURCE_GROUP
112120
$FunctionAppName = $ENV:WEBSITE_SITE_NAME
113-
$AllClients = Get-CIPPAzDataTableEntity @Table -Filter 'Enabled eq true'
121+
$AllClients = Get-CIPPAzDataTableEntity @Table -Filter 'Enabled eq true' | Where-Object { ![string]::IsNullOrEmpty($_.RowKey) }
114122
$ClientIds = $AllClients.RowKey
115123
try {
116124
Set-CippApiAuth -RGName $RGName -FunctionAppName $FunctionAppName -TenantId $TenantId -ClientIds $ClientIds

Modules/CIPPCore/Public/New-CIPPAlertTemplate.ps1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,21 @@ function New-CIPPAlertTemplate {
2525
$DataHTML = ($Data | Select-Object * -ExcludeProperty Etag, PartitionKey, TimeStamp | ConvertTo-Html | Out-String).Replace('<table>', ' <table class="table-modern">')
2626
$IntroText = "<p>You've configured CIPP to send you alerts based on the logbook. The following alerts match your configured rules</p>$dataHTML"
2727
$ButtonUrl = "$CIPPURL/cipp/logs"
28-
$ButtonText = 'C heck logbook information'
28+
$ButtonText = 'Check logbook information'
2929
}
3030
if ($InputObject -eq 'standards') {
3131
$DataHTML = foreach ($object in $data) {
32-
"<p>For the standard $($object.standardName) in template {{Template Name }} we've detected:</p> <li>$($object.message)</li>"
32+
"<p>For the standard $($object.standardName) in template {{Template Name }} we've detected the following:</p> <li>$($object.message)</li>"
3333
if ($object.object) {
3434
$object.object = $object.object | ConvertFrom-Json
3535
$object.object = $object.object | Select-Object * -ExcludeProperty Etag, PartitionKey, TimeStamp
36-
($object.object.compare | ConvertTo-Html -Fragment | Out-String).Replace('<table>', ' <table class="table-modern">')
36+
if ($object.object.compare) {
37+
'<p>The following differences have been detected:</p>'
38+
($object.object.compare | ConvertTo-Html -Fragment | Out-String).Replace('<table>', ' <table class="table-modern">')
39+
} else {
40+
'<p>This is a table representation of the current settings:</p>'
41+
($object.object | ConvertTo-Html -Fragment -As List | Out-String).Replace('<table>', ' <table class="table-modern">')
42+
}
3743
}
3844

3945
}

0 commit comments

Comments
 (0)