mirror of
https://github.com/openfaas/faas.git
synced 2025-06-09 16:56:47 +00:00
**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>
30 lines
491 B
Go
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)
|
|
}
|