Update faas-provider version

Signed-off-by: Alex Ellis <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis
2019-06-08 10:16:30 +01:00
parent 678e93599e
commit 701708fe0e
11 changed files with 167 additions and 18 deletions

View File

@ -22,6 +22,10 @@ type ReadBasicAuth interface {
type ReadBasicAuthFromDisk struct {
SecretMountPath string
UserFilename string
PasswordFilename string
}
func (r *ReadBasicAuthFromDisk) Read() (*BasicAuthCredentials, error) {
@ -31,13 +35,23 @@ func (r *ReadBasicAuthFromDisk) Read() (*BasicAuthCredentials, error) {
return nil, fmt.Errorf("invalid SecretMountPath specified for reading secrets")
}
userPath := path.Join(r.SecretMountPath, "basic-auth-user")
userKey := "basic-auth-user"
if len(r.UserFilename) > 0 {
userKey = r.UserFilename
}
passwordKey := "basic-auth-password"
if len(r.PasswordFilename) > 0 {
passwordKey = r.PasswordFilename
}
userPath := path.Join(r.SecretMountPath, userKey)
user, userErr := ioutil.ReadFile(userPath)
if userErr != nil {
return nil, fmt.Errorf("unable to load %s", userPath)
}
userPassword := path.Join(r.SecretMountPath, "basic-auth-password")
userPassword := path.Join(r.SecretMountPath, passwordKey)
password, passErr := ioutil.ReadFile(userPassword)
if passErr != nil {
return nil, fmt.Errorf("Unable to load %s", userPassword)

View File

@ -0,0 +1,64 @@
// Copyright (c) OpenFaaS Author(s). All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package auth
import (
"io/ioutil"
"os"
"path"
"testing"
)
func Test_ReadFromCustomLocation_AndNames(t *testing.T) {
tmp := os.TempDir()
userWant := "admin"
ioutil.WriteFile(path.Join(tmp, "user.txt"), []byte(userWant), 0700)
passWant := "test1234"
ioutil.WriteFile(path.Join(tmp, "pass.txt"), []byte(passWant), 0700)
reader := ReadBasicAuthFromDisk{
SecretMountPath: tmp,
UserFilename: "user.txt",
PasswordFilename: "pass.txt",
}
creds, err := reader.Read()
if err != nil {
t.Errorf("can't read secrets: %s", err.Error())
}
if creds.User != userWant {
t.Errorf("user, want: %s, got %s", userWant, creds.User)
}
if creds.Password != passWant {
t.Errorf("password, want: %s, got %s", passWant, creds.Password)
}
}
func Test_ReadFromCustomLocation_DefaultNames(t *testing.T) {
tmp := os.TempDir()
userWant := "admin"
ioutil.WriteFile(path.Join(tmp, "basic-auth-user"), []byte(userWant), 0700)
passWant := "test1234"
ioutil.WriteFile(path.Join(tmp, "basic-auth-password"), []byte(passWant), 0700)
reader := ReadBasicAuthFromDisk{
SecretMountPath: tmp,
}
creds, err := reader.Read()
if err != nil {
t.Errorf("can't read secrets: %s", err.Error())
}
if creds.User != userWant {
t.Errorf("user, want: %s, got %s", userWant, creds.User)
}
if creds.Password != passWant {
t.Errorf("password, want: %s, got %s", passWant, creds.Password)
}
}