2023-03-28 18:39:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2021-11-08 21:20:50 +00:00
|
|
|
//go:build !consulent
|
2021-03-16 19:29:30 +00:00
|
|
|
// +build !consulent
|
|
|
|
|
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2022-04-05 21:10:06 +00:00
|
|
|
"github.com/hashicorp/consul/acl"
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
2021-03-16 19:29:30 +00:00
|
|
|
)
|
|
|
|
|
2022-06-23 15:07:19 +00:00
|
|
|
func prefixIndexFromQuery(arg any) ([]byte, error) {
|
2021-03-16 19:29:30 +00:00
|
|
|
var b indexBuilder
|
|
|
|
switch v := arg.(type) {
|
2022-04-05 21:10:06 +00:00
|
|
|
case *acl.EnterpriseMeta:
|
2021-03-16 19:29:30 +00:00
|
|
|
return nil, nil
|
2022-04-05 21:10:06 +00:00
|
|
|
case acl.EnterpriseMeta:
|
2021-03-16 19:29:30 +00:00
|
|
|
return nil, nil
|
|
|
|
case Query:
|
2021-11-08 21:20:50 +00:00
|
|
|
if v.Value == "" {
|
|
|
|
return nil, nil
|
|
|
|
}
|
2021-03-16 19:29:30 +00:00
|
|
|
b.String(strings.ToLower(v.Value))
|
|
|
|
return b.Bytes(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("unexpected type %T for Query prefix index", arg)
|
|
|
|
}
|
2021-08-17 18:29:39 +00:00
|
|
|
|
2022-06-23 15:07:19 +00:00
|
|
|
func prefixIndexFromQueryWithPeer(arg any) ([]byte, error) {
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
var b indexBuilder
|
|
|
|
switch v := arg.(type) {
|
|
|
|
case *acl.EnterpriseMeta:
|
|
|
|
return nil, nil
|
|
|
|
case acl.EnterpriseMeta:
|
|
|
|
return nil, nil
|
|
|
|
case Query:
|
|
|
|
if v.PeerOrEmpty() == "" {
|
|
|
|
b.String(structs.LocalPeerKeyword)
|
|
|
|
} else {
|
|
|
|
b.String(strings.ToLower(v.PeerOrEmpty()))
|
|
|
|
}
|
|
|
|
if v.Value == "" {
|
|
|
|
return b.Bytes(), nil
|
|
|
|
}
|
|
|
|
b.String(strings.ToLower(v.Value))
|
|
|
|
return b.Bytes(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("unexpected type %T for Query prefix index", arg)
|
|
|
|
}
|
|
|
|
|
2022-06-29 20:34:58 +00:00
|
|
|
// prefixIndexFromQueryWithPeerWildcardable allows for a wildcard "*" peerName
|
|
|
|
// to query for all peers _excluding_ structs.LocalPeerKeyword.
|
|
|
|
// Assumes that non-local peers are prefixed with "peer:".
|
|
|
|
func prefixIndexFromQueryWithPeerWildcardable(v Query) ([]byte, error) {
|
|
|
|
var b indexBuilder
|
|
|
|
|
|
|
|
peername := v.PeerOrEmpty()
|
|
|
|
if peername == "" {
|
|
|
|
b.String(strings.ToLower(structs.LocalPeerKeyword))
|
|
|
|
} else if peername == "*" {
|
|
|
|
// use b.Raw so we don't add null terminator to prefix
|
|
|
|
b.Raw([]byte("peer:"))
|
|
|
|
return b.Bytes(), nil
|
|
|
|
} else {
|
|
|
|
b.String(strings.ToLower("peer:" + peername))
|
|
|
|
}
|
|
|
|
|
|
|
|
if v.Value != "" {
|
|
|
|
b.String(strings.ToLower(v.Value))
|
|
|
|
}
|
|
|
|
return b.Bytes(), nil
|
|
|
|
}
|
|
|
|
|
2021-08-17 18:29:39 +00:00
|
|
|
func prefixIndexFromQueryNoNamespace(arg interface{}) ([]byte, error) {
|
|
|
|
return prefixIndexFromQuery(arg)
|
|
|
|
}
|
|
|
|
|
2021-09-10 20:56:56 +00:00
|
|
|
// indexFromAuthMethodQuery builds an index key where Query.Value is lowercase, and is
|
|
|
|
// a required value.
|
2022-06-23 15:07:19 +00:00
|
|
|
func indexFromAuthMethodQuery(q AuthMethodQuery) ([]byte, error) {
|
2021-09-10 20:56:56 +00:00
|
|
|
var b indexBuilder
|
|
|
|
b.String(strings.ToLower(q.Value))
|
|
|
|
return b.Bytes(), nil
|
|
|
|
}
|