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) {
|
|
|
|
n, ok := arg.(ConfigEntryKindName)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("invalid type for ConfigEntryKindName query: %T", arg)
|
|
|
|
}
|
|
|
|
|
|
|
|
var b indexBuilder
|
|
|
|
b.String(strings.ToLower(n.Kind))
|
|
|
|
b.String(strings.ToLower(n.Name))
|
|
|
|
return b.Bytes(), nil
|
2020-01-24 15:04:58 +00:00
|
|
|
}
|
|
|
|
|
2021-02-09 17:37:57 +00:00
|
|
|
func indexFromConfigEntry(raw interface{}) ([]byte, error) {
|
|
|
|
c, ok := raw.(structs.ConfigEntry)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("type must be structs.ConfigEntry: %T", raw)
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.GetName() == "" || c.GetKind() == "" {
|
|
|
|
return nil, errMissingValueForIndex
|
|
|
|
}
|
|
|
|
|
|
|
|
var b indexBuilder
|
|
|
|
b.String(strings.ToLower(c.GetKind()))
|
|
|
|
b.String(strings.ToLower(c.GetName()))
|
|
|
|
return b.Bytes(), nil
|
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
|
|
|
}
|
|
|
|
|
2020-08-11 20:31:23 +00:00
|
|
|
func getConfigEntryKindsWithTxn(tx ReadTxn, kind string, _ *structs.EnterpriseMeta) (memdb.ResultIterator, error) {
|
2021-03-10 18:37:17 +00:00
|
|
|
return tx.Get(tableConfigEntries, indexKind, 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
|
|
|
|
}
|