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 #20 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
- Loading branch information
Showing
4 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecAzBobbyTables.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,58 @@ | ||
|
||
function Invoke-ExecAzBobbyTables { | ||
<# | ||
.SYNOPSIS | ||
Execute a AzBobbyTables function | ||
.DESCRIPTION | ||
This function is used to interact with Azure Tables. This is advanced functionality used for external integrations or SuperAdmin functionality. | ||
.FUNCTIONALITY | ||
Entrypoint | ||
.ROLE | ||
CIPP.SuperAdmin.ReadWrite | ||
#> | ||
[CmdletBinding()] | ||
param($Request, $TriggerMetadata) | ||
|
||
$AllowList = @( | ||
'Add-AzDataTableEntity' | ||
'Update-AzDataTableEntity' | ||
'Get-AzDataTableEntity' | ||
'Get-AzDataTable' | ||
'New-AzDataTable' | ||
'Remove-AzDataTableEntity' | ||
'Remove-AzDataTable' | ||
) | ||
|
||
$Function = $Request.Body.FunctionName | ||
$Params = if ($Request.Body.Parameters) { | ||
$Request.Body.Parameters | ConvertTo-Json -Compress -ErrorAction Stop | ConvertFrom-Json -AsHashtable | ||
} else { | ||
@{} | ||
} | ||
|
||
if ($Function -in $AllowList) { | ||
if ($Function -eq 'Get-AzDataTable') { | ||
$Context = New-AzDataTableContext -ConnectionString $env:AzureWebJobsStorage | ||
} else { | ||
$Context = New-AzDataTableContext -ConnectionString $env:AzureWebJobsStorage -TableName $Request.Body.TableName | ||
} | ||
try { | ||
$Results = & $Function -Context $Context @Params | ||
if (!$Results) { | ||
$Results = "Function $Function executed successfully" | ||
} | ||
$StatusCode = [HttpStatusCode]::OK | ||
} catch { | ||
$Results = $_.Exception.Message | ||
$StatusCode = [HttpStatusCode]::InternalServerError | ||
} | ||
} else { | ||
$Results = "Function $Function not found or not allowed" | ||
$StatusCode = [HttpStatusCode]::NotFound | ||
} | ||
|
||
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{ | ||
StatusCode = $StatusCode | ||
Body = $Results | ||
}) | ||
} |
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