File tree Expand file tree Collapse file tree 3 files changed +45
-6
lines changed
HTTP Functions/Tenant/Tools Expand file tree Collapse file tree 3 files changed +45
-6
lines changed Original file line number Diff line number Diff line change 11using namespace System.Net
22
3- Function Invoke-ExecGraphExplorerPreset {
3+ function Invoke-ExecGraphExplorerPreset {
44 <#
55 . FUNCTIONALITY
66 Entrypoint
@@ -22,7 +22,7 @@ Function Invoke-ExecGraphExplorerPreset {
2222
2323 switch ($Action ) {
2424 ' Copy' {
25- $Id = $Request.Body.preset.id ? $Request.Body.preset.id : (New-Guid ).Guid
25+ $Id = $Request.Body.preset.id ? $Request.Body.preset.id : (New-Guid ).Guid
2626 }
2727 ' Save' {
2828 $Id = $Request.Body.preset.id
@@ -42,6 +42,32 @@ Function Invoke-ExecGraphExplorerPreset {
4242 $params .' $select' = ($params .' $select' ).value -join ' ,'
4343 }
4444
45+ if (! $Request.Body.preset.name ) {
46+ $Message = ' Error: Preset name is required'
47+ $StatusCode = [HttpStatusCode ]::BadRequest
48+ Push-OutputBinding - Name Response - Value ([HttpResponseContext ]@ {
49+ StatusCode = $StatusCode
50+ Body = @ {
51+ Results = $Message
52+ Success = $false
53+ }
54+ })
55+ return
56+ }
57+
58+ if (! $Request.Body.preset.endpoint ) {
59+ $Message = ' Error: Preset endpoint is required'
60+ $StatusCode = [HttpStatusCode ]::BadRequest
61+ Push-OutputBinding - Name Response - Value ([HttpResponseContext ]@ {
62+ StatusCode = $StatusCode
63+ Body = @ {
64+ Results = $Message
65+ Success = $false
66+ }
67+ })
68+ return
69+ }
70+
4571 $Preset = [PSCustomObject ]@ {
4672 PartitionKey = ' Preset'
4773 RowKey = [string ]$Id
Original file line number Diff line number Diff line change 11using namespace System.Net
22
3- Function Invoke-ListGraphExplorerPresets {
3+ function Invoke-ListGraphExplorerPresets {
44 <#
55 . FUNCTIONALITY
66 Entrypoint,AnyTenant
@@ -19,14 +19,14 @@ Function Invoke-ListGraphExplorerPresets {
1919
2020 try {
2121 $Table = Get-CIPPTable - TableName ' GraphPresets'
22- $Presets = Get-CIPPAzDataTableEntity @Table - Filter " Owner eq ' $Username ' or IsShared eq true" | Sort-Object - Property name
22+ $Presets = Get-CIPPAzDataTableEntity @Table | Where-Object { $Username - eq $_ .Owner - or $_ . IsShared - eq $ true } | Sort-Object - Property name
2323 $Results = foreach ($Preset in $Presets ) {
2424 [PSCustomObject ]@ {
2525 id = $Preset.Id
2626 name = $Preset.name
2727 IsShared = $Preset.IsShared
2828 IsMyPreset = $Preset.Owner -eq $Username
29- params = ConvertFrom-Json - InputObject $Preset.Params
29+ params = ( ConvertFrom-Json - InputObject $Preset.Params )
3030 }
3131 }
3232
@@ -35,6 +35,8 @@ Function Invoke-ListGraphExplorerPresets {
3535 $Results = $Results | Where-Object { ($_.params.endpoint -replace ' ^/' , ' ' ) -eq $Endpoint }
3636 }
3737 } catch {
38+ Write-Warning " Could not list presets. $ ( $_.Exception.Message ) "
39+ Write-Information $_.InvocationInfo.PositionMessage
3840 $Results = @ ()
3941 }
4042 # Associate values to output bindings by calling 'Push-OutputBinding'.
Original file line number Diff line number Diff line change @@ -19,9 +19,20 @@ function Get-CIPPAuthentication {
1919 }
2020 }
2121 } else {
22+ Write-Information ' Connecting to Azure'
2223 Connect-AzAccount - Identity
2324 $SubscriptionId = $env: WEBSITE_OWNER_NAME -split ' \+' | Select-Object - First 1
24- $null = Set-AzContext - SubscriptionId $SubscriptionId
25+ try {
26+ $Context = Get-AzContext
27+ Write-Information " Current context: $ ( $Context | ConvertTo-Json ) "
28+ if ($Context.Subscription.Id -ne $SubscriptionId ) {
29+ Write-Information " Setting context to subscription $SubscriptionId "
30+ $null = Set-AzContext - SubscriptionId $SubscriptionId
31+ }
32+ } catch {
33+ Write-Information " ERROR: Could not set context to subscription $SubscriptionId ."
34+ }
35+
2536 $keyvaultname = ($env: WEBSITE_DEPLOYMENT_ID -split ' -' )[0 ]
2637 $Variables | ForEach-Object {
2738 Set-Item - Path env:$_ - Value (Get-AzKeyVaultSecret - VaultName $keyvaultname - Name $_ - AsPlainText - ErrorAction Stop) - Force
You can’t perform that action at this time.
0 commit comments