Files
faas/gateway/vendor/github.com/openfaas/nats-queue-worker/auth.go
Alex Ellis c394b09ae6 Bump to nats-queue-worker 0.7.0
Includes fix for reconnection bug to NATS Streaming

Signed-off-by: Alex Ellis <alexellis2@gmail.com>
2019-02-12 17:46:00 +00:00

44 lines
989 B
Go

package main
import (
"fmt"
"net/http"
"os"
"github.com/openfaas/faas-provider/auth"
)
//AddBasicAuth to a request by reading secrets
func AddBasicAuth(req *http.Request) error {
if os.Getenv("basic_auth") == "true" {
reader := auth.ReadBasicAuthFromDisk{}
if len(os.Getenv("secret_mount_path")) > 0 {
reader.SecretMountPath = os.Getenv("secret_mount_path")
}
credentials, err := reader.Read()
if err != nil {
return fmt.Errorf("unable to read basic auth: %s", err.Error())
}
req.SetBasicAuth(credentials.User, credentials.Password)
}
return nil
}
//LoadCredentials load credentials from dis
func LoadCredentials() (*auth.BasicAuthCredentials, error) {
reader := auth.ReadBasicAuthFromDisk{}
if len(os.Getenv("secret_mount_path")) > 0 {
reader.SecretMountPath = os.Getenv("secret_mount_path")
}
credentials, err := reader.Read()
if err != nil {
return nil, fmt.Errorf("unable to read basic auth: %s", err.Error())
}
return credentials, nil
}