From 05bc5cf97325fb1c100c79174c01194c5cb3e6e6 Mon Sep 17 00:00:00 2001 From: Alejandro Ruiz Date: Thu, 18 Jul 2024 17:55:09 +0200 Subject: [PATCH] misc: rename fields --- pkg/accesscontrol/access_store.go | 22 +++++++++++----------- pkg/accesscontrol/access_store_test.go | 20 ++++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/pkg/accesscontrol/access_store.go b/pkg/accesscontrol/access_store.go index b0f3ec2f..ffe48326 100644 --- a/pkg/accesscontrol/access_store.go +++ b/pkg/accesscontrol/access_store.go @@ -32,10 +32,10 @@ type roleRevisions interface { } type AccessStore struct { - users policyRules - groups policyRules - roles roleRevisions - cache *cache.LRUExpireCache + usersPolicyRules policyRules + groupsPolicyRules policyRules + roles roleRevisions + cache *cache.LRUExpireCache } type roleKey struct { @@ -45,9 +45,9 @@ type roleKey struct { func NewAccessStore(ctx context.Context, cacheResults bool, rbac v1.Interface) *AccessStore { as := &AccessStore{ - users: newPolicyRuleIndex(true, rbac), - groups: newPolicyRuleIndex(false, rbac), - roles: newRoleRevision(ctx, rbac), + usersPolicyRules: newPolicyRuleIndex(true, rbac), + groupsPolicyRules: newPolicyRuleIndex(false, rbac), + roles: newRoleRevision(ctx, rbac), } if cacheResults { as.cache = cache.NewLRUExpireCache(50) @@ -66,9 +66,9 @@ func (l *AccessStore) AccessFor(user user.Info) *AccessSet { } } - result := l.users.get(user.GetName()) + result := l.usersPolicyRules.get(user.GetName()) for _, group := range user.GetGroups() { - result.Merge(l.groups.get(group)) + result.Merge(l.groupsPolicyRules.get(group)) } if l.cache != nil { @@ -91,9 +91,9 @@ func (l *AccessStore) CacheKey(user user.Info) string { copy(groups, groupBase) sort.Strings(groups) - l.addRolesToHash(d, user.GetName(), l.users) + l.addRolesToHash(d, user.GetName(), l.usersPolicyRules) for _, group := range groups { - l.addRolesToHash(d, group, l.groups) + l.addRolesToHash(d, group, l.groupsPolicyRules) } return hex.EncodeToString(d.Sum(nil)) diff --git a/pkg/accesscontrol/access_store_test.go b/pkg/accesscontrol/access_store_test.go index 42f7f5e9..25a995d3 100644 --- a/pkg/accesscontrol/access_store_test.go +++ b/pkg/accesscontrol/access_store_test.go @@ -27,7 +27,7 @@ func TestAccessStore_CacheKey(t *testing.T) { { name: "consistently produces the same value", store: &AccessStore{ - users: &policyRulesMock{ + usersPolicyRules: &policyRulesMock{ getRBFunc: func(s string) []*rbacv1.RoleBinding { return []*rbacv1.RoleBinding{ makeRB("testns", "testrb", testUser.Name, "testrole"), @@ -39,7 +39,7 @@ func TestAccessStore_CacheKey(t *testing.T) { } }, }, - groups: &policyRulesMock{}, + groupsPolicyRules: &policyRulesMock{}, roles: roleRevisionsMock(func(ns, name string) string { return fmt.Sprintf("%s%srev", ns, name) }), @@ -55,8 +55,8 @@ func TestAccessStore_CacheKey(t *testing.T) { { name: "group permissions are taken into account", store: &AccessStore{ - users: &policyRulesMock{}, - groups: &policyRulesMock{ + usersPolicyRules: &policyRulesMock{}, + groupsPolicyRules: &policyRulesMock{ getRBFunc: func(s string) []*rbacv1.RoleBinding { return []*rbacv1.RoleBinding{ makeRB("testns", "testrb", testUser.Name, "testrole"), @@ -85,8 +85,8 @@ func TestAccessStore_CacheKey(t *testing.T) { { name: "different groups order produces the same value", store: &AccessStore{ - users: &policyRulesMock{}, - groups: &policyRulesMock{ + usersPolicyRules: &policyRulesMock{}, + groupsPolicyRules: &policyRulesMock{ getRBFunc: func(s string) []*rbacv1.RoleBinding { if s == testUser.Groups[0] { return []*rbacv1.RoleBinding{ @@ -121,14 +121,14 @@ func TestAccessStore_CacheKey(t *testing.T) { { name: "role changes produce a different value", store: &AccessStore{ - users: &policyRulesMock{ + usersPolicyRules: &policyRulesMock{ getRBFunc: func(s string) []*rbacv1.RoleBinding { return []*rbacv1.RoleBinding{ makeRB("testns", "testrb", testUser.Name, "testrole"), } }, }, - groups: &policyRulesMock{}, + groupsPolicyRules: &policyRulesMock{}, roles: roleRevisionsMock(func(ns, name string) string { return "rev1" }), @@ -146,8 +146,8 @@ func TestAccessStore_CacheKey(t *testing.T) { { name: "new groups produce a different value", store: &AccessStore{ - users: &policyRulesMock{}, - groups: &policyRulesMock{ + usersPolicyRules: &policyRulesMock{}, + groupsPolicyRules: &policyRulesMock{ getRBFunc: func(s string) []*rbacv1.RoleBinding { return []*rbacv1.RoleBinding{ makeRB("testns", "testrb", testUser.Name, "testrole"),