GetCheckKey retrieves the value for the given key from the EngineKeys cache. It returns the PermissionCheckResponse if the key is found, and a boolean value indicating whether the key was found or not.
(key *base.PermissionCheckRequest, isRelational bool)
| 100 | // It returns the PermissionCheckResponse if the key is found, and a boolean value |
| 101 | // indicating whether the key was found or not. |
| 102 | func (c *CheckEngineWithCache) getCheckKey(key *base.PermissionCheckRequest, isRelational bool) (*base.PermissionCheckResponse, bool) { |
| 103 | if key == nil { |
| 104 | // If either the key or value is nil, return false |
| 105 | return nil, false |
| 106 | } |
| 107 | |
| 108 | // Initialize a new xxhash object |
| 109 | h := xxhash.New() |
| 110 | |
| 111 | // Write the checkKey string to the hash object |
| 112 | _, err := h.Write([]byte(engines.GenerateKey(key, isRelational))) |
| 113 | if err != nil { |
| 114 | // If there's an error, return nil and false |
| 115 | return nil, false |
| 116 | } |
| 117 | |
| 118 | // Generate the final cache key by encoding the hash object's sum as a hexadecimal string |
| 119 | k := hex.EncodeToString(h.Sum(nil)) |
| 120 | |
| 121 | // Get the value from the cache using the generated cache key |
| 122 | resp, found := c.cache.Get(k) |
| 123 | |
| 124 | // If the key is found, return the value and true |
| 125 | if found { |
| 126 | // If permission is granted, return allowed response |
| 127 | return &base.PermissionCheckResponse{ |
| 128 | Can: resp.(base.CheckResult), |
| 129 | Metadata: &base.PermissionCheckResponseMetadata{ |
| 130 | CheckCount: 0, |
| 131 | }, |
| 132 | }, true |
| 133 | } |
| 134 | |
| 135 | // If the key is not found, return nil and false |
| 136 | return nil, false |
| 137 | } |
| 138 | |
| 139 | // setCheckKey is a function to set a check key in the cache of the CheckEngineWithKeys. |
| 140 | // It takes a permission check request as a key, a permission check response as a value, |
no test coverage detected