api.NewClient() now uses $VAULT_NAMESPACE as an input. (#6470)

* api.NewClient() now uses $VAULT_NAMESPACE as an input.

* Remove bogus comments.
This commit is contained in:
ncabatoff 2019-03-25 14:23:59 -04:00 committed by Brian Kassouf
parent 775f547e4e
commit 9670ec28b1
2 changed files with 32 additions and 0 deletions

View File

@ -422,6 +422,10 @@ func NewClient(c *Config) (*Client, error) {
client.token = token
}
if namespace := os.Getenv(EnvVaultNamespace); namespace != "" {
client.SetNamespace(namespace)
}
return client, nil
}

View File

@ -2,6 +2,7 @@ package api
import (
"bytes"
"github.com/hashicorp/vault/helper/consts"
"io"
"net/http"
"os"
@ -195,6 +196,33 @@ func TestClientEnvSettings(t *testing.T) {
}
}
func TestClientEnvNamespace(t *testing.T) {
var seenNamespace string
handler := func(w http.ResponseWriter, req *http.Request) {
seenNamespace = req.Header.Get(consts.NamespaceHeaderName)
}
config, ln := testHTTPServer(t, http.HandlerFunc(handler))
defer ln.Close()
oldVaultNamespace := os.Getenv(EnvVaultNamespace)
defer os.Setenv(EnvVaultNamespace, oldVaultNamespace)
os.Setenv(EnvVaultNamespace, "test")
client, err := NewClient(config)
if err != nil {
t.Fatalf("err: %s", err)
}
_, err = client.RawRequest(client.NewRequest("GET", "/"))
if err != nil {
t.Fatalf("err: %s", err)
}
if seenNamespace != "test" {
t.Fatalf("Bad: %s", seenNamespace)
}
}
func TestParsingRateAndBurst(t *testing.T) {
var (
correctFormat = "400:400"