2023-03-28 19:39:22 +01:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-11 09:12:13 -04:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-28 19:39:22 +01:00
|
|
|
|
2021-11-16 12:04:01 -06:00
|
|
|
//go:build !consulent
|
2019-10-24 14:38:09 -04:00
|
|
|
|
|
|
|
package structs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hashicorp/consul/acl"
|
2020-01-03 15:51:19 -05:00
|
|
|
"github.com/hashicorp/consul/types"
|
2019-10-24 14:38:09 -04:00
|
|
|
)
|
|
|
|
|
2022-03-11 19:51:24 -08:00
|
|
|
// TODO(acl-move-enterprise-meta) sync this with enterprise
|
|
|
|
var emptyEnterpriseMeta = acl.EnterpriseMeta{}
|
2021-12-08 11:02:14 -08:00
|
|
|
|
2021-07-22 13:20:45 -05:00
|
|
|
// TODO(partition): stop using this
|
2022-03-11 19:51:24 -08:00
|
|
|
func NewEnterpriseMetaInDefaultPartition(_ string) acl.EnterpriseMeta {
|
2021-07-22 13:20:45 -05:00
|
|
|
return emptyEnterpriseMeta
|
|
|
|
}
|
|
|
|
|
2022-03-11 19:51:24 -08:00
|
|
|
// ReplicationEnterpriseMeta stub
|
|
|
|
func ReplicationEnterpriseMeta() *acl.EnterpriseMeta {
|
|
|
|
return &emptyEnterpriseMeta
|
2021-08-25 13:40:47 +01:00
|
|
|
}
|
|
|
|
|
2022-03-11 19:51:24 -08:00
|
|
|
// TODO(partition): stop using this
|
|
|
|
func WildcardEnterpriseMetaInDefaultPartition() *acl.EnterpriseMeta {
|
2019-12-06 14:01:34 -05:00
|
|
|
return &emptyEnterpriseMeta
|
2019-10-24 14:38:09 -04:00
|
|
|
}
|
|
|
|
|
2021-07-22 13:20:45 -05:00
|
|
|
// TODO(partition): stop using this
|
2022-03-11 19:51:24 -08:00
|
|
|
func DefaultEnterpriseMetaInDefaultPartition() *acl.EnterpriseMeta {
|
2021-07-22 13:20:45 -05:00
|
|
|
return &emptyEnterpriseMeta
|
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultEnterpriseMetaInPartition stub
|
2022-03-11 19:51:24 -08:00
|
|
|
func DefaultEnterpriseMetaInPartition(_ string) *acl.EnterpriseMeta {
|
2021-07-22 13:20:45 -05:00
|
|
|
return &emptyEnterpriseMeta
|
|
|
|
}
|
|
|
|
|
2022-03-11 19:51:24 -08:00
|
|
|
// WildcardEnterpriseMetaInPartition stub
|
|
|
|
func WildcardEnterpriseMetaInPartition(_ string) *acl.EnterpriseMeta {
|
2021-07-22 13:20:45 -05:00
|
|
|
return &emptyEnterpriseMeta
|
|
|
|
}
|
|
|
|
|
2022-03-11 19:51:24 -08:00
|
|
|
func NewEnterpriseMetaWithPartition(_, _ string) acl.EnterpriseMeta {
|
|
|
|
return emptyEnterpriseMeta
|
2021-07-22 13:20:45 -05:00
|
|
|
}
|
|
|
|
|
2022-03-11 19:51:24 -08:00
|
|
|
func NodeEnterpriseMetaInPartition(_ string) *acl.EnterpriseMeta {
|
2019-12-06 14:01:34 -05:00
|
|
|
return &emptyEnterpriseMeta
|
2019-10-24 14:38:09 -04:00
|
|
|
}
|
|
|
|
|
2022-03-11 19:51:24 -08:00
|
|
|
// TODO(partition): stop using this
|
|
|
|
func NodeEnterpriseMetaInDefaultPartition() *acl.EnterpriseMeta {
|
2019-12-06 14:01:34 -05:00
|
|
|
return &emptyEnterpriseMeta
|
|
|
|
}
|
2019-10-24 14:38:09 -04:00
|
|
|
|
2022-11-14 11:36:27 -07:00
|
|
|
func (n *Node) FillAuthzContext(ctx *acl.AuthorizerContext) {
|
|
|
|
if ctx == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ctx.Peer = n.PeerName
|
|
|
|
}
|
2021-08-25 13:43:11 -05:00
|
|
|
|
2022-05-19 16:37:52 -05:00
|
|
|
func (n *Node) OverridePartition(_ string) {
|
|
|
|
n.Partition = ""
|
|
|
|
}
|
|
|
|
|
2021-08-25 13:43:11 -05:00
|
|
|
func (_ *Coordinate) FillAuthzContext(_ *acl.AuthorizerContext) {}
|
|
|
|
|
2022-11-14 12:35:20 -07:00
|
|
|
func (n *NodeInfo) FillAuthzContext(ctx *acl.AuthorizerContext) {
|
|
|
|
ctx.Peer = n.PeerName
|
|
|
|
}
|
2021-08-25 13:43:11 -05:00
|
|
|
|
2019-12-09 21:26:41 -05:00
|
|
|
// FillAuthzContext stub
|
2019-12-18 13:43:24 -05:00
|
|
|
func (_ *DirEntry) FillAuthzContext(_ *acl.AuthorizerContext) {}
|
2019-12-09 21:26:41 -05:00
|
|
|
|
2019-11-01 16:48:44 -04:00
|
|
|
// FillAuthzContext stub
|
2019-12-18 13:43:24 -05:00
|
|
|
func (_ *RegisterRequest) FillAuthzContext(_ *acl.AuthorizerContext) {}
|
2019-12-09 21:26:41 -05:00
|
|
|
|
2022-03-11 19:51:24 -08:00
|
|
|
func (_ *RegisterRequest) GetEnterpriseMeta() *acl.EnterpriseMeta {
|
2019-12-09 21:26:41 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-08-22 09:46:03 -05:00
|
|
|
// CE Stub
|
2019-12-18 13:43:24 -05:00
|
|
|
func (op *TxnNodeOp) FillAuthzContext(ctx *acl.AuthorizerContext) {}
|
2019-12-09 21:26:41 -05:00
|
|
|
|
2023-08-22 09:46:03 -05:00
|
|
|
// CE Stub
|
2019-12-18 13:43:24 -05:00
|
|
|
func (_ *TxnServiceOp) FillAuthzContext(_ *acl.AuthorizerContext) {}
|
2019-12-09 21:26:41 -05:00
|
|
|
|
2023-08-22 09:46:03 -05:00
|
|
|
// CE Stub
|
2019-12-18 13:43:24 -05:00
|
|
|
func (_ *TxnCheckOp) FillAuthzContext(_ *acl.AuthorizerContext) {}
|
2019-12-09 21:26:41 -05:00
|
|
|
|
2022-03-11 19:51:24 -08:00
|
|
|
func NodeNameString(node string, _ *acl.EnterpriseMeta) string {
|
2021-08-25 13:43:11 -05:00
|
|
|
return node
|
|
|
|
}
|
|
|
|
|
2022-03-11 19:51:24 -08:00
|
|
|
func ServiceIDString(id string, _ *acl.EnterpriseMeta) string {
|
2019-12-09 21:26:41 -05:00
|
|
|
return id
|
|
|
|
}
|
|
|
|
|
2022-03-11 19:51:24 -08:00
|
|
|
func ParseServiceIDString(input string) (string, *acl.EnterpriseMeta) {
|
2021-07-22 13:20:45 -05:00
|
|
|
return input, DefaultEnterpriseMetaInDefaultPartition()
|
2020-01-24 10:04:58 -05:00
|
|
|
}
|
|
|
|
|
2020-12-11 16:10:00 -05:00
|
|
|
func (sid ServiceID) String() string {
|
2019-12-09 21:26:41 -05:00
|
|
|
return sid.ID
|
|
|
|
}
|
|
|
|
|
2020-01-24 10:04:58 -05:00
|
|
|
func ServiceIDFromString(input string) ServiceID {
|
|
|
|
id, _ := ParseServiceIDString(input)
|
|
|
|
return ServiceID{ID: id}
|
|
|
|
}
|
|
|
|
|
2022-03-11 19:51:24 -08:00
|
|
|
func ParseServiceNameString(input string) (string, *acl.EnterpriseMeta) {
|
2021-07-22 13:20:45 -05:00
|
|
|
return input, DefaultEnterpriseMetaInDefaultPartition()
|
2020-06-12 08:57:41 -06:00
|
|
|
}
|
|
|
|
|
2020-12-11 16:10:00 -05:00
|
|
|
func (n ServiceName) String() string {
|
2020-06-12 08:57:41 -06:00
|
|
|
return n.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
func ServiceNameFromString(input string) ServiceName {
|
|
|
|
id, _ := ParseServiceNameString(input)
|
|
|
|
return ServiceName{Name: id}
|
|
|
|
}
|
|
|
|
|
2022-05-12 10:08:50 -05:00
|
|
|
// Less implements sort.Interface.
|
|
|
|
func (s ServiceList) Less(i, j int) bool {
|
|
|
|
a, b := s[i], s[j]
|
|
|
|
return a.Name < b.Name
|
|
|
|
}
|
|
|
|
|
2020-12-11 16:10:00 -05:00
|
|
|
func (cid CheckID) String() string {
|
2019-12-09 21:26:41 -05:00
|
|
|
return string(cid.ID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (_ *HealthCheck) Validate() error {
|
|
|
|
return nil
|
|
|
|
}
|
2020-01-03 15:51:19 -05:00
|
|
|
|
2020-10-09 14:57:29 -05:00
|
|
|
func enterpriseRequestType(m MessageType) (string, bool) {
|
|
|
|
return "", false
|
|
|
|
}
|
|
|
|
|
2020-01-03 15:51:19 -05:00
|
|
|
// CheckIDs returns the IDs for all checks associated with a session, regardless of type
|
|
|
|
func (s *Session) CheckIDs() []types.CheckID {
|
|
|
|
// Merge all check IDs into a single slice, since they will be handled the same way
|
|
|
|
checks := make([]types.CheckID, 0, len(s.Checks)+len(s.NodeChecks)+len(s.ServiceChecks))
|
|
|
|
checks = append(checks, s.Checks...)
|
|
|
|
|
|
|
|
for _, c := range s.NodeChecks {
|
|
|
|
checks = append(checks, types.CheckID(c))
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, c := range s.ServiceChecks {
|
|
|
|
checks = append(checks, types.CheckID(c.ID))
|
|
|
|
}
|
|
|
|
return checks
|
|
|
|
}
|
2021-03-17 22:15:48 -06:00
|
|
|
|
|
|
|
func (t *Intention) HasWildcardSource() bool {
|
|
|
|
return t.SourceName == WildcardSpecifier
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *Intention) HasWildcardDestination() bool {
|
|
|
|
return t.DestinationName == WildcardSpecifier
|
|
|
|
}
|
2021-07-22 14:33:22 -05:00
|
|
|
|
|
|
|
func (s *ServiceNode) NodeIdentity() Identity {
|
|
|
|
return Identity{ID: s.Node}
|
|
|
|
}
|
2023-02-08 12:07:21 -08:00
|
|
|
|
|
|
|
type EnterpriseServiceUsage struct{}
|
2023-10-06 13:59:47 -05:00
|
|
|
|
|
|
|
// WithNormalizedUpstreams returns a deep copy of the NodeService with no modifications to
|
|
|
|
// data for CE versions.
|
|
|
|
func (ns *NodeService) WithNormalizedUpstreams() *NodeService {
|
|
|
|
// Simply return a copy for CE, since it doesn't have partitions or namespaces.
|
|
|
|
if ns == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return ns.DeepCopy()
|
|
|
|
}
|