Skip to content

Commit

Permalink
feat: add error to some of the APIs (#1389)
Browse files Browse the repository at this point in the history
* fix: add nil checks

* fix: lint

* fix: return error at anywhere assertion not found

* fix: lint

* fix: test

* fix: format
  • Loading branch information
MuZhou233 committed May 7, 2024
1 parent 44b890d commit 65cce21
Show file tree
Hide file tree
Showing 16 changed files with 396 additions and 190 deletions.
56 changes: 37 additions & 19 deletions enforcer_distributed.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,25 @@ func (d *DistributedEnforcer) AddPoliciesSelf(shouldPersist func() bool, sec str
if shouldPersist != nil && shouldPersist() {
var noExistsPolicy [][]string
for _, rule := range rules {
if !d.model.HasPolicy(sec, ptype, rule) {
var hasPolicy bool
hasPolicy, err = d.model.HasPolicy(sec, ptype, rule)
if err != nil {
return nil, err
}
if !hasPolicy {
noExistsPolicy = append(noExistsPolicy, rule)
}
}

if err := d.adapter.(persist.BatchAdapter).AddPolicies(sec, ptype, noExistsPolicy); err != nil {
if err.Error() != notImplemented {
return nil, err
}
if err = d.adapter.(persist.BatchAdapter).AddPolicies(sec, ptype, noExistsPolicy); err != nil && err.Error() != notImplemented {
return nil, err
}
}

affected = d.model.AddPoliciesWithAffected(sec, ptype, rules)
affected, err = d.model.AddPoliciesWithAffected(sec, ptype, rules)
if err != nil {
return affected, err
}

if sec == "g" {
err := d.BuildIncrementalRoleLinks(model.PolicyAdd, ptype, affected)
Expand All @@ -71,7 +77,10 @@ func (d *DistributedEnforcer) RemovePoliciesSelf(shouldPersist func() bool, sec
}
}

affected = d.model.RemovePoliciesWithAffected(sec, ptype, rules)
affected, err = d.model.RemovePoliciesWithAffected(sec, ptype, rules)
if err != nil {
return affected, err
}

if sec == "g" {
err = d.BuildIncrementalRoleLinks(model.PolicyRemove, ptype, affected)
Expand All @@ -89,14 +98,17 @@ func (d *DistributedEnforcer) RemoveFilteredPolicySelf(shouldPersist func() bool
d.m.Lock()
defer d.m.Unlock()
if shouldPersist != nil && shouldPersist() {
if err := d.adapter.RemoveFilteredPolicy(sec, ptype, fieldIndex, fieldValues...); err != nil {
if err = d.adapter.RemoveFilteredPolicy(sec, ptype, fieldIndex, fieldValues...); err != nil {
if err.Error() != notImplemented {
return nil, err
}
}
}

_, affected = d.model.RemoveFilteredPolicy(sec, ptype, fieldIndex, fieldValues...)
_, affected, err = d.model.RemoveFilteredPolicy(sec, ptype, fieldIndex, fieldValues...)
if err != nil {
return affected, err
}

if sec == "g" {
err := d.BuildIncrementalRoleLinks(model.PolicyRemove, ptype, affected)
Expand Down Expand Up @@ -129,15 +141,15 @@ func (d *DistributedEnforcer) UpdatePolicySelf(shouldPersist func() bool, sec st
d.m.Lock()
defer d.m.Unlock()
if shouldPersist != nil && shouldPersist() {
err := d.adapter.(persist.UpdatableAdapter).UpdatePolicy(sec, ptype, oldRule, newRule)
err = d.adapter.(persist.UpdatableAdapter).UpdatePolicy(sec, ptype, oldRule, newRule)
if err != nil {
return false, err
}
}

ruleUpdated := d.model.UpdatePolicy(sec, ptype, oldRule, newRule)
if !ruleUpdated {
return ruleUpdated, nil
ruleUpdated, err := d.model.UpdatePolicy(sec, ptype, oldRule, newRule)
if !ruleUpdated || err != nil {
return ruleUpdated, err
}

if sec == "g" {
Expand All @@ -159,15 +171,15 @@ func (d *DistributedEnforcer) UpdatePoliciesSelf(shouldPersist func() bool, sec
d.m.Lock()
defer d.m.Unlock()
if shouldPersist != nil && shouldPersist() {
err := d.adapter.(persist.UpdatableAdapter).UpdatePolicies(sec, ptype, oldRules, newRules)
err = d.adapter.(persist.UpdatableAdapter).UpdatePolicies(sec, ptype, oldRules, newRules)
if err != nil {
return false, err
}
}

ruleUpdated := d.model.UpdatePolicies(sec, ptype, oldRules, newRules)
if !ruleUpdated {
return ruleUpdated, nil
ruleUpdated, err := d.model.UpdatePolicies(sec, ptype, oldRules, newRules)
if !ruleUpdated || err != nil {
return ruleUpdated, err
}

if sec == "g" {
Expand Down Expand Up @@ -199,8 +211,14 @@ func (d *DistributedEnforcer) UpdateFilteredPoliciesSelf(shouldPersist func() bo
}
}

ruleChanged := !d.model.RemovePolicies(sec, ptype, oldRules)
d.model.AddPolicies(sec, ptype, newRules)
ruleChanged, err := d.model.RemovePolicies(sec, ptype, oldRules)
if err != nil {
return ruleChanged, err
}
err = d.model.AddPolicies(sec, ptype, newRules)
if err != nil {
return ruleChanged, err
}
ruleChanged = ruleChanged && len(newRules) != 0
if !ruleChanged {
return ruleChanged, nil
Expand Down
46 changes: 23 additions & 23 deletions enforcer_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type IEnforcer interface {
DeletePermissionForUser(user string, permission ...string) (bool, error)
DeletePermissionsForUser(user string) (bool, error)
GetPermissionsForUser(user string, domain ...string) ([][]string, error)
HasPermissionForUser(user string, permission ...string) bool
HasPermissionForUser(user string, permission ...string) (bool, error)
GetImplicitRolesForUser(name string, domain ...string) ([]string, error)
GetImplicitPermissionsForUser(user string, domain ...string) ([][]string, error)
GetImplicitUsersForPermission(permission ...string) ([]string, error)
Expand All @@ -86,32 +86,32 @@ type IEnforcer interface {
GetPermissionsForUserInDomain(user string, domain string) [][]string
AddRoleForUserInDomain(user string, role string, domain string) (bool, error)
DeleteRoleForUserInDomain(user string, role string, domain string) (bool, error)
GetAllUsersByDomain(domain string) []string
GetAllUsersByDomain(domain string) ([]string, error)
DeleteRolesForUserInDomain(user string, domain string) (bool, error)
DeleteAllUsersByDomain(domain string) (bool, error)
DeleteDomains(domains ...string) (bool, error)
GetAllDomains() ([]string, error)
GetAllRolesByDomain(domain string) []string
GetAllRolesByDomain(domain string) ([]string, error)

/* Management API */
GetAllSubjects() []string
GetAllNamedSubjects(ptype string) []string
GetAllObjects() []string
GetAllNamedObjects(ptype string) []string
GetAllActions() []string
GetAllNamedActions(ptype string) []string
GetAllRoles() []string
GetAllNamedRoles(ptype string) []string
GetPolicy() [][]string
GetFilteredPolicy(fieldIndex int, fieldValues ...string) [][]string
GetNamedPolicy(ptype string) [][]string
GetFilteredNamedPolicy(ptype string, fieldIndex int, fieldValues ...string) [][]string
GetGroupingPolicy() [][]string
GetFilteredGroupingPolicy(fieldIndex int, fieldValues ...string) [][]string
GetNamedGroupingPolicy(ptype string) [][]string
GetFilteredNamedGroupingPolicy(ptype string, fieldIndex int, fieldValues ...string) [][]string
HasPolicy(params ...interface{}) bool
HasNamedPolicy(ptype string, params ...interface{}) bool
GetAllSubjects() ([]string, error)
GetAllNamedSubjects(ptype string) ([]string, error)
GetAllObjects() ([]string, error)
GetAllNamedObjects(ptype string) ([]string, error)
GetAllActions() ([]string, error)
GetAllNamedActions(ptype string) ([]string, error)
GetAllRoles() ([]string, error)
GetAllNamedRoles(ptype string) ([]string, error)
GetPolicy() ([][]string, error)
GetFilteredPolicy(fieldIndex int, fieldValues ...string) ([][]string, error)
GetNamedPolicy(ptype string) ([][]string, error)
GetFilteredNamedPolicy(ptype string, fieldIndex int, fieldValues ...string) ([][]string, error)
GetGroupingPolicy() ([][]string, error)
GetFilteredGroupingPolicy(fieldIndex int, fieldValues ...string) ([][]string, error)
GetNamedGroupingPolicy(ptype string) ([][]string, error)
GetFilteredNamedGroupingPolicy(ptype string, fieldIndex int, fieldValues ...string) ([][]string, error)
HasPolicy(params ...interface{}) (bool, error)
HasNamedPolicy(ptype string, params ...interface{}) (bool, error)
AddPolicy(params ...interface{}) (bool, error)
AddPolicies(rules [][]string) (bool, error)
AddNamedPolicy(ptype string, params ...interface{}) (bool, error)
Expand All @@ -124,8 +124,8 @@ type IEnforcer interface {
RemoveNamedPolicy(ptype string, params ...interface{}) (bool, error)
RemoveNamedPolicies(ptype string, rules [][]string) (bool, error)
RemoveFilteredNamedPolicy(ptype string, fieldIndex int, fieldValues ...string) (bool, error)
HasGroupingPolicy(params ...interface{}) bool
HasNamedGroupingPolicy(ptype string, params ...interface{}) bool
HasGroupingPolicy(params ...interface{}) (bool, error)
HasNamedGroupingPolicy(ptype string, params ...interface{}) (bool, error)
AddGroupingPolicy(params ...interface{}) (bool, error)
AddGroupingPolicies(rules [][]string) (bool, error)
AddGroupingPoliciesEx(rules [][]string) (bool, error)
Expand Down
40 changes: 20 additions & 20 deletions enforcer_synced.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,126 +233,126 @@ func (e *SyncedEnforcer) BatchEnforceWithMatcher(matcher string, requests [][]in
}

// GetAllSubjects gets the list of subjects that show up in the current policy.
func (e *SyncedEnforcer) GetAllSubjects() []string {
func (e *SyncedEnforcer) GetAllSubjects() ([]string, error) {
e.m.RLock()
defer e.m.RUnlock()
return e.Enforcer.GetAllSubjects()
}

// GetAllNamedSubjects gets the list of subjects that show up in the current named policy.
func (e *SyncedEnforcer) GetAllNamedSubjects(ptype string) []string {
func (e *SyncedEnforcer) GetAllNamedSubjects(ptype string) ([]string, error) {
e.m.RLock()
defer e.m.RUnlock()
return e.Enforcer.GetAllNamedSubjects(ptype)
}

// GetAllObjects gets the list of objects that show up in the current policy.
func (e *SyncedEnforcer) GetAllObjects() []string {
func (e *SyncedEnforcer) GetAllObjects() ([]string, error) {
e.m.RLock()
defer e.m.RUnlock()
return e.Enforcer.GetAllObjects()
}

// GetAllNamedObjects gets the list of objects that show up in the current named policy.
func (e *SyncedEnforcer) GetAllNamedObjects(ptype string) []string {
func (e *SyncedEnforcer) GetAllNamedObjects(ptype string) ([]string, error) {
e.m.RLock()
defer e.m.RUnlock()
return e.Enforcer.GetAllNamedObjects(ptype)
}

// GetAllActions gets the list of actions that show up in the current policy.
func (e *SyncedEnforcer) GetAllActions() []string {
func (e *SyncedEnforcer) GetAllActions() ([]string, error) {
e.m.RLock()
defer e.m.RUnlock()
return e.Enforcer.GetAllActions()
}

// GetAllNamedActions gets the list of actions that show up in the current named policy.
func (e *SyncedEnforcer) GetAllNamedActions(ptype string) []string {
func (e *SyncedEnforcer) GetAllNamedActions(ptype string) ([]string, error) {
e.m.RLock()
defer e.m.RUnlock()
return e.Enforcer.GetAllNamedActions(ptype)
}

// GetAllRoles gets the list of roles that show up in the current policy.
func (e *SyncedEnforcer) GetAllRoles() []string {
func (e *SyncedEnforcer) GetAllRoles() ([]string, error) {
e.m.RLock()
defer e.m.RUnlock()
return e.Enforcer.GetAllRoles()
}

// GetAllNamedRoles gets the list of roles that show up in the current named policy.
func (e *SyncedEnforcer) GetAllNamedRoles(ptype string) []string {
func (e *SyncedEnforcer) GetAllNamedRoles(ptype string) ([]string, error) {
e.m.RLock()
defer e.m.RUnlock()
return e.Enforcer.GetAllNamedRoles(ptype)
}

// GetPolicy gets all the authorization rules in the policy.
func (e *SyncedEnforcer) GetPolicy() [][]string {
func (e *SyncedEnforcer) GetPolicy() ([][]string, error) {
e.m.RLock()
defer e.m.RUnlock()
return e.Enforcer.GetPolicy()
}

// GetFilteredPolicy gets all the authorization rules in the policy, field filters can be specified.
func (e *SyncedEnforcer) GetFilteredPolicy(fieldIndex int, fieldValues ...string) [][]string {
func (e *SyncedEnforcer) GetFilteredPolicy(fieldIndex int, fieldValues ...string) ([][]string, error) {
e.m.RLock()
defer e.m.RUnlock()
return e.Enforcer.GetFilteredPolicy(fieldIndex, fieldValues...)
}

// GetNamedPolicy gets all the authorization rules in the named policy.
func (e *SyncedEnforcer) GetNamedPolicy(ptype string) [][]string {
func (e *SyncedEnforcer) GetNamedPolicy(ptype string) ([][]string, error) {
e.m.RLock()
defer e.m.RUnlock()
return e.Enforcer.GetNamedPolicy(ptype)
}

// GetFilteredNamedPolicy gets all the authorization rules in the named policy, field filters can be specified.
func (e *SyncedEnforcer) GetFilteredNamedPolicy(ptype string, fieldIndex int, fieldValues ...string) [][]string {
func (e *SyncedEnforcer) GetFilteredNamedPolicy(ptype string, fieldIndex int, fieldValues ...string) ([][]string, error) {
e.m.RLock()
defer e.m.RUnlock()
return e.Enforcer.GetFilteredNamedPolicy(ptype, fieldIndex, fieldValues...)
}

// GetGroupingPolicy gets all the role inheritance rules in the policy.
func (e *SyncedEnforcer) GetGroupingPolicy() [][]string {
func (e *SyncedEnforcer) GetGroupingPolicy() ([][]string, error) {
e.m.RLock()
defer e.m.RUnlock()
return e.Enforcer.GetGroupingPolicy()
}

// GetFilteredGroupingPolicy gets all the role inheritance rules in the policy, field filters can be specified.
func (e *SyncedEnforcer) GetFilteredGroupingPolicy(fieldIndex int, fieldValues ...string) [][]string {
func (e *SyncedEnforcer) GetFilteredGroupingPolicy(fieldIndex int, fieldValues ...string) ([][]string, error) {
e.m.RLock()
defer e.m.RUnlock()
return e.Enforcer.GetFilteredGroupingPolicy(fieldIndex, fieldValues...)
}

// GetNamedGroupingPolicy gets all the role inheritance rules in the policy.
func (e *SyncedEnforcer) GetNamedGroupingPolicy(ptype string) [][]string {
func (e *SyncedEnforcer) GetNamedGroupingPolicy(ptype string) ([][]string, error) {
e.m.RLock()
defer e.m.RUnlock()
return e.Enforcer.GetNamedGroupingPolicy(ptype)
}

// GetFilteredNamedGroupingPolicy gets all the role inheritance rules in the policy, field filters can be specified.
func (e *SyncedEnforcer) GetFilteredNamedGroupingPolicy(ptype string, fieldIndex int, fieldValues ...string) [][]string {
func (e *SyncedEnforcer) GetFilteredNamedGroupingPolicy(ptype string, fieldIndex int, fieldValues ...string) ([][]string, error) {
e.m.RLock()
defer e.m.RUnlock()
return e.Enforcer.GetFilteredNamedGroupingPolicy(ptype, fieldIndex, fieldValues...)
}

// HasPolicy determines whether an authorization rule exists.
func (e *SyncedEnforcer) HasPolicy(params ...interface{}) bool {
func (e *SyncedEnforcer) HasPolicy(params ...interface{}) (bool, error) {
e.m.RLock()
defer e.m.RUnlock()
return e.Enforcer.HasPolicy(params...)
}

// HasNamedPolicy determines whether a named authorization rule exists.
func (e *SyncedEnforcer) HasNamedPolicy(ptype string, params ...interface{}) bool {
func (e *SyncedEnforcer) HasNamedPolicy(ptype string, params ...interface{}) (bool, error) {
e.m.RLock()
defer e.m.RUnlock()
return e.Enforcer.HasNamedPolicy(ptype, params...)
Expand Down Expand Up @@ -493,14 +493,14 @@ func (e *SyncedEnforcer) RemoveFilteredNamedPolicy(ptype string, fieldIndex int,
}

// HasGroupingPolicy determines whether a role inheritance rule exists.
func (e *SyncedEnforcer) HasGroupingPolicy(params ...interface{}) bool {
func (e *SyncedEnforcer) HasGroupingPolicy(params ...interface{}) (bool, error) {
e.m.RLock()
defer e.m.RUnlock()
return e.Enforcer.HasGroupingPolicy(params...)
}

// HasNamedGroupingPolicy determines whether a named role inheritance rule exists.
func (e *SyncedEnforcer) HasNamedGroupingPolicy(ptype string, params ...interface{}) bool {
func (e *SyncedEnforcer) HasNamedGroupingPolicy(ptype string, params ...interface{}) (bool, error) {
e.m.RLock()
defer e.m.RUnlock()
return e.Enforcer.HasNamedGroupingPolicy(ptype, params...)
Expand Down
5 changes: 4 additions & 1 deletion enforcer_synced_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ func TestStopAutoLoadPolicy(t *testing.T) {

func testSyncedEnforcerGetPolicy(t *testing.T, e *SyncedEnforcer, res [][]string) {
t.Helper()
myRes := e.GetPolicy()
myRes, err := e.GetPolicy()
if err != nil {
t.Error(err)
}

if !util.SortedArray2DEquals(res, myRes) {
t.Error("Policy: ", myRes, ", supposed to be ", res)
Expand Down
10 changes: 8 additions & 2 deletions frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ func CasbinJsGetPermissionForUser(e IEnforcer, user string) (string, error) {

pRules := [][]string{}
for ptype := range model["p"] {
policies := model.GetPolicy("p", ptype)
policies, err := model.GetPolicy("p", ptype)
if err != nil {
return "", err
}
for _, rules := range policies {
pRules = append(pRules, append([]string{ptype}, rules...))
}
Expand All @@ -36,7 +39,10 @@ func CasbinJsGetPermissionForUser(e IEnforcer, user string) (string, error) {

gRules := [][]string{}
for ptype := range model["g"] {
policies := model.GetPolicy("g", ptype)
policies, err := model.GetPolicy("g", ptype)
if err != nil {
return "", err
}
for _, rules := range policies {
gRules = append(gRules, append([]string{ptype}, rules...))
}
Expand Down

2 comments on commit 65cce21

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 65cce21 Previous: 44b890d Ratio
BenchmarkCachedRaw 17.55 ns/op 0 B/op 0 allocs/op 17.56 ns/op 0 B/op 0 allocs/op 1.00
BenchmarkCachedRaw - ns/op 17.55 ns/op 17.56 ns/op 1.00
BenchmarkCachedRaw - B/op 0 B/op 0 B/op 1
BenchmarkCachedRaw - allocs/op 0 allocs/op 0 allocs/op 1
BenchmarkCachedBasicModel 158.7 ns/op 104 B/op 4 allocs/op 166 ns/op 104 B/op 4 allocs/op 0.96
BenchmarkCachedBasicModel - ns/op 158.7 ns/op 166 ns/op 0.96
BenchmarkCachedBasicModel - B/op 104 B/op 104 B/op 1
BenchmarkCachedBasicModel - allocs/op 4 allocs/op 4 allocs/op 1
BenchmarkCachedRBACModel 159 ns/op 104 B/op 4 allocs/op 165.3 ns/op 104 B/op 4 allocs/op 0.96
BenchmarkCachedRBACModel - ns/op 159 ns/op 165.3 ns/op 0.96
BenchmarkCachedRBACModel - B/op 104 B/op 104 B/op 1
BenchmarkCachedRBACModel - allocs/op 4 allocs/op 4 allocs/op 1
BenchmarkCachedRBACModelSmall 179.2 ns/op 104 B/op 4 allocs/op 183.4 ns/op 104 B/op 4 allocs/op 0.98
BenchmarkCachedRBACModelSmall - ns/op 179.2 ns/op 183.4 ns/op 0.98
BenchmarkCachedRBACModelSmall - B/op 104 B/op 104 B/op 1
BenchmarkCachedRBACModelSmall - allocs/op 4 allocs/op 4 allocs/op 1
BenchmarkCachedRBACModelMedium 181.8 ns/op 104 B/op 4 allocs/op 185.5 ns/op 104 B/op 4 allocs/op 0.98
BenchmarkCachedRBACModelMedium - ns/op 181.8 ns/op 185.5 ns/op 0.98
BenchmarkCachedRBACModelMedium - B/op 104 B/op 104 B/op 1
BenchmarkCachedRBACModelMedium - allocs/op 4 allocs/op 4 allocs/op 1
BenchmarkCachedRBACModelLarge 154.4 ns/op 96 B/op 3 allocs/op 162.2 ns/op 96 B/op 3 allocs/op 0.95
BenchmarkCachedRBACModelLarge - ns/op 154.4 ns/op 162.2 ns/op 0.95
BenchmarkCachedRBACModelLarge - B/op 96 B/op 96 B/op 1
BenchmarkCachedRBACModelLarge - allocs/op 3 allocs/op 3 allocs/op 1
BenchmarkCachedRBACModelWithResourceRoles 161.8 ns/op 104 B/op 4 allocs/op 170 ns/op 104 B/op 4 allocs/op 0.95
BenchmarkCachedRBACModelWithResourceRoles - ns/op 161.8 ns/op 170 ns/op 0.95
BenchmarkCachedRBACModelWithResourceRoles - B/op 104 B/op 104 B/op 1
BenchmarkCachedRBACModelWithResourceRoles - allocs/op 4 allocs/op 4 allocs/op 1
BenchmarkCachedRBACModelWithDomains 175.2 ns/op 120 B/op 4 allocs/op 180.4 ns/op 120 B/op 4 allocs/op 0.97
BenchmarkCachedRBACModelWithDomains - ns/op 175.2 ns/op 180.4 ns/op 0.97
BenchmarkCachedRBACModelWithDomains - B/op 120 B/op 120 B/op 1
BenchmarkCachedRBACModelWithDomains - allocs/op 4 allocs/op 4 allocs/op 1
BenchmarkCachedABACModel 2685 ns/op 1537 B/op 18 allocs/op 2752 ns/op 1538 B/op 18 allocs/op 0.98
BenchmarkCachedABACModel - ns/op 2685 ns/op 2752 ns/op 0.98
BenchmarkCachedABACModel - B/op 1537 B/op 1538 B/op 1.00
BenchmarkCachedABACModel - allocs/op 18 allocs/op 18 allocs/op 1
BenchmarkCachedKeyMatchModel 174.6 ns/op 152 B/op 4 allocs/op 193.9 ns/op 152 B/op 4 allocs/op 0.90
BenchmarkCachedKeyMatchModel - ns/op 174.6 ns/op 193.9 ns/op 0.90
BenchmarkCachedKeyMatchModel - B/op 152 B/op 152 B/op 1
BenchmarkCachedKeyMatchModel - allocs/op 4 allocs/op 4 allocs/op 1
BenchmarkCachedRBACModelWithDeny 160.2 ns/op 104 B/op 4 allocs/op 171 ns/op 104 B/op 4 allocs/op 0.94
BenchmarkCachedRBACModelWithDeny - ns/op 160.2 ns/op 171 ns/op 0.94
BenchmarkCachedRBACModelWithDeny - B/op 104 B/op 104 B/op 1
BenchmarkCachedRBACModelWithDeny - allocs/op 4 allocs/op 4 allocs/op 1
BenchmarkCachedPriorityModel 161 ns/op 104 B/op 4 allocs/op 169.6 ns/op 104 B/op 4 allocs/op 0.95
BenchmarkCachedPriorityModel - ns/op 161 ns/op 169.6 ns/op 0.95
BenchmarkCachedPriorityModel - B/op 104 B/op 104 B/op 1
BenchmarkCachedPriorityModel - allocs/op 4 allocs/op 4 allocs/op 1
BenchmarkCachedWithEnforceContext 274.9 ns/op 240 B/op 5 allocs/op 303 ns/op 240 B/op 5 allocs/op 0.91
BenchmarkCachedWithEnforceContext - ns/op 274.9 ns/op 303 ns/op 0.91
BenchmarkCachedWithEnforceContext - B/op 240 B/op 240 B/op 1
BenchmarkCachedWithEnforceContext - allocs/op 5 allocs/op 5 allocs/op 1
BenchmarkCachedRBACModelMediumParallel 161.9 ns/op 106 B/op 4 allocs/op 169.2 ns/op 106 B/op 4 allocs/op 0.96
BenchmarkCachedRBACModelMediumParallel - ns/op 161.9 ns/op 169.2 ns/op 0.96
BenchmarkCachedRBACModelMediumParallel - B/op 106 B/op 106 B/op 1
BenchmarkCachedRBACModelMediumParallel - allocs/op 4 allocs/op 4 allocs/op 1
BenchmarkHasPolicySmall 514.4 ns/op 150 B/op 6 allocs/op 455.2 ns/op 150 B/op 6 allocs/op 1.13
BenchmarkHasPolicySmall - ns/op 514.4 ns/op 455.2 ns/op 1.13
BenchmarkHasPolicySmall - B/op 150 B/op 150 B/op 1
BenchmarkHasPolicySmall - allocs/op 6 allocs/op 6 allocs/op 1
BenchmarkHasPolicyMedium 533.6 ns/op 157 B/op 6 allocs/op 482.9 ns/op 157 B/op 6 allocs/op 1.10
BenchmarkHasPolicyMedium - ns/op 533.6 ns/op 482.9 ns/op 1.10
BenchmarkHasPolicyMedium - B/op 157 B/op 157 B/op 1
BenchmarkHasPolicyMedium - allocs/op 6 allocs/op 6 allocs/op 1
BenchmarkHasPolicyLarge 568.7 ns/op 165 B/op 7 allocs/op 523.8 ns/op 165 B/op 7 allocs/op 1.09
BenchmarkHasPolicyLarge - ns/op 568.7 ns/op 523.8 ns/op 1.09
BenchmarkHasPolicyLarge - B/op 165 B/op 165 B/op 1
BenchmarkHasPolicyLarge - allocs/op 7 allocs/op 7 allocs/op 1
BenchmarkAddPolicySmall 505.3 ns/op 152 B/op 6 allocs/op 464.2 ns/op 152 B/op 6 allocs/op 1.09
BenchmarkAddPolicySmall - ns/op 505.3 ns/op 464.2 ns/op 1.09
BenchmarkAddPolicySmall - B/op 152 B/op 152 B/op 1
BenchmarkAddPolicySmall - allocs/op 6 allocs/op 6 allocs/op 1
BenchmarkAddPolicyMedium 615.2 ns/op 177 B/op 7 allocs/op 577.2 ns/op 177 B/op 7 allocs/op 1.07
BenchmarkAddPolicyMedium - ns/op 615.2 ns/op 577.2 ns/op 1.07
BenchmarkAddPolicyMedium - B/op 177 B/op 177 B/op 1
BenchmarkAddPolicyMedium - allocs/op 7 allocs/op 7 allocs/op 1
BenchmarkAddPolicyLarge 1178 ns/op 470 B/op 9 allocs/op 1195 ns/op 470 B/op 9 allocs/op 0.99
BenchmarkAddPolicyLarge - ns/op 1178 ns/op 1195 ns/op 0.99
BenchmarkAddPolicyLarge - B/op 470 B/op 470 B/op 1
BenchmarkAddPolicyLarge - allocs/op 9 allocs/op 9 allocs/op 1
BenchmarkRemovePolicySmall 521.8 ns/op 166 B/op 7 allocs/op 478.2 ns/op 166 B/op 7 allocs/op 1.09
BenchmarkRemovePolicySmall - ns/op 521.8 ns/op 478.2 ns/op 1.09
BenchmarkRemovePolicySmall - B/op 166 B/op 166 B/op 1
BenchmarkRemovePolicySmall - allocs/op 7 allocs/op 7 allocs/op 1
BenchmarkRemovePolicyMedium 563.3 ns/op 177 B/op 7 allocs/op 560.7 ns/op 176 B/op 7 allocs/op 1.00
BenchmarkRemovePolicyMedium - ns/op 563.3 ns/op 560.7 ns/op 1.00
BenchmarkRemovePolicyMedium - B/op 177 B/op 176 B/op 1.01
BenchmarkRemovePolicyMedium - allocs/op 7 allocs/op 7 allocs/op 1
BenchmarkRemovePolicyLarge 1202 ns/op 296 B/op 13 allocs/op 1347 ns/op 290 B/op 13 allocs/op 0.89
BenchmarkRemovePolicyLarge - ns/op 1202 ns/op 1347 ns/op 0.89
BenchmarkRemovePolicyLarge - B/op 296 B/op 290 B/op 1.02
BenchmarkRemovePolicyLarge - allocs/op 13 allocs/op 13 allocs/op 1
BenchmarkRaw 17.56 ns/op 0 B/op 0 allocs/op 17.4 ns/op 0 B/op 0 allocs/op 1.01
BenchmarkRaw - ns/op 17.56 ns/op 17.4 ns/op 1.01
BenchmarkRaw - B/op 0 B/op 0 B/op 1
BenchmarkRaw - allocs/op 0 allocs/op 0 allocs/op 1
BenchmarkBasicModel 3401 ns/op 1503 B/op 17 allocs/op 3537 ns/op 1506 B/op 17 allocs/op 0.96
BenchmarkBasicModel - ns/op 3401 ns/op 3537 ns/op 0.96
BenchmarkBasicModel - B/op 1503 B/op 1506 B/op 1.00
BenchmarkBasicModel - allocs/op 17 allocs/op 17 allocs/op 1
BenchmarkRBACModel 5231 ns/op 2056 B/op 35 allocs/op 5319 ns/op 2064 B/op 35 allocs/op 0.98
BenchmarkRBACModel - ns/op 5231 ns/op 5319 ns/op 0.98
BenchmarkRBACModel - B/op 2056 B/op 2064 B/op 1.00
BenchmarkRBACModel - allocs/op 35 allocs/op 35 allocs/op 1
BenchmarkRBACModelSizes/small 51810 ns/op 20346 B/op 480 allocs/op 48717 ns/op 20231 B/op 480 allocs/op 1.06
BenchmarkRBACModelSizes/small - ns/op 51810 ns/op 48717 ns/op 1.06
BenchmarkRBACModelSizes/small - B/op 20346 B/op 20231 B/op 1.01
BenchmarkRBACModelSizes/small - allocs/op 480 allocs/op 480 allocs/op 1
BenchmarkRBACModelSizes/medium 478667 ns/op 191678 B/op 4828 allocs/op 500856 ns/op 191431 B/op 4828 allocs/op 0.96
BenchmarkRBACModelSizes/medium - ns/op 478667 ns/op 500856 ns/op 0.96
BenchmarkRBACModelSizes/medium - B/op 191678 B/op 191431 B/op 1.00
BenchmarkRBACModelSizes/medium - allocs/op 4828 allocs/op 4828 allocs/op 1
BenchmarkRBACModelSizes/large 5102054 ns/op 1906407 B/op 48353 allocs/op 5300440 ns/op 1899686 B/op 48171 allocs/op 0.96
BenchmarkRBACModelSizes/large - ns/op 5102054 ns/op 5300440 ns/op 0.96
BenchmarkRBACModelSizes/large - B/op 1906407 B/op 1899686 B/op 1.00
BenchmarkRBACModelSizes/large - allocs/op 48353 allocs/op 48171 allocs/op 1.00
BenchmarkRBACModelSmall 60837 ns/op 20482 B/op 615 allocs/op 60137 ns/op 20440 B/op 615 allocs/op 1.01
BenchmarkRBACModelSmall - ns/op 60837 ns/op 60137 ns/op 1.01
BenchmarkRBACModelSmall - B/op 20482 B/op 20440 B/op 1.00
BenchmarkRBACModelSmall - allocs/op 615 allocs/op 615 allocs/op 1
BenchmarkRBACModelMedium 577655 ns/op 194765 B/op 6021 allocs/op 588805 ns/op 194936 B/op 6020 allocs/op 0.98
BenchmarkRBACModelMedium - ns/op 577655 ns/op 588805 ns/op 0.98
BenchmarkRBACModelMedium - B/op 194765 B/op 194936 B/op 1.00
BenchmarkRBACModelMedium - allocs/op 6021 allocs/op 6020 allocs/op 1.00
BenchmarkRBACModelLarge 5934143 ns/op 1940245 B/op 60608 allocs/op 6218220 ns/op 1941524 B/op 60641 allocs/op 0.95
BenchmarkRBACModelLarge - ns/op 5934143 ns/op 6218220 ns/op 0.95
BenchmarkRBACModelLarge - B/op 1940245 B/op 1941524 B/op 1.00
BenchmarkRBACModelLarge - allocs/op 60608 allocs/op 60641 allocs/op 1.00
BenchmarkRBACModelWithResourceRoles 4939 ns/op 2724 B/op 28 allocs/op 5048 ns/op 2730 B/op 28 allocs/op 0.98
BenchmarkRBACModelWithResourceRoles - ns/op 4939 ns/op 5048 ns/op 0.98
BenchmarkRBACModelWithResourceRoles - B/op 2724 B/op 2730 B/op 1.00
BenchmarkRBACModelWithResourceRoles - allocs/op 28 allocs/op 28 allocs/op 1
BenchmarkRBACModelWithDomains 4816 ns/op 1820 B/op 25 allocs/op 4935 ns/op 1824 B/op 25 allocs/op 0.98
BenchmarkRBACModelWithDomains - ns/op 4816 ns/op 4935 ns/op 0.98
BenchmarkRBACModelWithDomains - B/op 1820 B/op 1824 B/op 1.00
BenchmarkRBACModelWithDomains - allocs/op 25 allocs/op 25 allocs/op 1
BenchmarkABACModel 2604 ns/op 1529 B/op 17 allocs/op 2671 ns/op 1531 B/op 17 allocs/op 0.97
BenchmarkABACModel - ns/op 2604 ns/op 2671 ns/op 0.97
BenchmarkABACModel - B/op 1529 B/op 1531 B/op 1.00
BenchmarkABACModel - allocs/op 17 allocs/op 17 allocs/op 1
BenchmarkABACRuleModel 3784670 ns/op 1324583 B/op 40091 allocs/op 3907306 ns/op 1329018 B/op 40092 allocs/op 0.97
BenchmarkABACRuleModel - ns/op 3784670 ns/op 3907306 ns/op 0.97
BenchmarkABACRuleModel - B/op 1324583 B/op 1329018 B/op 1.00
BenchmarkABACRuleModel - allocs/op 40091 allocs/op 40092 allocs/op 1.00
BenchmarkKeyMatchModel 5685 ns/op 3054 B/op 37 allocs/op 5869 ns/op 3063 B/op 37 allocs/op 0.97
BenchmarkKeyMatchModel - ns/op 5685 ns/op 5869 ns/op 0.97
BenchmarkKeyMatchModel - B/op 3054 B/op 3063 B/op 1.00
BenchmarkKeyMatchModel - allocs/op 37 allocs/op 37 allocs/op 1
BenchmarkRBACModelWithDeny 6556 ns/op 2472 B/op 49 allocs/op 6731 ns/op 2477 B/op 49 allocs/op 0.97
BenchmarkRBACModelWithDeny - ns/op 6556 ns/op 6731 ns/op 0.97
BenchmarkRBACModelWithDeny - B/op 2472 B/op 2477 B/op 1.00
BenchmarkRBACModelWithDeny - allocs/op 49 allocs/op 49 allocs/op 1
BenchmarkPriorityModel 3965 ns/op 1755 B/op 22 allocs/op 4088 ns/op 1758 B/op 22 allocs/op 0.97
BenchmarkPriorityModel - ns/op 3965 ns/op 4088 ns/op 0.97
BenchmarkPriorityModel - B/op 1755 B/op 1758 B/op 1.00
BenchmarkPriorityModel - allocs/op 22 allocs/op 22 allocs/op 1
BenchmarkRBACModelWithDomainPatternLarge 22975 ns/op 16741 B/op 164 allocs/op 22747 ns/op 16721 B/op 164 allocs/op 1.01
BenchmarkRBACModelWithDomainPatternLarge - ns/op 22975 ns/op 22747 ns/op 1.01
BenchmarkRBACModelWithDomainPatternLarge - B/op 16741 B/op 16721 B/op 1.00
BenchmarkRBACModelWithDomainPatternLarge - allocs/op 164 allocs/op 164 allocs/op 1
BenchmarkRoleManagerSmall 68543 ns/op 11956 B/op 797 allocs/op 67823 ns/op 11955 B/op 797 allocs/op 1.01
BenchmarkRoleManagerSmall - ns/op 68543 ns/op 67823 ns/op 1.01
BenchmarkRoleManagerSmall - B/op 11956 B/op 11955 B/op 1.00
BenchmarkRoleManagerSmall - allocs/op 797 allocs/op 797 allocs/op 1
BenchmarkRoleManagerMedium 711191 ns/op 125916 B/op 8741 allocs/op 710275 ns/op 125914 B/op 8741 allocs/op 1.00
BenchmarkRoleManagerMedium - ns/op 711191 ns/op 710275 ns/op 1.00
BenchmarkRoleManagerMedium - B/op 125916 B/op 125914 B/op 1.00
BenchmarkRoleManagerMedium - allocs/op 8741 allocs/op 8741 allocs/op 1
BenchmarkRoleManagerLarge 7906676 ns/op 1349923 B/op 89741 allocs/op 7956983 ns/op 1349932 B/op 89741 allocs/op 0.99
BenchmarkRoleManagerLarge - ns/op 7906676 ns/op 7956983 ns/op 0.99
BenchmarkRoleManagerLarge - B/op 1349923 B/op 1349932 B/op 1.00
BenchmarkRoleManagerLarge - allocs/op 89741 allocs/op 89741 allocs/op 1
BenchmarkBuildRoleLinksWithPatternLarge 6175247993 ns/op 5352361120 B/op 60951447 allocs/op 6128452526 ns/op 5344946064 B/op 60949357 allocs/op 1.01
BenchmarkBuildRoleLinksWithPatternLarge - ns/op 6175247993 ns/op 6128452526 ns/op 1.01
BenchmarkBuildRoleLinksWithPatternLarge - B/op 5352361120 B/op 5344946064 B/op 1.00
BenchmarkBuildRoleLinksWithPatternLarge - allocs/op 60951447 allocs/op 60949357 allocs/op 1.00
BenchmarkBuildRoleLinksWithDomainPatternLarge 169925258 ns/op 141977253 B/op 1676596 allocs/op 167620139 ns/op 141724989 B/op 1676532 allocs/op 1.01
BenchmarkBuildRoleLinksWithDomainPatternLarge - ns/op 169925258 ns/op 167620139 ns/op 1.01
BenchmarkBuildRoleLinksWithDomainPatternLarge - B/op 141977253 B/op 141724989 B/op 1.00
BenchmarkBuildRoleLinksWithDomainPatternLarge - allocs/op 1676596 allocs/op 1676532 allocs/op 1.00
BenchmarkBuildRoleLinksWithPatternAndDomainPatternLarge 6345010372 ns/op 5494759736 B/op 62562904 allocs/op 6324546585 ns/op 5485116776 B/op 62560476 allocs/op 1.00
BenchmarkBuildRoleLinksWithPatternAndDomainPatternLarge - ns/op 6345010372 ns/op 6324546585 ns/op 1.00
BenchmarkBuildRoleLinksWithPatternAndDomainPatternLarge - B/op 5494759736 B/op 5485116776 B/op 1.00
BenchmarkBuildRoleLinksWithPatternAndDomainPatternLarge - allocs/op 62562904 allocs/op 62560476 allocs/op 1.00
BenchmarkHasLinkWithPatternLarge 10465 ns/op 7606 B/op 111 allocs/op 10321 ns/op 7605 B/op 111 allocs/op 1.01
BenchmarkHasLinkWithPatternLarge - ns/op 10465 ns/op 10321 ns/op 1.01
BenchmarkHasLinkWithPatternLarge - B/op 7606 B/op 7605 B/op 1.00
BenchmarkHasLinkWithPatternLarge - allocs/op 111 allocs/op 111 allocs/op 1
BenchmarkHasLinkWithDomainPatternLarge 471.8 ns/op 80 B/op 5 allocs/op 475.6 ns/op 80 B/op 5 allocs/op 0.99
BenchmarkHasLinkWithDomainPatternLarge - ns/op 471.8 ns/op 475.6 ns/op 0.99
BenchmarkHasLinkWithDomainPatternLarge - B/op 80 B/op 80 B/op 1
BenchmarkHasLinkWithDomainPatternLarge - allocs/op 5 allocs/op 5 allocs/op 1
BenchmarkHasLinkWithPatternAndDomainPatternLarge 10366 ns/op 7612 B/op 111 allocs/op 10323 ns/op 7610 B/op 111 allocs/op 1.00
BenchmarkHasLinkWithPatternAndDomainPatternLarge - ns/op 10366 ns/op 10323 ns/op 1.00
BenchmarkHasLinkWithPatternAndDomainPatternLarge - B/op 7612 B/op 7610 B/op 1.00
BenchmarkHasLinkWithPatternAndDomainPatternLarge - allocs/op 111 allocs/op 111 allocs/op 1

This comment was automatically generated by workflow using github-action-benchmark.

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.10.

Benchmark suite Current: 65cce21 Previous: 44b890d Ratio
BenchmarkHasPolicySmall 514.4 ns/op 150 B/op 6 allocs/op 455.2 ns/op 150 B/op 6 allocs/op 1.13
BenchmarkHasPolicySmall - ns/op 514.4 ns/op 455.2 ns/op 1.13
BenchmarkHasPolicyMedium 533.6 ns/op 157 B/op 6 allocs/op 482.9 ns/op 157 B/op 6 allocs/op 1.10
BenchmarkHasPolicyMedium - ns/op 533.6 ns/op 482.9 ns/op 1.10

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.