Skip to content
Snippets Groups Projects
Commit 56e8c5b2 authored by Alex Ellis's avatar Alex Ellis
Browse files

Remove legacy sample function


Signed-off-by: default avatarAlex Ellis <alexellis2@gmail.com>
parent 9cdf24df
No related branches found
No related tags found
No related merge requests found
ApiKeyProtected
FROM golang:1.9.4-alpine as builder
MAINTAINER alex@openfaas.com
ENTRYPOINT []
RUN apk --no-cache add make curl \
&& curl -sL https://github.com/openfaas/faas/releases/download/0.7.1/fwatchdog > /usr/bin/fwatchdog \
&& chmod +x /usr/bin/fwatchdog
WORKDIR /go/src/github.com/openfaas/faas/sample-functions/ApiKeyProtected
COPY handler.go .
# COPY vendor vendor
RUN go install
FROM alpine:3.6
# Needed to reach the hub
RUN apk --no-cache add ca-certificates
COPY --from=builder /usr/bin/fwatchdog /usr/bin/fwatchdog
COPY --from=builder /go/bin/ApiKeyProtected /usr/bin/ApiKeyProtected
ENV fprocess "/usr/bin/ApiKeyProtected"
CMD ["/usr/bin/fwatchdog"]
### Api-Key-Protected sample
To use this sample provide an env variable for the container/service in `secret_api_key`.
Then when calling via the gateway pass the additional header "X-Api-Key", if it matches the `secret_api_key` value then the function will give access, otherwise access denied.
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"github.com/openfaas/faas/watchdog/types"
)
func handle(header http.Header, body []byte) {
key := header.Get("X-Api-Key")
if key == os.Getenv("secret_api_key") {
fmt.Println("Unlocked the function!")
} else {
fmt.Println("Access denied!")
}
}
func main() {
bytes, _ := ioutil.ReadAll(os.Stdin)
req, err := types.UnmarshalRequest(bytes)
if err != nil {
log.Fatal(err)
}
handle(req.Header, req.Body.Raw)
}
......@@ -19,14 +19,13 @@ Here is a list of some of the sample functions included this repository.
| Name | Details |
|------------------------|----------------------------------------- |
| AlpineFunction | BusyBox - a useful base image with busybox utilities pre-installed |
| ApiKeyProtected | Example in Golang showing how to read X-Api-Key header |
| CaptainsIntent | Alexa skill - find the count of Docker Captains |
| ChangeColorIntent | Alexa skill - change the colour of IoT-connected lights |
| echo | Uses `cat` from BusyBox to provide an echo function |
| DockerHubStats | Golang function gives the count of repos a user has on the Docker hub |
| HostnameIntent | Prints the hostname of a container |
| NodeInfo | Node.js - gives CPU/network info on the current container |
| WebhookStash | Golang function provides way to capture webhooks - JSON/text/binary are all OK |
| WordCountFunction | BusyBox `wc` is exposed as a function / service through FaaS |
| AlpineFunction | BusyBox - a useful base image with busybox utilities pre-installed |
| ApiKeyProtected-Secrets | Example in Golang showing how to read a secret from a HTTP header and validate with a Swarm/Kubernetes secret |
| CaptainsIntent | Alexa skill - find the count of Docker Captains |
| ChangeColorIntent | Alexa skill - change the colour of IoT-connected lights |
| echo | Uses `cat` from BusyBox to provide an echo function |
| DockerHubStats | Golang function gives the count of repos a user has on the Docker hub |
| HostnameIntent | Prints the hostname of a container |
| NodeInfo | Node.js - gives CPU/network info on the current container |
| WebhookStash | Golang function provides way to capture webhooks - JSON/text/binary are all OK |
| WordCountFunction | BusyBox `wc` is exposed as a function / service through FaaS |
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment