Skip to content

Commit

Permalink
misc: rename fields
Browse files Browse the repository at this point in the history
  • Loading branch information
aruiz14 committed Jul 18, 2024
1 parent 234a949 commit 05bc5cf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
22 changes: 11 additions & 11 deletions pkg/accesscontrol/access_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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 {
Expand All @@ -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))
Expand Down
20 changes: 10 additions & 10 deletions pkg/accesscontrol/access_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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)
}),
Expand All @@ -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"),
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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"
}),
Expand All @@ -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"),
Expand Down

0 comments on commit 05bc5cf

Please sign in to comment.