Change how namespaces are specified for the CLI (#6960)

This commit is contained in:
Matt Keeler 2019-12-18 11:06:39 -05:00 committed by GitHub
parent 3faee222f2
commit 34e6e23d43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 4 deletions

View File

@ -71,6 +71,10 @@ const (
// client in this package but is defined here for consistency with all the
// other ENV names we use.
GRPCAddrEnvName = "CONSUL_GRPC_ADDR"
// HTTPNamespaceEnvVar defines an environment variable name which sets
// the HTTP Namespace to be used by default. This can still be overridden.
HTTPNamespaceEnvName = "CONSUL_NAMESPACE"
)
// QueryOptions are used to parameterize a query
@ -427,6 +431,10 @@ func defaultConfig(transportFn func() *http.Transport) *Config {
}
}
if v := os.Getenv(HTTPNamespaceEnvName); v != "" {
config.Namespace = v
}
return config
}

View File

@ -76,8 +76,7 @@ func (f *HTTPFlags) ServerFlags() *flag.FlagSet {
func (f *HTTPFlags) NamespaceFlags() *flag.FlagSet {
fs := flag.NewFlagSet("", flag.ContinueOnError)
// TODO (namespaces) Do we want to allow setting via an env var? CONSUL_NAMESPACE
fs.Var(&f.namespace, "ns",
fs.Var(&f.namespace, "namespace",
"Specifies the namespace to query. If not provided, the namespace will"+
"default to the `default` namespace. Namespaces is a Consul Enterprise feature.")
return fs

View File

@ -1,2 +1,3 @@
* `-ns=<string>` - Specifies the namespace to query. If not provided, the namespace
will default to the `default` namespace. Namespaces is a Consul Enterprise feature added in v1.7.0.
* `-namespace=<string>` - Specifies the namespace to query. If not provided, the namespace will default
to the value of the `CONSUL_NAMESPACE` environment variable or `default` if neither is set. Namespaces
is a Consul Enterprise feature added in v1.7.0.