Azure / Azure/azure-functions-powershell-worker
Feature Request: Attribute-Based Input/Output Bindings using Worker Abstraction Attributes
- Dominant language
- C#
- Stars
- 215
- Forks
- 61
- Avg merge
- 21h 4m
- Merged PRs (30d)
- 6
Description
# User Story
As a PowerShell developer, I want to write my azure functions like I write my PowerShell modules without a bunch of unintuitive folder, json, and run.ps1 abstractions.
# Synopsis
The dotnet isolated worker now provides abstraction attributes with no dependencies for use in defining functions.
https://docs.microsoft.com/en-us/azure/azure-functions/dotnet-isolated-process-guide#bindings
These attributes can be used in PowerShell as well. I've prepared a POC where the attributes are applied in PowerShell, and then can be parsed and have the function.json and run.ps1 generated automatically so that all management of a function's lifecycle is controlled on the function itself, and can work with multi-file modules.
## Example of the default HTTP Demo
```powershell
#requires -module AzureFunctionsHelpers
using namespace Microsoft.Azure.Functions.Worker
[Function('PushHttpOutputBindingDemo')]
[HttpOutput('response')]
param(
[HttpTrigger('Anonymous', ('GET', 'POST'))]
[HttpRequestContext]$Request,
$TriggerMetadata
)
# Write to the Azure Functions log stream.
Write-Host 'PowerShell HTTP trigger function processed a request.'
# Interact with query parameters or the body of the request.
$name = $Request.Query.Name
if (-not $name) {
$name = $Request.Body.Name
}
$body = 'This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.'
if ($name) {
$body = "Hello, $name. This HTTP triggered function executed successfully."
}
# Associate values to output bindings by calling 'Push-OutputBinding'.
$body | Push-HttpBinding -StatusCode OK -Name response
```
The function can be parsed by converting to a scriptblock and using .attributes, or parsing it to a command and reading the parameter attributes, and then generate the host.json or function definition from that.
The PowerShell worker host can do the same, and parse the functions via a separate interface to how the function.json definition works today.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.