Browse Source

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

pull/6969/head
Matt Keeler 5 years ago committed by GitHub
parent
commit
34e6e23d43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      api/api.go
  2. 3
      command/flags/http.go
  3. 5
      website/source/docs/commands/_http_api_namespace_options.html.md

8
api/api.go

@ -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
}

3
command/flags/http.go

@ -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

5
website/source/docs/commands/_http_api_namespace_options.html.md

@ -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.

Loading…
Cancel
Save