Skip to content

Commit a178f0b

Browse files
authored
Merge pull request #512 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents c09229f + 9e02376 commit a178f0b

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-GetCippAlerts.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function Invoke-GetCippAlerts {
5353
type = 'error'
5454
})
5555
}
56-
if ((!$env:WEBSITE_RUN_FROM_PACKAGE -or [string]::IsNullOrEmpty($env:WEBSITE_RUN_FROM_PACKAGE)) -and $env:AzureWebJobsStorage -ne 'UseDevelopmentStorage=true' -and $env:NonLocalHostAzurite -ne 'true') {
56+
if (!(![string]::IsNullOrEmpty($env:WEBSITE_RUN_FROM_PACKAGE) -or ![string]::IsNullOrEmpty($env:DEPLOYMENT_STORAGE_CONNECTION_STRING)) -and $env:AzureWebJobsStorage -ne 'UseDevelopmentStorage=true' -and $env:NonLocalHostAzurite -ne 'true') {
5757
$Alerts.Add(
5858
@{
5959
title = 'Function App in Write Mode'

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ListApiTest.ps1

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,20 @@ function Invoke-ListApiTest {
77
#>
88
[CmdletBinding()]
99
param($Request, $TriggerMetadata)
10+
11+
$Response = @{}
12+
$Response.Request = $Request
13+
if ($env:DEBUG_ENV_VARS -eq 'true') {
14+
$BlockedKeys = @('ApplicationSecret', 'RefreshToken', 'AzureWebJobsStorage', 'DEPLOYMENT_STORAGE_CONNECTION_STRING')
15+
$EnvironmentVariables = [PSCustomObject]@{}
16+
Get-ChildItem env: | Where-Object { $BlockedKeys -notcontains $_.Name } | ForEach-Object {
17+
$EnvironmentVariables | Add-Member -NotePropertyName $_.Name -NotePropertyValue $_.Value
18+
}
19+
$Response.EnvironmentVariables = $EnvironmentVariables
20+
}
21+
1022
return ([HttpResponseContext]@{
1123
StatusCode = [HttpStatusCode]::OK
12-
Body = ($Request | ConvertTo-Json -Depth 5)
24+
Body = $Response
1325
})
1426
}

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ function Update-CIPPDynamicTenantGroups {
1717
try {
1818
$GroupTable = Get-CippTable -tablename 'TenantGroups'
1919
$MembersTable = Get-CippTable -tablename 'TenantGroupMembers'
20+
$LicenseCacheTable = Get-CippTable -tablename 'cachetenantskus'
21+
22+
$Skus = Get-CIPPAzDataTableEntity @LicenseCacheTable -Filter "PartitionKey eq 'sku' and Timestamp ge datetime'$( (Get-Date).ToUniversalTime().AddHours(-8).ToString('yyyy-MM-ddTHH:mm:ssZ') )'"
23+
24+
$SkuHashtable = @{}
25+
foreach ($Sku in $Skus) {
26+
if ($Sku.JSON -and (Test-Json -Json $Sku.JSON -ErrorAction SilentlyContinue)) {
27+
$SkuHashtable[$Sku.RowKey] = $Sku.JSON | ConvertFrom-Json
28+
}
29+
}
2030

2131
if ($GroupId) {
2232
$DynamicGroups = Get-CIPPAzDataTableEntity @GroupTable -Filter "PartitionKey eq 'TenantGroup' and RowKey eq '$GroupId'"
@@ -88,7 +98,20 @@ function Update-CIPPDynamicTenantGroups {
8898
}
8999
$TenantObj = $AllTenants | ForEach-Object {
90100
if ($Rules.property -contains 'availableLicense') {
91-
$LicenseInfo = New-GraphGetRequest -uri 'https://graph.microsoft.com/v1.0/subscribedSkus' -TenantId $_.defaultDomainName
101+
if ($SkuHashtable.ContainsKey($_.customerId)) {
102+
Write-Information "Using cached licenses for tenant $($_.defaultDomainName)"
103+
$LicenseInfo = $SkuHashtable[$_.customerId]
104+
} else {
105+
Write-Information "Fetching licenses for tenant $($_.defaultDomainName)"
106+
$LicenseInfo = New-GraphGetRequest -uri 'https://graph.microsoft.com/v1.0/subscribedSkus' -TenantId $_.defaultDomainName
107+
# Cache the result
108+
$CacheEntity = @{
109+
PartitionKey = 'sku'
110+
RowKey = [string]$_.customerId
111+
JSON = [string]($LicenseInfo | ConvertTo-Json -Depth 5 -Compress)
112+
}
113+
Add-CIPPAzDataTableEntity @LicenseCacheTable -Entity $CacheEntity -Force
114+
}
92115
}
93116
$SKUId = $LicenseInfo.SKUId ?? @()
94117
$ServicePlans = (Get-CIPPTenantCapabilities -TenantFilter $_.defaultDomainName).psobject.properties.name

Modules/CippEntrypoints/CippEntrypoints.psm1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ function Receive-CippHttpTrigger {
144144
$Response.Body = $Response.Body | ConvertTo-Json -Depth 20 -Compress
145145
}
146146
Push-OutputBinding -Name Response -Value ([HttpResponseContext]$Response)
147+
} else {
148+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
149+
StatusCode = [HttpStatusCode]::InternalServerError
150+
Body = @{
151+
error = @{
152+
code = 'InternalServerError'
153+
message = 'An error occurred processing the request'
154+
}
155+
}
156+
})
147157
}
148158
}
149159
return

0 commit comments

Comments
 (0)