add new entmeta stuff.
Signed-off-by: Mark Anderson <manderson@hashicorp.com>
This commit is contained in:
parent
67bedd02cc
commit
497b300c76
|
@ -5,6 +5,11 @@ package acl
|
|||
|
||||
const DefaultPartitionName = ""
|
||||
|
||||
// Reviewer Note: This is a little bit strange; one might want it to be "" like partition name
|
||||
// However in consul/structs/intention.go we define IntentionDefaultNamespace as 'default' and so
|
||||
// we use the same here
|
||||
const DefaultNamespaceName = "default"
|
||||
|
||||
type EnterpriseConfig struct {
|
||||
// no fields in OSS
|
||||
}
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
//go:build !consulent
|
||||
// +build !consulent
|
||||
|
||||
package acl
|
||||
|
||||
import "hash"
|
||||
|
||||
var emptyEnterpriseMeta = EnterpriseMeta{}
|
||||
|
||||
// EnterpriseMeta stub
|
||||
type EnterpriseMeta struct{}
|
||||
|
||||
func (m *EnterpriseMeta) ToEnterprisePolicyMeta() *EnterprisePolicyMeta {
|
||||
return nil
|
||||
}
|
||||
|
||||
func DefaultEnterpriseMeta() *EnterpriseMeta {
|
||||
return &EnterpriseMeta{}
|
||||
}
|
||||
|
||||
func WildcardEnterpriseMeta() *EnterpriseMeta {
|
||||
return &EnterpriseMeta{}
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) EstimateSize() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) AddToHash(_ hash.Hash, _ bool) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) PartitionOrDefault() string {
|
||||
return "default"
|
||||
}
|
||||
|
||||
func EqualPartitions(_, _ string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func IsDefaultPartition(partition string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func PartitionOrDefault(_ string) string {
|
||||
return "default"
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) PartitionOrEmpty() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) InDefaultPartition() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) NamespaceOrDefault() string {
|
||||
return DefaultNamespaceName
|
||||
}
|
||||
|
||||
func NamespaceOrDefault(_ string) string {
|
||||
return DefaultNamespaceName
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) NamespaceOrEmpty() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) InDefaultNamespace() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) Merge(_ *EnterpriseMeta) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) MergeNoWildcard(_ *EnterpriseMeta) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (_ *EnterpriseMeta) Normalize() {}
|
||||
|
||||
func (m *EnterpriseMeta) Matches(_ *EnterpriseMeta) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) IsSame(_ *EnterpriseMeta) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) LessThan(_ *EnterpriseMeta) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) WithWildcardNamespace() *EnterpriseMeta {
|
||||
return &emptyEnterpriseMeta
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) UnsetPartition() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func NewEnterpriseMetaWithPartition(_, _ string) EnterpriseMeta {
|
||||
return emptyEnterpriseMeta
|
||||
}
|
||||
|
||||
// FillAuthzContext stub
|
||||
func (_ *EnterpriseMeta) FillAuthzContext(_ *AuthorizerContext) {}
|
|
@ -1896,13 +1896,13 @@ type CheckID struct {
|
|||
EnterpriseMeta
|
||||
}
|
||||
|
||||
// NamespaceOrDefault exists because structs.EnterpriseMeta uses a pointer
|
||||
// NamespaceOrDefault exists because acl.EnterpriseMeta uses a pointer
|
||||
// receiver for this method. Remove once that is fixed.
|
||||
func (c CheckID) NamespaceOrDefault() string {
|
||||
return c.EnterpriseMeta.NamespaceOrDefault()
|
||||
}
|
||||
|
||||
// PartitionOrDefault exists because structs.EnterpriseMeta uses a pointer
|
||||
// PartitionOrDefault exists because acl.EnterpriseMeta uses a pointer
|
||||
// receiver for this method. Remove once that is fixed.
|
||||
func (c CheckID) PartitionOrDefault() string {
|
||||
return c.EnterpriseMeta.PartitionOrDefault()
|
||||
|
|
|
@ -4,158 +4,70 @@
|
|||
package structs
|
||||
|
||||
import (
|
||||
"hash"
|
||||
|
||||
"github.com/hashicorp/consul/acl"
|
||||
"github.com/hashicorp/consul/types"
|
||||
)
|
||||
|
||||
var emptyEnterpriseMeta = EnterpriseMeta{}
|
||||
|
||||
// EnterpriseMeta stub
|
||||
type EnterpriseMeta struct{}
|
||||
|
||||
func (m *EnterpriseMeta) ToEnterprisePolicyMeta() *acl.EnterprisePolicyMeta {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) estimateSize() int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) addToHash(_ hash.Hash, _ bool) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) Merge(_ *EnterpriseMeta) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) MergeNoWildcard(_ *EnterpriseMeta) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) Matches(_ *EnterpriseMeta) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) IsSame(_ *EnterpriseMeta) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) LessThan(_ *EnterpriseMeta) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) WithWildcardNamespace() *EnterpriseMeta {
|
||||
return &emptyEnterpriseMeta
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) UnsetPartition() {
|
||||
// do nothing
|
||||
}
|
||||
// TODO(acl-move-enterprise-meta) sync this with enterprise
|
||||
var emptyEnterpriseMeta = acl.EnterpriseMeta{}
|
||||
|
||||
// TODO(partition): stop using this
|
||||
func NewEnterpriseMetaInDefaultPartition(_ string) EnterpriseMeta {
|
||||
func NewEnterpriseMetaInDefaultPartition(_ string) acl.EnterpriseMeta {
|
||||
return emptyEnterpriseMeta
|
||||
}
|
||||
|
||||
func NewEnterpriseMetaWithPartition(_, _ string) EnterpriseMeta {
|
||||
return emptyEnterpriseMeta
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) NamespaceOrDefault() string {
|
||||
return IntentionDefaultNamespace
|
||||
}
|
||||
|
||||
func NamespaceOrDefault(_ string) string {
|
||||
return IntentionDefaultNamespace
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) NamespaceOrEmpty() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) InDefaultNamespace() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) PartitionOrDefault() string {
|
||||
return "default"
|
||||
}
|
||||
|
||||
func EqualPartitions(_, _ string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func IsDefaultPartition(partition string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func PartitionOrDefault(_ string) string {
|
||||
return "default"
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) PartitionOrEmpty() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *EnterpriseMeta) InDefaultPartition() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// ReplicationEnterpriseMeta stub
|
||||
func ReplicationEnterpriseMeta() *EnterpriseMeta {
|
||||
func ReplicationEnterpriseMeta() *acl.EnterpriseMeta {
|
||||
return &emptyEnterpriseMeta
|
||||
}
|
||||
|
||||
// TODO(partition): stop using this
|
||||
func DefaultEnterpriseMetaInDefaultPartition() *EnterpriseMeta {
|
||||
func WildcardEnterpriseMetaInDefaultPartition() *acl.EnterpriseMeta {
|
||||
return &emptyEnterpriseMeta
|
||||
}
|
||||
|
||||
// TODO(partition): stop using this
|
||||
func DefaultEnterpriseMetaInDefaultPartition() *acl.EnterpriseMeta {
|
||||
return &emptyEnterpriseMeta
|
||||
}
|
||||
|
||||
// DefaultEnterpriseMetaInPartition stub
|
||||
func DefaultEnterpriseMetaInPartition(_ string) *EnterpriseMeta {
|
||||
return &emptyEnterpriseMeta
|
||||
}
|
||||
|
||||
func NodeEnterpriseMetaInPartition(_ string) *EnterpriseMeta {
|
||||
return &emptyEnterpriseMeta
|
||||
}
|
||||
|
||||
// TODO(partition): stop using this
|
||||
func NodeEnterpriseMetaInDefaultPartition() *EnterpriseMeta {
|
||||
return &emptyEnterpriseMeta
|
||||
}
|
||||
|
||||
// TODO(partition): stop using this
|
||||
func WildcardEnterpriseMetaInDefaultPartition() *EnterpriseMeta {
|
||||
func DefaultEnterpriseMetaInPartition(_ string) *acl.EnterpriseMeta {
|
||||
return &emptyEnterpriseMeta
|
||||
}
|
||||
|
||||
// WildcardEnterpriseMetaInPartition stub
|
||||
func WildcardEnterpriseMetaInPartition(_ string) *EnterpriseMeta {
|
||||
func WildcardEnterpriseMetaInPartition(_ string) *acl.EnterpriseMeta {
|
||||
return &emptyEnterpriseMeta
|
||||
}
|
||||
|
||||
func NewEnterpriseMetaWithPartition(_, _ string) acl.EnterpriseMeta {
|
||||
return emptyEnterpriseMeta
|
||||
}
|
||||
|
||||
func NodeEnterpriseMetaInPartition(_ string) *acl.EnterpriseMeta {
|
||||
return &emptyEnterpriseMeta
|
||||
}
|
||||
|
||||
// TODO(partition): stop using this
|
||||
func NodeEnterpriseMetaInDefaultPartition() *acl.EnterpriseMeta {
|
||||
return &emptyEnterpriseMeta
|
||||
}
|
||||
|
||||
// FillAuthzContext stub
|
||||
func (_ *EnterpriseMeta) FillAuthzContext(_ *acl.AuthorizerContext) {}
|
||||
|
||||
func (_ *Node) FillAuthzContext(_ *acl.AuthorizerContext) {}
|
||||
|
||||
func (_ *Coordinate) FillAuthzContext(_ *acl.AuthorizerContext) {}
|
||||
|
||||
func (_ *NodeInfo) FillAuthzContext(_ *acl.AuthorizerContext) {}
|
||||
|
||||
func (_ *EnterpriseMeta) Normalize() {}
|
||||
|
||||
// FillAuthzContext stub
|
||||
func (_ *DirEntry) FillAuthzContext(_ *acl.AuthorizerContext) {}
|
||||
|
||||
// FillAuthzContext stub
|
||||
func (_ *RegisterRequest) FillAuthzContext(_ *acl.AuthorizerContext) {}
|
||||
|
||||
func (_ *RegisterRequest) GetEnterpriseMeta() *EnterpriseMeta {
|
||||
func (_ *RegisterRequest) GetEnterpriseMeta() *acl.EnterpriseMeta {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -168,15 +80,15 @@ func (_ *TxnServiceOp) FillAuthzContext(_ *acl.AuthorizerContext) {}
|
|||
// OSS Stub
|
||||
func (_ *TxnCheckOp) FillAuthzContext(_ *acl.AuthorizerContext) {}
|
||||
|
||||
func NodeNameString(node string, _ *EnterpriseMeta) string {
|
||||
func NodeNameString(node string, _ *acl.EnterpriseMeta) string {
|
||||
return node
|
||||
}
|
||||
|
||||
func ServiceIDString(id string, _ *EnterpriseMeta) string {
|
||||
func ServiceIDString(id string, _ *acl.EnterpriseMeta) string {
|
||||
return id
|
||||
}
|
||||
|
||||
func ParseServiceIDString(input string) (string, *EnterpriseMeta) {
|
||||
func ParseServiceIDString(input string) (string, *acl.EnterpriseMeta) {
|
||||
return input, DefaultEnterpriseMetaInDefaultPartition()
|
||||
}
|
||||
|
||||
|
@ -189,7 +101,7 @@ func ServiceIDFromString(input string) ServiceID {
|
|||
return ServiceID{ID: id}
|
||||
}
|
||||
|
||||
func ParseServiceNameString(input string) (string, *EnterpriseMeta) {
|
||||
func ParseServiceNameString(input string) (string, *acl.EnterpriseMeta) {
|
||||
return input, DefaultEnterpriseMetaInDefaultPartition()
|
||||
}
|
||||
|
||||
|
|
|
@ -8,39 +8,41 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/hashicorp/consul/acl"
|
||||
)
|
||||
|
||||
var enterpriseMetaField = "EnterpriseMeta"
|
||||
|
||||
func TestServiceID_String(t *testing.T) {
|
||||
t.Run("value", func(t *testing.T) {
|
||||
sid := NewServiceID("the-id", &EnterpriseMeta{})
|
||||
sid := NewServiceID("the-id", &acl.EnterpriseMeta{})
|
||||
require.Equal(t, "the-id", fmt.Sprintf("%v", sid))
|
||||
})
|
||||
t.Run("pointer", func(t *testing.T) {
|
||||
sid := NewServiceID("the-id", &EnterpriseMeta{})
|
||||
sid := NewServiceID("the-id", &acl.EnterpriseMeta{})
|
||||
require.Equal(t, "the-id", fmt.Sprintf("%v", &sid))
|
||||
})
|
||||
}
|
||||
|
||||
func TestCheckID_String(t *testing.T) {
|
||||
t.Run("value", func(t *testing.T) {
|
||||
cid := NewCheckID("the-id", &EnterpriseMeta{})
|
||||
cid := NewCheckID("the-id", &acl.EnterpriseMeta{})
|
||||
require.Equal(t, "the-id", fmt.Sprintf("%v", cid))
|
||||
})
|
||||
t.Run("pointer", func(t *testing.T) {
|
||||
cid := NewCheckID("the-id", &EnterpriseMeta{})
|
||||
cid := NewCheckID("the-id", &acl.EnterpriseMeta{})
|
||||
require.Equal(t, "the-id", fmt.Sprintf("%v", &cid))
|
||||
})
|
||||
}
|
||||
|
||||
func TestServiceName_String(t *testing.T) {
|
||||
t.Run("value", func(t *testing.T) {
|
||||
sn := NewServiceName("the-id", &EnterpriseMeta{})
|
||||
sn := NewServiceName("the-id", &acl.EnterpriseMeta{})
|
||||
require.Equal(t, "the-id", fmt.Sprintf("%v", sn))
|
||||
})
|
||||
t.Run("pointer", func(t *testing.T) {
|
||||
sn := NewServiceName("the-id", &EnterpriseMeta{})
|
||||
sn := NewServiceName("the-id", &acl.EnterpriseMeta{})
|
||||
require.Equal(t, "the-id", fmt.Sprintf("%v", &sn))
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue