Skip to content

Commit 0cd0971

Browse files
authored
Merge pull request #226 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 184ba88 + 156f966 commit 0cd0971

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Tools/Invoke-ExecGraphExplorerPreset.ps1

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using 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

Modules/CIPPCore/Public/Entrypoints/Invoke-ListGraphExplorerPresets.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using 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'.

Modules/CIPPCore/Public/Get-CIPPAuthentication.ps1

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)