mirror of https://github.com/hashicorp/consul
use constants in validation.
parent
0f5d0adebd
commit
8a1d017999
|
@ -8,12 +8,25 @@ package acl
|
||||||
const (
|
const (
|
||||||
WildcardPartitionName = ""
|
WildcardPartitionName = ""
|
||||||
DefaultPartitionName = ""
|
DefaultPartitionName = ""
|
||||||
)
|
// NonEmptyDefaultPartitionName is the name of the default partition that is
|
||||||
|
// not empty. An example of this being supplied is when a partition is specified
|
||||||
|
// in the request for DNS by consul-dataplane. This has been added to support
|
||||||
|
// DNS v1.5, which needs to be compatible with the original DNS subsystem which
|
||||||
|
// supports partition being "default" or empty. Otherwise, use DefaultPartitionName.
|
||||||
|
NonEmptyDefaultPartitionName = "default"
|
||||||
|
|
||||||
// Reviewer Note: This is a little bit strange; one might want it to be "" like partition name
|
// DefaultNamespaceName is used to mimic the behavior in consul/structs/intention.go,
|
||||||
// However in consul/structs/intention.go we define IntentionDefaultNamespace as 'default' and so
|
// where we define IntentionDefaultNamespace as 'default' and so we use the same here.
|
||||||
// we use the same here
|
// This is a little bit strange; one might want it to be "" like DefaultPartitionName.
|
||||||
const DefaultNamespaceName = "default"
|
DefaultNamespaceName = "default"
|
||||||
|
|
||||||
|
// EmptyNamespaceName is the name of the default partition that is an empty string.
|
||||||
|
// An example of this being supplied is when a namespace is specifiedDNS v1.
|
||||||
|
// EmptyNamespaceName has been added to support DNS v1.5, which needs to be
|
||||||
|
// compatible with the original DNS subsystem which supports partition being "default" or empty.
|
||||||
|
// Otherwise, use DefaultNamespaceName.
|
||||||
|
EmptyNamespaceName = ""
|
||||||
|
)
|
||||||
|
|
||||||
type EnterpriseConfig struct {
|
type EnterpriseConfig struct {
|
||||||
// no fields in CE
|
// no fields in CE
|
||||||
|
|
|
@ -424,7 +424,6 @@ RPC:
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *V1DataFetcher) ValidateRequest(_ Context, req *QueryPayload) error {
|
func (f *V1DataFetcher) ValidateRequest(_ Context, req *QueryPayload) error {
|
||||||
f.logger.Debug(fmt.Sprintf("req %+v", req))
|
|
||||||
if req.EnableFailover {
|
if req.EnableFailover {
|
||||||
return ErrNotSupported
|
return ErrNotSupported
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ package discovery
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/hashicorp/consul/acl"
|
"github.com/hashicorp/consul/acl"
|
||||||
"github.com/hashicorp/consul/api"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (f *V1DataFetcher) NormalizeRequest(req *QueryPayload) {
|
func (f *V1DataFetcher) NormalizeRequest(req *QueryPayload) {
|
||||||
|
@ -15,8 +14,12 @@ func (f *V1DataFetcher) NormalizeRequest(req *QueryPayload) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// validateEnterpriseTenancy validates the tenancy fields for an enterprise request to
|
||||||
|
// make sure that they are either set to an empty string or "default" to align with the behavior
|
||||||
|
// in CE.
|
||||||
func validateEnterpriseTenancy(req QueryTenancy) error {
|
func validateEnterpriseTenancy(req QueryTenancy) error {
|
||||||
if !(req.Namespace == "" || req.Namespace == acl.DefaultNamespaceName) || !(req.Partition == "" || req.Partition == api.PartitionDefaultName) {
|
if !(req.Namespace == acl.EmptyNamespaceName || req.Namespace == acl.DefaultNamespaceName) ||
|
||||||
|
!(req.Partition == acl.DefaultPartitionName || req.Partition == acl.NonEmptyDefaultPartitionName) {
|
||||||
return ErrNotSupported
|
return ErrNotSupported
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue