mirror of
https://github.com/openfaas/faas.git
synced 2025-06-18 03:56:37 +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
31
sample-functions/ApiKeyProtected-Secrets/handler.go
Normal file
31
sample-functions/ApiKeyProtected-Secrets/handler.go
Normal file
@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
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 {
|
||||
fmt.Println("Unlocked the function!")
|
||||
} else {
|
||||
fmt.Println("Access denied!")
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
bytes, _ := ioutil.ReadAll(os.Stdin)
|
||||
handle(bytes)
|
||||
}
|
Reference in New Issue
Block a user