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"
|
|
|
|
)
|
|
|
|
|
2017-10-11 17:21:20 +00:00
|
|
|
func identityStoreSchema() *memdb.DBSchema {
|
|
|
|
iStoreSchema := &memdb.DBSchema{
|
|
|
|
Tables: make(map[string]*memdb.TableSchema),
|
|
|
|
}
|
|
|
|
|
|
|
|
schemas := []func() *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,
|
2017-10-11 17:21:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, schemaFunc := range schemas {
|
|
|
|
schema := schemaFunc()
|
|
|
|
if _, ok := iStoreSchema.Tables[schema.Name]; ok {
|
|
|
|
panic(fmt.Sprintf("duplicate table name: %s", schema.Name))
|
|
|
|
}
|
|
|
|
iStoreSchema.Tables[schema.Name] = schema
|
|
|
|
}
|
|
|
|
|
|
|
|
return iStoreSchema
|
|
|
|
}
|
|
|
|
|
|
|
|
func aliasesTableSchema() *memdb.TableSchema {
|
|
|
|
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{
|
|
|
|
"id": &memdb.IndexSchema{
|
|
|
|
Name: "id",
|
|
|
|
Unique: true,
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "ID",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"factors": &memdb.IndexSchema{
|
|
|
|
Name: "factors",
|
|
|
|
Unique: true,
|
|
|
|
Indexer: &memdb.CompoundIndex{
|
|
|
|
Indexes: []memdb.Indexer{
|
|
|
|
&memdb.StringFieldIndex{
|
|
|
|
Field: "MountAccessor",
|
|
|
|
},
|
|
|
|
&memdb.StringFieldIndex{
|
|
|
|
Field: "Name",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-02 20:05:48 +00:00
|
|
|
func entitiesTableSchema() *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{
|
|
|
|
"id": &memdb.IndexSchema{
|
|
|
|
Name: "id",
|
|
|
|
Unique: true,
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "ID",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"name": &memdb.IndexSchema{
|
|
|
|
Name: "name",
|
|
|
|
Unique: true,
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "Name",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"merged_entity_ids": &memdb.IndexSchema{
|
|
|
|
Name: "merged_entity_ids",
|
|
|
|
Unique: true,
|
|
|
|
AllowMissing: true,
|
|
|
|
Indexer: &memdb.StringSliceFieldIndex{
|
|
|
|
Field: "MergedEntityIDs",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"bucket_key_hash": &memdb.IndexSchema{
|
|
|
|
Name: "bucket_key_hash",
|
|
|
|
Unique: false,
|
|
|
|
AllowMissing: false,
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "BucketKeyHash",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-02 20:05:48 +00:00
|
|
|
func groupsTableSchema() *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,
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "Name",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"member_entity_ids": {
|
|
|
|
Name: "member_entity_ids",
|
|
|
|
Unique: false,
|
|
|
|
AllowMissing: true,
|
|
|
|
Indexer: &memdb.StringSliceFieldIndex{
|
|
|
|
Field: "MemberEntityIDs",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"parent_group_ids": {
|
|
|
|
Name: "parent_group_ids",
|
|
|
|
Unique: false,
|
|
|
|
AllowMissing: true,
|
|
|
|
Indexer: &memdb.StringSliceFieldIndex{
|
|
|
|
Field: "ParentGroupIDs",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"bucket_key_hash": &memdb.IndexSchema{
|
|
|
|
Name: "bucket_key_hash",
|
|
|
|
Unique: false,
|
|
|
|
AllowMissing: false,
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "BucketKeyHash",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2017-11-02 20:05:48 +00:00
|
|
|
|
|
|
|
func groupAliasesTableSchema() *memdb.TableSchema {
|
|
|
|
return &memdb.TableSchema{
|
|
|
|
Name: groupAliasesTable,
|
|
|
|
Indexes: map[string]*memdb.IndexSchema{
|
|
|
|
"id": &memdb.IndexSchema{
|
|
|
|
Name: "id",
|
|
|
|
Unique: true,
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "ID",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"factors": &memdb.IndexSchema{
|
|
|
|
Name: "factors",
|
|
|
|
Unique: true,
|
|
|
|
Indexer: &memdb.CompoundIndex{
|
|
|
|
Indexes: []memdb.Indexer{
|
|
|
|
&memdb.StringFieldIndex{
|
|
|
|
Field: "MountAccessor",
|
|
|
|
},
|
|
|
|
&memdb.StringFieldIndex{
|
|
|
|
Field: "Name",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|