2017-10-11 17:21:20 +00:00
|
|
|
package vault
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
memdb "github.com/hashicorp/go-memdb"
|
|
|
|
)
|
|
|
|
|
2017-11-02 20:05:48 +00:00
|
|
|
const (
|
|
|
|
entitiesTable = "entities"
|
|
|
|
entityAliasesTable = "entity_aliases"
|
|
|
|
groupsTable = "groups"
|
|
|
|
groupAliasesTable = "group_aliases"
|
2021-09-27 17:55:29 +00:00
|
|
|
oidcClientsTable = "oidc_clients"
|
2017-11-02 20:05:48 +00:00
|
|
|
)
|
|
|
|
|
2018-10-19 19:47:26 +00:00
|
|
|
func identityStoreSchema(lowerCaseName bool) *memdb.DBSchema {
|
2017-10-11 17:21:20 +00:00
|
|
|
iStoreSchema := &memdb.DBSchema{
|
|
|
|
Tables: make(map[string]*memdb.TableSchema),
|
|
|
|
}
|
|
|
|
|
2018-10-19 19:47:26 +00:00
|
|
|
schemas := []func(bool) *memdb.TableSchema{
|
2017-11-02 20:05:48 +00:00
|
|
|
entitiesTableSchema,
|
2017-10-11 17:21:20 +00:00
|
|
|
aliasesTableSchema,
|
2017-11-02 20:05:48 +00:00
|
|
|
groupsTableSchema,
|
|
|
|
groupAliasesTableSchema,
|
2021-09-27 17:55:29 +00:00
|
|
|
oidcClientsTableSchema,
|
2017-10-11 17:21:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, schemaFunc := range schemas {
|
2018-10-19 19:47:26 +00:00
|
|
|
schema := schemaFunc(lowerCaseName)
|
2017-10-11 17:21:20 +00:00
|
|
|
if _, ok := iStoreSchema.Tables[schema.Name]; ok {
|
|
|
|
panic(fmt.Sprintf("duplicate table name: %s", schema.Name))
|
|
|
|
}
|
|
|
|
iStoreSchema.Tables[schema.Name] = schema
|
|
|
|
}
|
|
|
|
|
|
|
|
return iStoreSchema
|
|
|
|
}
|
|
|
|
|
2018-10-19 19:47:26 +00:00
|
|
|
func aliasesTableSchema(lowerCaseName bool) *memdb.TableSchema {
|
2017-10-11 17:21:20 +00:00
|
|
|
return &memdb.TableSchema{
|
2017-11-02 20:05:48 +00:00
|
|
|
Name: entityAliasesTable,
|
2017-10-11 17:21:20 +00:00
|
|
|
Indexes: map[string]*memdb.IndexSchema{
|
2021-04-08 16:43:39 +00:00
|
|
|
"id": {
|
2017-10-11 17:21:20 +00:00
|
|
|
Name: "id",
|
|
|
|
Unique: true,
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "ID",
|
|
|
|
},
|
|
|
|
},
|
2021-04-08 16:43:39 +00:00
|
|
|
"factors": {
|
2017-10-11 17:21:20 +00:00
|
|
|
Name: "factors",
|
|
|
|
Unique: true,
|
|
|
|
Indexer: &memdb.CompoundIndex{
|
|
|
|
Indexes: []memdb.Indexer{
|
|
|
|
&memdb.StringFieldIndex{
|
|
|
|
Field: "MountAccessor",
|
|
|
|
},
|
|
|
|
&memdb.StringFieldIndex{
|
2018-10-19 19:47:26 +00:00
|
|
|
Field: "Name",
|
|
|
|
Lowercase: lowerCaseName,
|
2017-10-11 17:21:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-04-08 16:43:39 +00:00
|
|
|
"namespace_id": {
|
2018-09-18 03:03:00 +00:00
|
|
|
Name: "namespace_id",
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "NamespaceID",
|
|
|
|
},
|
|
|
|
},
|
2021-10-15 19:20:00 +00:00
|
|
|
"local_bucket_key": {
|
|
|
|
Name: "local_bucket_key",
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "LocalBucketKey",
|
|
|
|
},
|
|
|
|
},
|
2017-10-11 17:21:20 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-19 19:47:26 +00:00
|
|
|
func entitiesTableSchema(lowerCaseName bool) *memdb.TableSchema {
|
2017-10-11 17:21:20 +00:00
|
|
|
return &memdb.TableSchema{
|
2017-11-02 20:05:48 +00:00
|
|
|
Name: entitiesTable,
|
2017-10-11 17:21:20 +00:00
|
|
|
Indexes: map[string]*memdb.IndexSchema{
|
2021-04-08 16:43:39 +00:00
|
|
|
"id": {
|
2017-10-11 17:21:20 +00:00
|
|
|
Name: "id",
|
|
|
|
Unique: true,
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "ID",
|
|
|
|
},
|
|
|
|
},
|
2021-04-08 16:43:39 +00:00
|
|
|
"name": {
|
2017-10-11 17:21:20 +00:00
|
|
|
Name: "name",
|
|
|
|
Unique: true,
|
2018-09-18 03:03:00 +00:00
|
|
|
Indexer: &memdb.CompoundIndex{
|
|
|
|
Indexes: []memdb.Indexer{
|
|
|
|
&memdb.StringFieldIndex{
|
|
|
|
Field: "NamespaceID",
|
|
|
|
},
|
|
|
|
&memdb.StringFieldIndex{
|
2018-10-19 19:47:26 +00:00
|
|
|
Field: "Name",
|
|
|
|
Lowercase: lowerCaseName,
|
2018-09-18 03:03:00 +00:00
|
|
|
},
|
|
|
|
},
|
2017-10-11 17:21:20 +00:00
|
|
|
},
|
|
|
|
},
|
2021-04-08 16:43:39 +00:00
|
|
|
"merged_entity_ids": {
|
2017-10-11 17:21:20 +00:00
|
|
|
Name: "merged_entity_ids",
|
|
|
|
Unique: true,
|
|
|
|
AllowMissing: true,
|
|
|
|
Indexer: &memdb.StringSliceFieldIndex{
|
|
|
|
Field: "MergedEntityIDs",
|
|
|
|
},
|
|
|
|
},
|
2021-04-08 16:43:39 +00:00
|
|
|
"bucket_key": {
|
2019-05-07 19:29:51 +00:00
|
|
|
Name: "bucket_key",
|
2017-10-11 17:21:20 +00:00
|
|
|
Indexer: &memdb.StringFieldIndex{
|
2019-05-07 19:29:51 +00:00
|
|
|
Field: "BucketKey",
|
2017-10-11 17:21:20 +00:00
|
|
|
},
|
|
|
|
},
|
2021-04-08 16:43:39 +00:00
|
|
|
"namespace_id": {
|
2018-09-18 03:03:00 +00:00
|
|
|
Name: "namespace_id",
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "NamespaceID",
|
|
|
|
},
|
|
|
|
},
|
2017-10-11 17:21:20 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-19 19:47:26 +00:00
|
|
|
func groupsTableSchema(lowerCaseName bool) *memdb.TableSchema {
|
2017-10-11 17:21:20 +00:00
|
|
|
return &memdb.TableSchema{
|
2017-11-02 20:05:48 +00:00
|
|
|
Name: groupsTable,
|
2017-10-11 17:21:20 +00:00
|
|
|
Indexes: map[string]*memdb.IndexSchema{
|
|
|
|
"id": {
|
|
|
|
Name: "id",
|
|
|
|
Unique: true,
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "ID",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"name": {
|
|
|
|
Name: "name",
|
|
|
|
Unique: true,
|
2018-09-18 03:03:00 +00:00
|
|
|
Indexer: &memdb.CompoundIndex{
|
|
|
|
Indexes: []memdb.Indexer{
|
|
|
|
&memdb.StringFieldIndex{
|
|
|
|
Field: "NamespaceID",
|
|
|
|
},
|
|
|
|
&memdb.StringFieldIndex{
|
2018-10-19 19:47:26 +00:00
|
|
|
Field: "Name",
|
|
|
|
Lowercase: lowerCaseName,
|
2018-09-18 03:03:00 +00:00
|
|
|
},
|
|
|
|
},
|
2017-10-11 17:21:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
"member_entity_ids": {
|
|
|
|
Name: "member_entity_ids",
|
|
|
|
AllowMissing: true,
|
|
|
|
Indexer: &memdb.StringSliceFieldIndex{
|
|
|
|
Field: "MemberEntityIDs",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"parent_group_ids": {
|
|
|
|
Name: "parent_group_ids",
|
|
|
|
AllowMissing: true,
|
|
|
|
Indexer: &memdb.StringSliceFieldIndex{
|
|
|
|
Field: "ParentGroupIDs",
|
|
|
|
},
|
|
|
|
},
|
2021-04-08 16:43:39 +00:00
|
|
|
"bucket_key": {
|
2019-05-07 19:29:51 +00:00
|
|
|
Name: "bucket_key",
|
2017-10-11 17:21:20 +00:00
|
|
|
Indexer: &memdb.StringFieldIndex{
|
2019-05-07 19:29:51 +00:00
|
|
|
Field: "BucketKey",
|
2017-10-11 17:21:20 +00:00
|
|
|
},
|
|
|
|
},
|
2021-04-08 16:43:39 +00:00
|
|
|
"namespace_id": {
|
2018-09-18 03:03:00 +00:00
|
|
|
Name: "namespace_id",
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "NamespaceID",
|
|
|
|
},
|
|
|
|
},
|
2017-10-11 17:21:20 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2017-11-02 20:05:48 +00:00
|
|
|
|
2018-10-19 19:47:26 +00:00
|
|
|
func groupAliasesTableSchema(lowerCaseName bool) *memdb.TableSchema {
|
2017-11-02 20:05:48 +00:00
|
|
|
return &memdb.TableSchema{
|
|
|
|
Name: groupAliasesTable,
|
|
|
|
Indexes: map[string]*memdb.IndexSchema{
|
2021-04-08 16:43:39 +00:00
|
|
|
"id": {
|
2017-11-02 20:05:48 +00:00
|
|
|
Name: "id",
|
|
|
|
Unique: true,
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "ID",
|
|
|
|
},
|
|
|
|
},
|
2021-04-08 16:43:39 +00:00
|
|
|
"factors": {
|
2017-11-02 20:05:48 +00:00
|
|
|
Name: "factors",
|
|
|
|
Unique: true,
|
|
|
|
Indexer: &memdb.CompoundIndex{
|
|
|
|
Indexes: []memdb.Indexer{
|
|
|
|
&memdb.StringFieldIndex{
|
|
|
|
Field: "MountAccessor",
|
|
|
|
},
|
|
|
|
&memdb.StringFieldIndex{
|
2018-10-19 19:47:26 +00:00
|
|
|
Field: "Name",
|
|
|
|
Lowercase: lowerCaseName,
|
2017-11-02 20:05:48 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-04-08 16:43:39 +00:00
|
|
|
"namespace_id": {
|
2018-09-18 03:03:00 +00:00
|
|
|
Name: "namespace_id",
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "NamespaceID",
|
|
|
|
},
|
|
|
|
},
|
2017-11-02 20:05:48 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2021-09-27 17:55:29 +00:00
|
|
|
|
|
|
|
func oidcClientsTableSchema(_ bool) *memdb.TableSchema {
|
|
|
|
return &memdb.TableSchema{
|
|
|
|
Name: oidcClientsTable,
|
|
|
|
Indexes: map[string]*memdb.IndexSchema{
|
|
|
|
"id": {
|
|
|
|
Name: "id",
|
|
|
|
Unique: true,
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "ClientID",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"name": {
|
|
|
|
Name: "name",
|
|
|
|
Unique: true,
|
|
|
|
Indexer: &memdb.CompoundIndex{
|
|
|
|
Indexes: []memdb.Indexer{
|
|
|
|
&memdb.StringFieldIndex{
|
|
|
|
Field: "NamespaceID",
|
|
|
|
},
|
|
|
|
&memdb.StringFieldIndex{
|
|
|
|
Field: "Name",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"namespace_id": {
|
|
|
|
Name: "namespace_id",
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "NamespaceID",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|