2021-11-16 18:04:01 +00:00
|
|
|
//go:build !consulent
|
2020-01-24 15:04:58 +00:00
|
|
|
// +build !consulent
|
|
|
|
|
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
2021-02-09 17:37:57 +00:00
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2020-01-24 15:04:58 +00:00
|
|
|
memdb "github.com/hashicorp/go-memdb"
|
|
|
|
|
2022-04-05 21:10:06 +00:00
|
|
|
"github.com/hashicorp/consul/acl"
|
2022-02-22 16:36:36 +00:00
|
|
|
"github.com/hashicorp/consul/agent/configentry"
|
2021-01-29 01:34:15 +00:00
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
|
|
|
)
|
2020-01-24 15:04:58 +00:00
|
|
|
|
2021-02-09 17:37:57 +00:00
|
|
|
func indexFromConfigEntryKindName(arg interface{}) ([]byte, error) {
|
2021-03-31 20:21:21 +00:00
|
|
|
var b indexBuilder
|
|
|
|
|
|
|
|
switch n := arg.(type) {
|
2022-04-05 21:10:06 +00:00
|
|
|
case *acl.EnterpriseMeta:
|
2021-03-31 20:21:21 +00:00
|
|
|
return nil, nil
|
2022-04-05 21:10:06 +00:00
|
|
|
case acl.EnterpriseMeta:
|
2021-03-31 20:21:21 +00:00
|
|
|
return b.Bytes(), nil
|
|
|
|
case ConfigEntryKindQuery:
|
|
|
|
b.String(strings.ToLower(n.Kind))
|
|
|
|
return b.Bytes(), nil
|
2022-02-22 16:36:36 +00:00
|
|
|
case configentry.KindName:
|
2021-03-31 20:21:21 +00:00
|
|
|
b.String(strings.ToLower(n.Kind))
|
|
|
|
b.String(strings.ToLower(n.Name))
|
|
|
|
return b.Bytes(), nil
|
2021-02-09 17:37:57 +00:00
|
|
|
}
|
|
|
|
|
2021-03-31 20:21:21 +00:00
|
|
|
return nil, fmt.Errorf("invalid type for ConfigEntryKindName query: %T", arg)
|
2020-01-24 15:04:58 +00:00
|
|
|
}
|
|
|
|
|
2020-08-11 20:31:23 +00:00
|
|
|
func validateConfigEntryEnterprise(_ ReadTxn, _ structs.ConfigEntry) error {
|
2020-05-08 18:24:33 +00:00
|
|
|
return nil
|
2020-01-24 15:04:58 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 21:10:06 +00:00
|
|
|
func getAllConfigEntriesWithTxn(tx ReadTxn, _ *acl.EnterpriseMeta) (memdb.ResultIterator, error) {
|
2021-03-10 18:37:17 +00:00
|
|
|
return tx.Get(tableConfigEntries, indexID)
|
2020-01-24 15:04:58 +00:00
|
|
|
}
|
|
|
|
|
2021-10-13 14:47:12 +00:00
|
|
|
func getAllConfigEntriesByKindWithTxn(tx ReadTxn, kind string) (memdb.ResultIterator, error) {
|
|
|
|
return getConfigEntryKindsWithTxn(tx, kind, nil)
|
|
|
|
}
|
|
|
|
|
2022-04-05 21:10:06 +00:00
|
|
|
func getConfigEntryKindsWithTxn(tx ReadTxn, kind string, _ *acl.EnterpriseMeta) (memdb.ResultIterator, error) {
|
2021-03-31 20:21:21 +00:00
|
|
|
return tx.Get(tableConfigEntries, indexID+"_prefix", ConfigEntryKindQuery{Kind: kind})
|
2020-01-24 15:04:58 +00:00
|
|
|
}
|
2020-10-06 18:24:05 +00:00
|
|
|
|
2022-04-05 21:10:06 +00:00
|
|
|
func configIntentionsConvertToList(iter memdb.ResultIterator, _ *acl.EnterpriseMeta) structs.Intentions {
|
2020-10-06 18:24:05 +00:00
|
|
|
var results structs.Intentions
|
|
|
|
for v := iter.Next(); v != nil; v = iter.Next() {
|
|
|
|
entry := v.(*structs.ServiceIntentionsConfigEntry)
|
|
|
|
for _, src := range entry.Sources {
|
|
|
|
results = append(results, entry.ToIntention(src))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return results
|
|
|
|
}
|