state: use constants for acl-roles table and indexes
This commit is contained in:
parent
90ad52575f
commit
6bc2c0e1ce
|
@ -237,7 +237,7 @@ func (s *Restore) ACLPolicy(policy *structs.ACLPolicy) error {
|
|||
|
||||
// ACLRoles is used when saving a snapshot
|
||||
func (s *Snapshot) ACLRoles() (memdb.ResultIterator, error) {
|
||||
iter, err := s.tx.Get("acl-roles", "id")
|
||||
iter, err := s.tx.Get(tableACLRoles, indexID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -1440,7 +1440,7 @@ func (s *Store) ACLRoleBatchGet(ws memdb.WatchSet, ids []string) (uint64, struct
|
|||
}
|
||||
}
|
||||
|
||||
idx := maxIndexTxn(tx, "acl-roles")
|
||||
idx := maxIndexTxn(tx, tableACLRoles)
|
||||
|
||||
return idx, roles, nil
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ func aclChangeUnsubscribeEvent(tx ReadTxn, changes Changes) ([]stream.Event, err
|
|||
token := changeObject(change).(*structs.ACLToken)
|
||||
secretIDs = append(secretIDs, token.SecretID)
|
||||
|
||||
case "acl-roles":
|
||||
case tableACLRoles:
|
||||
role := changeObject(change).(*structs.ACLRole)
|
||||
tokens, err := aclTokenListByRole(tx, role.ID, &role.EnterpriseMeta)
|
||||
if err != nil {
|
||||
|
|
|
@ -144,48 +144,48 @@ func (s *Store) ACLTokenUpsertValidateEnterprise(token *structs.ACLToken, existi
|
|||
|
||||
func aclRoleInsert(tx *txn, role *structs.ACLRole) error {
|
||||
// insert the role into memdb
|
||||
if err := tx.Insert("acl-roles", role); err != nil {
|
||||
if err := tx.Insert(tableACLRoles, role); err != nil {
|
||||
return fmt.Errorf("failed inserting acl role: %v", err)
|
||||
}
|
||||
|
||||
// update the overall acl-roles index
|
||||
if err := indexUpdateMaxTxn(tx, role.ModifyIndex, "acl-roles"); err != nil {
|
||||
if err := indexUpdateMaxTxn(tx, role.ModifyIndex, tableACLRoles); err != nil {
|
||||
return fmt.Errorf("failed updating acl roles index: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func aclRoleGetByID(tx ReadTxn, id string, _ *structs.EnterpriseMeta) (<-chan struct{}, interface{}, error) {
|
||||
return tx.FirstWatch("acl-roles", "id", id)
|
||||
return tx.FirstWatch(tableACLRoles, indexID, id)
|
||||
}
|
||||
|
||||
func aclRoleGetByName(tx ReadTxn, name string, _ *structs.EnterpriseMeta) (<-chan struct{}, interface{}, error) {
|
||||
return tx.FirstWatch("acl-roles", "name", name)
|
||||
return tx.FirstWatch(tableACLRoles, indexName, name)
|
||||
}
|
||||
|
||||
func aclRoleList(tx ReadTxn, _ *structs.EnterpriseMeta) (memdb.ResultIterator, error) {
|
||||
return tx.Get("acl-roles", "id")
|
||||
return tx.Get(tableACLRoles, indexID)
|
||||
}
|
||||
|
||||
func aclRoleListByPolicy(tx ReadTxn, policy string, _ *structs.EnterpriseMeta) (memdb.ResultIterator, error) {
|
||||
return tx.Get("acl-roles", "policies", policy)
|
||||
return tx.Get(tableACLRoles, indexPolicies, policy)
|
||||
}
|
||||
|
||||
func aclRoleDeleteWithRole(tx *txn, role *structs.ACLRole, idx uint64) error {
|
||||
// remove the role
|
||||
if err := tx.Delete("acl-roles", role); err != nil {
|
||||
if err := tx.Delete(tableACLRoles, role); err != nil {
|
||||
return fmt.Errorf("failed deleting acl role: %v", err)
|
||||
}
|
||||
|
||||
// update the overall acl-roles index
|
||||
if err := indexUpdateMaxTxn(tx, idx, "acl-roles"); err != nil {
|
||||
if err := indexUpdateMaxTxn(tx, idx, tableACLRoles); err != nil {
|
||||
return fmt.Errorf("failed updating acl policies index: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func aclRoleMaxIndex(tx ReadTxn, _ *structs.ACLRole, _ *structs.EnterpriseMeta) uint64 {
|
||||
return maxIndexTxn(tx, "acl-roles")
|
||||
return maxIndexTxn(tx, tableACLRoles)
|
||||
}
|
||||
|
||||
func aclRoleUpsertValidateEnterprise(tx *txn, role *structs.ACLRole, existing *structs.ACLRole) error {
|
||||
|
|
|
@ -4082,7 +4082,7 @@ func TestStateStore_ACLRoles_Snapshot_Restore(t *testing.T) {
|
|||
require.NoError(t, err)
|
||||
require.Equal(t, uint64(2), idx)
|
||||
require.ElementsMatch(t, roles, res)
|
||||
require.Equal(t, uint64(2), s.maxIndex("acl-roles"))
|
||||
require.Equal(t, uint64(2), s.maxIndex(tableACLRoles))
|
||||
}()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue