add new entmeta stuff.

Signed-off-by: Mark Anderson <manderson@hashicorp.com>
This commit is contained in:
Mark Anderson 2022-03-11 19:51:24 -08:00
parent 96748197fc
commit 897ba08cfd
5 changed files with 153 additions and 126 deletions

View File

@ -5,6 +5,11 @@ package acl
const DefaultPartitionName = "" 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 { type EnterpriseConfig struct {
// no fields in OSS // no fields in OSS
} }

108
acl/enterprisemeta_oss.go Normal file
View File

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

View File

@ -1896,13 +1896,13 @@ type CheckID struct {
EnterpriseMeta 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. // receiver for this method. Remove once that is fixed.
func (c CheckID) NamespaceOrDefault() string { func (c CheckID) NamespaceOrDefault() string {
return c.EnterpriseMeta.NamespaceOrDefault() 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. // receiver for this method. Remove once that is fixed.
func (c CheckID) PartitionOrDefault() string { func (c CheckID) PartitionOrDefault() string {
return c.EnterpriseMeta.PartitionOrDefault() return c.EnterpriseMeta.PartitionOrDefault()

View File

@ -4,158 +4,70 @@
package structs package structs
import ( import (
"hash"
"github.com/hashicorp/consul/acl" "github.com/hashicorp/consul/acl"
"github.com/hashicorp/consul/types" "github.com/hashicorp/consul/types"
) )
var emptyEnterpriseMeta = EnterpriseMeta{} // TODO(acl-move-enterprise-meta) sync this with enterprise
var emptyEnterpriseMeta = acl.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(partition): stop using this // TODO(partition): stop using this
func NewEnterpriseMetaInDefaultPartition(_ string) EnterpriseMeta { func NewEnterpriseMetaInDefaultPartition(_ string) acl.EnterpriseMeta {
return emptyEnterpriseMeta 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 // ReplicationEnterpriseMeta stub
func ReplicationEnterpriseMeta() *EnterpriseMeta { func ReplicationEnterpriseMeta() *acl.EnterpriseMeta {
return &emptyEnterpriseMeta return &emptyEnterpriseMeta
} }
// TODO(partition): stop using this // 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 return &emptyEnterpriseMeta
} }
// DefaultEnterpriseMetaInPartition stub // DefaultEnterpriseMetaInPartition stub
func DefaultEnterpriseMetaInPartition(_ string) *EnterpriseMeta { func DefaultEnterpriseMetaInPartition(_ string) *acl.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 {
return &emptyEnterpriseMeta return &emptyEnterpriseMeta
} }
// WildcardEnterpriseMetaInPartition stub // 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 return &emptyEnterpriseMeta
} }
// FillAuthzContext stub // FillAuthzContext stub
func (_ *EnterpriseMeta) FillAuthzContext(_ *acl.AuthorizerContext) {}
func (_ *Node) FillAuthzContext(_ *acl.AuthorizerContext) {} func (_ *Node) FillAuthzContext(_ *acl.AuthorizerContext) {}
func (_ *Coordinate) FillAuthzContext(_ *acl.AuthorizerContext) {} func (_ *Coordinate) FillAuthzContext(_ *acl.AuthorizerContext) {}
func (_ *NodeInfo) FillAuthzContext(_ *acl.AuthorizerContext) {} func (_ *NodeInfo) FillAuthzContext(_ *acl.AuthorizerContext) {}
func (_ *EnterpriseMeta) Normalize() {}
// FillAuthzContext stub // FillAuthzContext stub
func (_ *DirEntry) FillAuthzContext(_ *acl.AuthorizerContext) {} func (_ *DirEntry) FillAuthzContext(_ *acl.AuthorizerContext) {}
// FillAuthzContext stub // FillAuthzContext stub
func (_ *RegisterRequest) FillAuthzContext(_ *acl.AuthorizerContext) {} func (_ *RegisterRequest) FillAuthzContext(_ *acl.AuthorizerContext) {}
func (_ *RegisterRequest) GetEnterpriseMeta() *EnterpriseMeta { func (_ *RegisterRequest) GetEnterpriseMeta() *acl.EnterpriseMeta {
return nil return nil
} }
@ -168,15 +80,15 @@ func (_ *TxnServiceOp) FillAuthzContext(_ *acl.AuthorizerContext) {}
// OSS Stub // OSS Stub
func (_ *TxnCheckOp) FillAuthzContext(_ *acl.AuthorizerContext) {} func (_ *TxnCheckOp) FillAuthzContext(_ *acl.AuthorizerContext) {}
func NodeNameString(node string, _ *EnterpriseMeta) string { func NodeNameString(node string, _ *acl.EnterpriseMeta) string {
return node return node
} }
func ServiceIDString(id string, _ *EnterpriseMeta) string { func ServiceIDString(id string, _ *acl.EnterpriseMeta) string {
return id return id
} }
func ParseServiceIDString(input string) (string, *EnterpriseMeta) { func ParseServiceIDString(input string) (string, *acl.EnterpriseMeta) {
return input, DefaultEnterpriseMetaInDefaultPartition() return input, DefaultEnterpriseMetaInDefaultPartition()
} }
@ -189,7 +101,7 @@ func ServiceIDFromString(input string) ServiceID {
return ServiceID{ID: id} return ServiceID{ID: id}
} }
func ParseServiceNameString(input string) (string, *EnterpriseMeta) { func ParseServiceNameString(input string) (string, *acl.EnterpriseMeta) {
return input, DefaultEnterpriseMetaInDefaultPartition() return input, DefaultEnterpriseMetaInDefaultPartition()
} }

View File

@ -8,39 +8,41 @@ import (
"testing" "testing"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/hashicorp/consul/acl"
) )
var enterpriseMetaField = "EnterpriseMeta" var enterpriseMetaField = "EnterpriseMeta"
func TestServiceID_String(t *testing.T) { func TestServiceID_String(t *testing.T) {
t.Run("value", func(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)) require.Equal(t, "the-id", fmt.Sprintf("%v", sid))
}) })
t.Run("pointer", func(t *testing.T) { 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)) require.Equal(t, "the-id", fmt.Sprintf("%v", &sid))
}) })
} }
func TestCheckID_String(t *testing.T) { func TestCheckID_String(t *testing.T) {
t.Run("value", func(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)) require.Equal(t, "the-id", fmt.Sprintf("%v", cid))
}) })
t.Run("pointer", func(t *testing.T) { 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)) require.Equal(t, "the-id", fmt.Sprintf("%v", &cid))
}) })
} }
func TestServiceName_String(t *testing.T) { func TestServiceName_String(t *testing.T) {
t.Run("value", func(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)) require.Equal(t, "the-id", fmt.Sprintf("%v", sn))
}) })
t.Run("pointer", func(t *testing.T) { 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)) require.Equal(t, "the-id", fmt.Sprintf("%v", &sn))
}) })
} }