Lucas Roesler 156103e2db Update the sample functions
**What**
- Move the new secrets sample function to ApiKeyProtected-Secrets
- Bring back the original ApiKeyProtected sample function

Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
2017-12-16 16:08:52 +00:00

30 lines
491 B
Go

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)
}