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:
parent
775f547e4e
commit
9670ec28b1
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue