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"
|
|
|
|
|
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) {
|
|
|
|
case *structs.EnterpriseMeta:
|
|
|
|
return nil, nil
|
|
|
|
case structs.EnterpriseMeta:
|
|
|
|
return b.Bytes(), nil
|
|
|
|
case ConfigEntryKindQuery:
|
|
|
|
b.String(strings.ToLower(n.Kind))
|
|
|
|
return b.Bytes(), nil
|
|
|
|
case ConfigEntryKindName:
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-08-11 20:31:23 +00:00
|
|
|
func getAllConfigEntriesWithTxn(tx ReadTxn, _ *structs.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)
|
|
|
|
}
|
|
|
|
|
2020-08-11 20:31:23 +00:00
|
|
|
func getConfigEntryKindsWithTxn(tx ReadTxn, kind string, _ *structs.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
|
|
|
|
|
|
|
func configIntentionsConvertToList(iter memdb.ResultIterator, _ *structs.EnterpriseMeta) structs.Intentions {
|
|
|
|
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
|
|
|
|
}
|