2023-08-11 13:12:13 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
2023-05-16 19:57:24 +00:00
|
|
|
package utils
|
|
|
|
|
|
|
|
import "github.com/hashicorp/consul/api"
|
|
|
|
|
|
|
|
func PartitionOrDefault(name string) string {
|
|
|
|
if name == "" {
|
|
|
|
return "default"
|
|
|
|
}
|
|
|
|
return name
|
|
|
|
}
|
|
|
|
func NamespaceOrDefault(name string) string {
|
|
|
|
if name == "" {
|
|
|
|
return "default"
|
|
|
|
}
|
|
|
|
return name
|
|
|
|
}
|
|
|
|
|
|
|
|
func DefaultToEmpty(name string) string {
|
|
|
|
if name == "default" {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return name
|
|
|
|
}
|
|
|
|
|
2023-07-18 23:41:30 +00:00
|
|
|
// CompatQueryOpts cleans a QueryOptions so that Partition and Namespace fields
|
|
|
|
// are compatible with OSS or ENT
|
|
|
|
// TODO: not sure why we can't do this server-side
|
|
|
|
func CompatQueryOpts(opts *api.QueryOptions) *api.QueryOptions {
|
|
|
|
opts.Partition = DefaultToEmpty(opts.Partition)
|
|
|
|
opts.Namespace = DefaultToEmpty(opts.Namespace)
|
|
|
|
return opts
|
2023-05-16 19:57:24 +00:00
|
|
|
}
|