checkRewrite prepares a CheckFunction according to the provided Rewrite operation. It uses a Rewrite object that describes how to combine the results of multiple CheckFunctions.
(ctx context.Context, request *base.PermissionCheckRequest, rewrite *base.Rewrite)
| 166 | // checkRewrite prepares a CheckFunction according to the provided Rewrite operation. |
| 167 | // It uses a Rewrite object that describes how to combine the results of multiple CheckFunctions. |
| 168 | func (engine *CheckEngine) checkRewrite(ctx context.Context, request *base.PermissionCheckRequest, rewrite *base.Rewrite) CheckFunction { |
| 169 | // Switch statement depending on the Rewrite operation |
| 170 | switch rewrite.GetRewriteOperation() { |
| 171 | // In case of UNION operation, set the children CheckFunctions to be run concurrently |
| 172 | // and return the permission if any of the CheckFunctions succeeds (union). |
| 173 | case *base.Rewrite_OPERATION_UNION.Enum(): |
| 174 | return engine.setChild(ctx, request, rewrite.GetChildren(), checkUnion) |
| 175 | // In case of INTERSECTION operation, set the children CheckFunctions to be run concurrently |
| 176 | // and return the permission if all the CheckFunctions succeed (intersection). |
| 177 | case *base.Rewrite_OPERATION_INTERSECTION.Enum(): |
| 178 | return engine.setChild(ctx, request, rewrite.GetChildren(), checkIntersection) |
| 179 | // In case of EXCLUSION operation, set the children CheckFunctions to be run concurrently |
| 180 | // and return the permission if the first CheckFunction succeeds and all others fail (exclusion). |
| 181 | case *base.Rewrite_OPERATION_EXCLUSION.Enum(): |
| 182 | return engine.setChild(ctx, request, rewrite.GetChildren(), checkExclusion) |
| 183 | // In case of an undefined child type, return a CheckFunction that always fails. |
| 184 | default: |
| 185 | return checkFail(errors.New(base.ErrorCode_ERROR_CODE_UNDEFINED_CHILD_TYPE.String())) |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | // checkLeaf prepares a CheckFunction according to the provided Leaf operation. |
| 190 | // It uses a Leaf object that describes how to check a permission request. |
no test coverage detected