Closed pvormste closed 1 month ago
API Changes
no api changes detected
โฑ๏ธ Estimated effort to review [1-5] | 2 |
๐งช Relevant tests | Yes |
๐ Security concerns | No |
โก Key issues to review |
Possible Bug: The method deleteRawKeysWithAllowanceScope does not handle the case where AccessRights is nil. This could lead to a nil pointer dereference if session.AccessRights is not initialized. |
Code Quality: The method deleteRawKeysWithAllowanceScope checks for store == nil and session == nil at the beginning, which is good for preventing nil dereferences. However, it might be beneficial to also log these occurrences or handle them more gracefully than just returning, to aid in debugging and operational monitoring. |
Category | Suggestion | Score |
Possible issue |
Handle errors from
___
**The function | 9 |
Enhancement |
Add validation for
___
**Consider checking if | 8 |
Performance |
Implement batch deletion of keys to enhance performance___ **To improve the efficiency of the deletion process, consider using a batch delete approachif your storage backend supports it. This can significantly reduce the overhead of individual delete operations, especially when dealing with large datasets.** [gateway/auth_manager.go [95]](https://github.com/TykTechnologies/tyk/pull/6373/files#diff-311e18b071d244ed1615c0019215b633278679df373288b3451bcc5cf7c52c4eR95-R95) ```diff -store.DeleteRawKey(rawKey) +keysToDelete := gatherKeysToDelete(session.AccessRights, keyName) +store.BatchDeleteRawKeys(keysToDelete) ``` Suggestion importance[1-10]: 7Why: Batch deletion can improve performance by reducing the overhead of individual delete operations, especially with large datasets. However, it depends on the storage backend's support for batch operations. | 7 |
Maintainability |
Refactor code to separate validation and deletion of keys___ **Refactor the loop that checks forAllowanceScope to filter and collect all valid scopes first, and then perform deletion. This separates the concerns of validation and deletion, making the code cleaner and potentially more efficient.** [gateway/auth_manager.go [90-95]](https://github.com/TykTechnologies/tyk/pull/6373/files#diff-311e18b071d244ed1615c0019215b633278679df373288b3451bcc5cf7c52c4eR90-R95) ```diff +validKeys := []string{} for _, acl := range session.AccessRights { - if acl.AllowanceScope == "" { - continue + if acl.AllowanceScope != "" { + validKeys = append(validKeys, QuotaKeyPrefix + acl.AllowanceScope + "-" + keyName) } - rawKey := QuotaKeyPrefix + acl.AllowanceScope + "-" + keyName - store.DeleteRawKey(rawKey) +} +for _, key := range validKeys { + store.DeleteRawKey(key) } ``` Suggestion importance[1-10]: 6Why: Refactoring to separate validation and deletion can make the code cleaner and potentially more efficient. However, the improvement is more about code maintainability than a critical issue. | 6 |
Failed conditions
C Reliability Rating on New Code (required โฅ A)
See analysis details on SonarCloud
Catch issues before they fail your Quality Gate with our IDE extension
SonarLint
/release to release-5.4
Working on it! Note that it can take a few minutes.
@pvormste Succesfully merged PR
/release to release-5.3
Working on it! Note that it can take a few minutes.
@pvormste Succesfully merged PR
User description
This PR fixes an issue where
DeleteRawKey
is called multiple times for AllowanceScopes that are non-existent.Types of changes
PR Type
Bug fix, Tests
Description
deleteRawKeysWithAllowanceScope
inDefaultSessionManager
to handle deletion of raw keys with allowance scopes.ResetQuota
to use the new method for better handling of raw key deletions.Changes walkthrough ๐
auth_manager.go
Add method to handle raw key deletion with allowance scopes
gateway/auth_manager.go
deleteRawKeysWithAllowanceScope
to handle deletionof raw keys with allowance scopes.
ResetQuota
to use the new method.auth_manager_test.go
Add unit tests for deleteRawKeysWithAllowanceScope method
gateway/auth_manager_test.go
deleteRawKeysWithAllowanceScope
method.countingStorageHandler
to count delete operations.and sessions with/without allowance scopes.