From fc499e3fd3169f5d6122134b8f2826a3e92d7e71 Mon Sep 17 00:00:00 2001 From: John Duprey Date: Fri, 25 Apr 2025 17:15:23 -0400 Subject: [PATCH 1/4] Update Get-CIPPAuthentication.ps1 --- Modules/CIPPCore/Public/Get-CIPPAuthentication.ps1 | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Modules/CIPPCore/Public/Get-CIPPAuthentication.ps1 b/Modules/CIPPCore/Public/Get-CIPPAuthentication.ps1 index e86fd4b2e128..979de65b3976 100644 --- a/Modules/CIPPCore/Public/Get-CIPPAuthentication.ps1 +++ b/Modules/CIPPCore/Public/Get-CIPPAuthentication.ps1 @@ -19,9 +19,19 @@ function Get-CIPPAuthentication { } } } else { + Write-Information 'Connecting to Azure' Connect-AzAccount -Identity $SubscriptionId = $env:WEBSITE_OWNER_NAME -split '\+' | Select-Object -First 1 - $null = Set-AzContext -SubscriptionId $SubscriptionId + try { + $Context = Get-AzContext + if ($Context.Subscription.Id -ne $SubscriptionId) { + Write-Information "Setting context to subscription $SubscriptionId" + $null = Set-AzContext -SubscriptionId $SubscriptionId + } + } catch { + Write-Information "ERROR: Could not set context to subscription $SubscriptionId." + } + $keyvaultname = ($env:WEBSITE_DEPLOYMENT_ID -split '-')[0] $Variables | ForEach-Object { Set-Item -Path env:$_ -Value (Get-AzKeyVaultSecret -VaultName $keyvaultname -Name $_ -AsPlainText -ErrorAction Stop) -Force From b7b5ac2a2e0b0ff04b2b208740cee420c3f4ce0d Mon Sep 17 00:00:00 2001 From: John Duprey Date: Wed, 23 Apr 2025 13:26:15 -0400 Subject: [PATCH 2/4] add graph preset validation --- .../Tools/Invoke-ExecGraphExplorerPreset.ps1 | 30 +++++++++++++++++-- .../Invoke-ListGraphExplorerPresets.ps1 | 8 +++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Tools/Invoke-ExecGraphExplorerPreset.ps1 b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Tools/Invoke-ExecGraphExplorerPreset.ps1 index 4c87012301e0..4b068585ffc6 100644 --- a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Tools/Invoke-ExecGraphExplorerPreset.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Tools/Invoke-ExecGraphExplorerPreset.ps1 @@ -1,6 +1,6 @@ using namespace System.Net -Function Invoke-ExecGraphExplorerPreset { +function Invoke-ExecGraphExplorerPreset { <# .FUNCTIONALITY Entrypoint @@ -22,7 +22,7 @@ Function Invoke-ExecGraphExplorerPreset { switch ($Action) { 'Copy' { - $Id = $Request.Body.preset.id ? $Request.Body.preset.id: (New-Guid).Guid + $Id = $Request.Body.preset.id ? $Request.Body.preset.id : (New-Guid).Guid } 'Save' { $Id = $Request.Body.preset.id @@ -42,6 +42,32 @@ Function Invoke-ExecGraphExplorerPreset { $params.'$select' = ($params.'$select').value -join ',' } + if (!$Request.Body.preset.name) { + $Message = 'Error: Preset name is required' + $StatusCode = [HttpStatusCode]::BadRequest + Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ + StatusCode = $StatusCode + Body = @{ + Results = $Message + Success = $false + } + }) + return + } + + if (!$Request.Body.preset.endpoint) { + $Message = 'Error: Preset endpoint is required' + $StatusCode = [HttpStatusCode]::BadRequest + Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ + StatusCode = $StatusCode + Body = @{ + Results = $Message + Success = $false + } + }) + return + } + $Preset = [PSCustomObject]@{ PartitionKey = 'Preset' RowKey = [string]$Id diff --git a/Modules/CIPPCore/Public/Entrypoints/Invoke-ListGraphExplorerPresets.ps1 b/Modules/CIPPCore/Public/Entrypoints/Invoke-ListGraphExplorerPresets.ps1 index ee84bc74bc19..7f372f03a1e7 100644 --- a/Modules/CIPPCore/Public/Entrypoints/Invoke-ListGraphExplorerPresets.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/Invoke-ListGraphExplorerPresets.ps1 @@ -1,6 +1,6 @@ using namespace System.Net -Function Invoke-ListGraphExplorerPresets { +function Invoke-ListGraphExplorerPresets { <# .FUNCTIONALITY Entrypoint,AnyTenant @@ -19,14 +19,14 @@ Function Invoke-ListGraphExplorerPresets { try { $Table = Get-CIPPTable -TableName 'GraphPresets' - $Presets = Get-CIPPAzDataTableEntity @Table -Filter "Owner eq '$Username' or IsShared eq true" | Sort-Object -Property name + $Presets = Get-CIPPAzDataTableEntity @Table | Where-Object { $Username -eq $_.Owner -or $_.IsShared -eq $true } | Sort-Object -Property name $Results = foreach ($Preset in $Presets) { [PSCustomObject]@{ id = $Preset.Id name = $Preset.name IsShared = $Preset.IsShared IsMyPreset = $Preset.Owner -eq $Username - params = ConvertFrom-Json -InputObject $Preset.Params + params = (ConvertFrom-Json -InputObject $Preset.Params) } } @@ -35,6 +35,8 @@ Function Invoke-ListGraphExplorerPresets { $Results = $Results | Where-Object { ($_.params.endpoint -replace '^/', '') -eq $Endpoint } } } catch { + Write-Warning "Could not list presets. $($_.Exception.Message)" + Write-Information $_.InvocationInfo.PositionMessage $Results = @() } # Associate values to output bindings by calling 'Push-OutputBinding'. From f24f5f660006e354b34fef51104b3e85423cb75f Mon Sep 17 00:00:00 2001 From: John Duprey Date: Fri, 25 Apr 2025 17:51:22 -0400 Subject: [PATCH 3/4] Update Get-CIPPAuthentication.ps1 --- Modules/CIPPCore/Public/Get-CIPPAuthentication.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/Modules/CIPPCore/Public/Get-CIPPAuthentication.ps1 b/Modules/CIPPCore/Public/Get-CIPPAuthentication.ps1 index 979de65b3976..b24f460b8d62 100644 --- a/Modules/CIPPCore/Public/Get-CIPPAuthentication.ps1 +++ b/Modules/CIPPCore/Public/Get-CIPPAuthentication.ps1 @@ -24,6 +24,7 @@ function Get-CIPPAuthentication { $SubscriptionId = $env:WEBSITE_OWNER_NAME -split '\+' | Select-Object -First 1 try { $Context = Get-AzContext + Write-Information "Current context: $($Context.Subscription.Name)" if ($Context.Subscription.Id -ne $SubscriptionId) { Write-Information "Setting context to subscription $SubscriptionId" $null = Set-AzContext -SubscriptionId $SubscriptionId From 156f9665770bbf495a30f07a1d93dd801f99d681 Mon Sep 17 00:00:00 2001 From: John Duprey Date: Fri, 25 Apr 2025 17:57:12 -0400 Subject: [PATCH 4/4] Update Get-CIPPAuthentication.ps1 --- Modules/CIPPCore/Public/Get-CIPPAuthentication.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/CIPPCore/Public/Get-CIPPAuthentication.ps1 b/Modules/CIPPCore/Public/Get-CIPPAuthentication.ps1 index b24f460b8d62..787dce5877bb 100644 --- a/Modules/CIPPCore/Public/Get-CIPPAuthentication.ps1 +++ b/Modules/CIPPCore/Public/Get-CIPPAuthentication.ps1 @@ -24,7 +24,7 @@ function Get-CIPPAuthentication { $SubscriptionId = $env:WEBSITE_OWNER_NAME -split '\+' | Select-Object -First 1 try { $Context = Get-AzContext - Write-Information "Current context: $($Context.Subscription.Name)" + Write-Information "Current context: $($Context | ConvertTo-Json)" if ($Context.Subscription.Id -ne $SubscriptionId) { Write-Information "Setting context to subscription $SubscriptionId" $null = Set-AzContext -SubscriptionId $SubscriptionId