mirror of
https://github.com/openfaas/faas.git
synced 2025-06-19 20:46:41 +00:00
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>
This commit is contained in:
committed by
Alex Ellis
parent
1a055deb49
commit
156103e2db
@ -4,21 +4,15 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/openfaas/faas/watchdog/types"
|
||||
)
|
||||
|
||||
func handle(body []byte) {
|
||||
key := os.Getenv("Http_X_Api_Key")
|
||||
|
||||
secretBytes, err := ioutil.ReadFile("/run/secrets/secret_api_key")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
secret := strings.TrimSpace(string(secretBytes))
|
||||
|
||||
if key == secret {
|
||||
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!")
|
||||
@ -27,5 +21,9 @@ func handle(body []byte) {
|
||||
|
||||
func main() {
|
||||
bytes, _ := ioutil.ReadAll(os.Stdin)
|
||||
handle(bytes)
|
||||
req, err := types.UnmarshalRequest(bytes)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
handle(req.Header, req.Body.Raw)
|
||||
}
|
||||
|
Reference in New Issue
Block a user