Skip to content

Commit 7f543b8

Browse files
committed
2 parents 435aaac + 9d405eb commit 7f543b8

File tree

1 file changed

+105
-4
lines changed

1 file changed

+105
-4
lines changed

README.md

Lines changed: 105 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,110 @@
1-
# powershell-http-template
2-
OpenFaaS HTTP template for PowerShell
31

4-
## Using this template
2+
OpenFaaS PowerShell HTTP function template
3+
=============================================
4+
5+
This template for building Powershell based functions on [OpenFaaS](https://www.openfaas.com), Docker, Knative and Cloud Run.
6+
7+
With this template you can create a new function and deploy it to a platform like [OpenFaaS](https://www.openfaas.com) for:
8+
9+
* scale-to-zero
10+
* horizontal scale-out
11+
* metrics & logs
12+
* automated health-checks
13+
* sane Kubernetes defaults like running as a non-root user
14+
15+
## Status of the template
16+
17+
This template is experimental and I would like your feedback through GitHub issues or [OpenFaaS Slack](https://docs.openfaas.com/community).
18+
19+
## Get started
20+
21+
You can create or scaffold a new function using the [OpenFaaS CLI](https://github.com/openfaas/faas-cli).
22+
523
```
24+
# USERNAME is your Docker Hub account or private Docker registry
25+
$ export USERNAME=alexellisuk
26+
627
$ faas template pull https://github.com/openfaas-incubator/powershell-http-template
7-
$ faas new --lang powershell-http <fn-name>
28+
$ faas new --lang powershell-http-template <fn-name> --prefix="${USERNAME}"
829
```
930

31+
Once you've written your code you can run `faas-cli build` to create a local Docker image, then `faas-cli push` to transfer it to your registry.
32+
33+
You can now deploy it to OpenFaaS, Knative, Google Cloud Run or even use `docker run`.
34+
35+
See also: [Deploy OpenFaaS](https://docs.openfaas.com/deployment/)
36+
37+
## Example usage
38+
39+
### Minimal string based example
40+
41+
```
42+
function Handler {
43+
Param(
44+
[Parameter(Mandatory=$true)]
45+
[FunctionContext]$fnContext,
46+
[Parameter(Mandatory=$true)]
47+
[FunctionResponse]$fnResponse
48+
)
49+
50+
$output = "Hello! Your input was: " + $fnContext.Body
51+
52+
$fnResponse.Body = $output
53+
54+
}
55+
```
56+
57+
### Minimal JSON based example
58+
59+
```
60+
function Handler {
61+
Param(
62+
[Parameter(Mandatory=$true)]
63+
[FunctionContext]$fnContext,
64+
[Parameter(Mandatory=$true)]
65+
[FunctionResponse]$fnResponse
66+
)
67+
68+
$json = $fnContext.Body | Out-String | ConvertFrom-Json
69+
70+
$key1 = $json.key1
71+
$key2 = $json.key2
72+
73+
$output = @{
74+
"Your JSON input was" = @{
75+
key1=$key1;
76+
key2=$key2;
77+
}
78+
} | ConvertTo-Json -Compress
79+
80+
$fnResponse.Body = $output
81+
82+
}
83+
```
84+
85+
86+
### Example usage with WinRM based remote PowerShell module, environment variables and secrets.
87+
88+
```
89+
function Handler {
90+
Param(
91+
[Parameter(Mandatory=$true)]
92+
[FunctionContext]$fnContext,
93+
[Parameter(Mandatory=$true)]
94+
[FunctionResponse]$fnResponse
95+
)
96+
97+
$username = $env:USERNAME
98+
$password = Get-Content "/var/openfaas/secrets/password" | ConvertTo-SecureString -AsPlainText -Force
99+
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList ($username, $password)
100+
101+
$sessionoptions = New-PSSessionOption -SkipCACheck -SkipCNCheck
102+
$output = Invoke-Command -ComputerName <winrm-server> -Authentication Negotiate -SessionOption $sessionoptions -Credential $cred -ScriptBlock {
103+
Import-module ActiveDirectory
104+
Get-Domain
105+
}
106+
107+
$fnResponse.Body = $output
108+
109+
}
110+
```

0 commit comments

Comments
 (0)