Skip to content

Commit

Permalink
Added custom graph request exec.
Browse files Browse the repository at this point in the history
  • Loading branch information
KelvinTegelaar committed Mar 7, 2022
1 parent e03d260 commit e07252a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ExecGraphRequest/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "Request",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "Response"
}
]
}
30 changes: 30 additions & 0 deletions ExecGraphRequest/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using namespace System.Net

# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)

$APIName = $TriggerMetadata.FunctionName
Log-Request -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Accessed this API" -Sev "Debug"

$TenantFilter = $Request.Query.TenantFilter
try {
if ($TenantFilter -ne "AllTenants") {
$GraphRequest = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/$($Request.Query.Endpoint)" -tenantid $TenantFilter
}
else {
$GraphRequest = Get-tenants | ForEach-Object { New-GraphGetRequest -uri "https://graph.microsoft.com/beta/$($Request.Query.Endpoint)" -tenantid $_ }

}
$StatusCode = [HttpStatusCode]::OK
}
catch {
$ErrorMessage = Get-NormalizedError -Message $_.Exception.Message
$StatusCode = [HttpStatusCode]::Forbidden
$GraphRequest = $ErrorMessage
}

# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = $StatusCode
Body = @($GraphRequest)
})

0 comments on commit e07252a

Please sign in to comment.