forked from KelvinTegelaar/CIPP-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from KelvinTegelaar/master
[pull] master from KelvinTegelaar:master
- Loading branch information
Showing
64 changed files
with
2,080 additions
and
888 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
Modules/CIPPCore/Public/Entrypoints/Invoke-ExecGraphExplorerPreset.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using namespace System.Net | ||
|
||
Function Invoke-ExecGraphExplorerPreset { | ||
<# | ||
.FUNCTIONALITY | ||
Entrypoint | ||
#> | ||
[CmdletBinding()] | ||
param($Request, $TriggerMetadata) | ||
|
||
$APIName = $TriggerMetadata.FunctionName | ||
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message 'Accessed this API' -Sev 'Debug' | ||
|
||
$Username = ([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($request.headers.'x-ms-client-principal')) | ConvertFrom-Json).userDetails | ||
# Write to the Azure Functions log stream. | ||
Write-Host 'PowerShell HTTP trigger function processed a request.' | ||
|
||
|
||
switch ($Request.Body.Action) { | ||
'Copy' { | ||
$Id = (New-Guid).Guid | ||
} | ||
'Save' { | ||
$Id = $Request.Body.values.reportTemplate.value | ||
} | ||
'Delete' { | ||
$Id = $Request.Body.values.reportTemplate.value | ||
} | ||
} | ||
|
||
$params = $Request.Body.values | Select-Object endpoint, '$filter', '$select', '$count', '$expand', '$search', NoPagination, '$top', IsShared | ||
$Preset = [PSCustomObject]@{ | ||
PartitionKey = 'Preset' | ||
RowKey = [string]$Id | ||
id = [string]$Id | ||
name = [string]$Request.Body.values.name | ||
Owner = [string]$Username | ||
IsShared = $Request.Body.values.IsShared | ||
params = [string](ConvertTo-Json -InputObject $params -Compress) | ||
} | ||
|
||
try { | ||
$Success = $false | ||
$Table = Get-CIPPTable -TableName 'GraphPresets' | ||
$Message = '{0} preset succeeded' -f $Request.Body.Action | ||
if ($Request.Body.Action -eq 'Copy') { | ||
Add-CIPPAzDataTableEntity @Table -Entity $Preset | ||
$Success = $true | ||
} else { | ||
$Entity = Get-CIPPAzDataTableEntity @Table -Filter "RowKey eq '$Id'" | ||
if ($Entity.Owner -eq $Username ) { | ||
if ($Request.Body.Action -eq 'Delete') { | ||
Remove-AzDataTableEntity @Table -Entity $Entity | ||
} elseif ($Request.Body.Action -eq 'Save') { | ||
Add-CIPPAzDataTableEntity @Table -Entity $Preset -Force | ||
} | ||
$Success = $true | ||
} else { | ||
$Message = 'Error: You can only modify your own presets.' | ||
$Success = $false | ||
} | ||
} | ||
|
||
$StatusCode = [HttpStatusCode]::OK | ||
} catch { | ||
$Success = $false | ||
$Message = $_.Exception.Message | ||
$StatusCode = [HttpStatusCode]::BadRequest | ||
} | ||
# Associate values to output bindings by calling 'Push-OutputBinding'. | ||
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ | ||
StatusCode = $StatusCode | ||
Body = @{ | ||
Results = $Message | ||
Success = $Success | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.