2020-01-24 15:04:58 +00:00
|
|
|
// +build !consulent
|
|
|
|
|
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
|
|
|
memdb "github.com/hashicorp/go-memdb"
|
|
|
|
)
|
|
|
|
|
|
|
|
// configTableSchema returns a new table schema used to store global
|
|
|
|
// config entries.
|
|
|
|
func configTableSchema() *memdb.TableSchema {
|
|
|
|
return &memdb.TableSchema{
|
|
|
|
Name: configTableName,
|
|
|
|
Indexes: map[string]*memdb.IndexSchema{
|
2020-06-16 17:19:31 +00:00
|
|
|
"id": {
|
2020-01-24 15:04:58 +00:00
|
|
|
Name: "id",
|
|
|
|
AllowMissing: false,
|
|
|
|
Unique: true,
|
|
|
|
Indexer: &memdb.CompoundIndex{
|
|
|
|
Indexes: []memdb.Indexer{
|
|
|
|
&memdb.StringFieldIndex{
|
|
|
|
Field: "Kind",
|
|
|
|
Lowercase: true,
|
|
|
|
},
|
|
|
|
&memdb.StringFieldIndex{
|
|
|
|
Field: "Name",
|
|
|
|
Lowercase: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"kind": {
|
2020-01-24 15:04:58 +00:00
|
|
|
Name: "kind",
|
|
|
|
AllowMissing: false,
|
|
|
|
Unique: false,
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "Kind",
|
|
|
|
Lowercase: true,
|
|
|
|
},
|
|
|
|
},
|
2020-06-16 17:19:31 +00:00
|
|
|
"link": {
|
2020-01-24 15:04:58 +00:00
|
|
|
Name: "link",
|
|
|
|
AllowMissing: true,
|
|
|
|
Unique: false,
|
|
|
|
Indexer: &ConfigEntryLinkIndex{},
|
|
|
|
},
|
2020-10-06 18:24:05 +00:00
|
|
|
"intention-legacy-id": {
|
|
|
|
Name: "intention-legacy-id",
|
|
|
|
AllowMissing: true,
|
|
|
|
Unique: true,
|
|
|
|
Indexer: &ServiceIntentionLegacyIDIndex{},
|
|
|
|
},
|
|
|
|
"intention-source": {
|
|
|
|
Name: "intention-source",
|
|
|
|
AllowMissing: true,
|
|
|
|
Unique: false,
|
|
|
|
Indexer: &ServiceIntentionSourceIndex{},
|
|
|
|
},
|
2020-01-24 15:04:58 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-11 20:31:23 +00:00
|
|
|
func firstConfigEntryWithTxn(tx ReadTxn, kind, name string, _ *structs.EnterpriseMeta) (interface{}, error) {
|
2020-01-24 15:04:58 +00:00
|
|
|
return tx.First(configTableName, "id", kind, name)
|
|
|
|
}
|
|
|
|
|
2020-08-11 20:31:23 +00:00
|
|
|
func firstWatchConfigEntryWithTxn(
|
|
|
|
tx ReadTxn,
|
|
|
|
kind string,
|
|
|
|
name string,
|
|
|
|
_ *structs.EnterpriseMeta,
|
|
|
|
) (<-chan struct{}, interface{}, error) {
|
2020-01-24 15:04:58 +00:00
|
|
|
return tx.FirstWatch(configTableName, "id", kind, name)
|
|
|
|
}
|
|
|
|
|
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) {
|
2020-01-24 15:04:58 +00:00
|
|
|
return tx.Get(configTableName, "id")
|
|
|
|
}
|
|
|
|
|
2020-08-11 20:31:23 +00:00
|
|
|
func getConfigEntryKindsWithTxn(tx ReadTxn, kind string, _ *structs.EnterpriseMeta) (memdb.ResultIterator, error) {
|
2020-01-24 15:04:58 +00:00
|
|
|
return tx.Get(configTableName, "kind", kind)
|
|
|
|
}
|
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
|
|
|
|
}
|