From 6bc2c0e1cea48d5498cad3c076f519757ca31837 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Tue, 16 Mar 2021 16:39:22 -0400 Subject: [PATCH] state: use constants for acl-roles table and indexes --- agent/consul/state/acl.go | 4 ++-- agent/consul/state/acl_events.go | 2 +- agent/consul/state/acl_oss.go | 18 +++++++++--------- agent/consul/state/acl_test.go | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/agent/consul/state/acl.go b/agent/consul/state/acl.go index 811bfe3ff..bebe9996c 100644 --- a/agent/consul/state/acl.go +++ b/agent/consul/state/acl.go @@ -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 } diff --git a/agent/consul/state/acl_events.go b/agent/consul/state/acl_events.go index f6a959a97..aea61ae54 100644 --- a/agent/consul/state/acl_events.go +++ b/agent/consul/state/acl_events.go @@ -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 { diff --git a/agent/consul/state/acl_oss.go b/agent/consul/state/acl_oss.go index b4a63e6b5..f53c5bd50 100644 --- a/agent/consul/state/acl_oss.go +++ b/agent/consul/state/acl_oss.go @@ -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 { diff --git a/agent/consul/state/acl_test.go b/agent/consul/state/acl_test.go index 3f3f21019..71d7cdd21 100644 --- a/agent/consul/state/acl_test.go +++ b/agent/consul/state/acl_test.go @@ -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)) }() }