Skip to content

Commit

Permalink
Merge branch 'KelvinTegelaar:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
BNWEIN authored Jul 27, 2023
2 parents 3538bea + f0278ee commit 04f74e9
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion SendStats/function.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "Timer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 0 0 * * 0"
"schedule": "0 0 0 * * *"
}
]
}
1 change: 1 addition & 0 deletions SendStats/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Set-Location (Get-Item $PSScriptRoot).Parent.FullName
$APIVersion = Get-Content "version_latest.txt" | Out-String

$SendingObject = [PSCustomObject]@{
rgid = $env:WEBSITE_SITE_NAME
SetupComplete = $SetupComplete
RunningVersionAPI = $APIVersion.trim()
CountOfTotalTenants = $tenantcount
Expand Down
32 changes: 28 additions & 4 deletions UpdatePermissions/run.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
# Input bindings are passed in via param block.
param($Timer)

#Switched to run for every tenant always, to make sure app permissions get applied succesfully.
# Get the current universal time in the default string format.
$currentUTCtime = (Get-Date).ToUniversalTime()

$Table = Get-CIPPTable -TableName cpvtenants
$CPVRows = Get-AzDataTableEntity @Table

$Tenants = get-tenants
$TenantList = $CPVRows.Tenant
foreach ($Row in $Tenants ) {
Write-Host "Processing tenants"
Push-OutputBinding -Name Msg -Value $row.customerId
}
Write-Output "Processing tenants"

if (!$CPVRows) {
Write-Output "No list available"
Push-OutputBinding -Name Msg -Value $row.customerId
continue
}

if ($Row.customerId -notin $TenantList) {
Write-Output "Not in the list: $($row.customerId)"
Push-OutputBinding -Name Msg -Value $row.customerId
continue

}

if ($CPVRows | Where-Object { $_.Tenant -eq $row.customerId } | Where-Object { $_.LastApply -EQ $null -or (Get-Date $_.LastApply).AddDays(-14) -gt $currentUTCtime }) {
Write-Output "In list, Old age."
Push-OutputBinding -Name Msg -Value $row.customerId
continue
}
}
6 changes: 3 additions & 3 deletions UpdatePermissionsQueue/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ $GraphRequest = $ExpectedPermissions.requiredResourceAccess | ForEach-Object {
"Could not set CPV permissions for $PermissionsName. Does the Tenant have a license for this API? Error: $($_.Exception.message)"
}
}
$ourSVCPrincipal = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/servicePrincipals(appId='$($ENV:applicationid)')" -tenantid $Tenantfilter
$ourSVCPrincipal = New-GraphGETRequest -uri "https://graph.microsoft.com/beta/servicePrincipals(appId='$($ENV:applicationid)')" -tenantid $Tenantfilter.customerid

# if the app svc principal exists, consent app permissions
$apps = $ExpectedPermissions
$Grants = foreach ($App in $apps.requiredResourceAccess) {
try {
$svcPrincipalId = New-GraphGETRequest -uri "https://graph.microsoft.com/v1.0/servicePrincipals(appId='$($app.resourceAppId)')" -tenantid $tenantfilter
$svcPrincipalId = New-GraphGETRequest -uri "https://graph.microsoft.com/v1.0/servicePrincipals(appId='$($app.resourceAppId)')" -tenantid $Tenantfilter.customerid
}
catch {
continue
Expand All @@ -73,7 +73,7 @@ $Grants = foreach ($App in $apps.requiredResourceAccess) {
}
foreach ($Grant in $grants) {
try {
$SettingsRequest = New-GraphPOSTRequest -body ($grant | ConvertTo-Json) -uri "https://graph.microsoft.com/beta/servicePrincipals/$($ourSVCPrincipal.id)/appRoleAssignedTo" -tenantid $tenantfilter -type POST
$SettingsRequest = New-GraphPOSTRequest -body ($grant | ConvertTo-Json) -uri "https://graph.microsoft.com/beta/servicePrincipals/$($ourSVCPrincipal.id)/appRoleAssignedTo" -tenantid $Tenantfilter.customerid -type POST
}
catch {
"Failed to grant $($grant.appRoleId) to $($grant.resourceId): $($_.Exception.Message). "
Expand Down
2 changes: 1 addition & 1 deletion version_latest.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.8.1
3.8.2

0 comments on commit 04f74e9

Please sign in to comment.