@@ -30,10 +30,6 @@ export class CompilerApi {
3030 this . sqlCache = options . sqlCache ;
3131 this . standalone = options . standalone ;
3232 this . nativeInstance = this . createNativeInstance ( ) ;
33- this . rbacEvaluationCache = new LRUCache ( {
34- max : 10000 ,
35- maxAge : 1000 * 60 * 5 , // 5 minutes
36- } ) ;
3733 }
3834
3935 setGraphQLSchema ( schema ) {
@@ -227,20 +223,21 @@ export class CompilerApi {
227223 return context . __hash ;
228224 }
229225
230- async getApplicablePolicies ( cube , context , cubeEvaluator ) {
226+ async getApplicablePolicies ( cube , context , compilers ) {
227+ const cache = compilers . compilerCache . getRbacCacheInstance ( ) ;
231228 const cacheKey = `${ cube . name } _${ this . hashRequestContext ( context ) } ` ;
232- if ( ! this . rbacEvaluationCache . has ( cacheKey ) ) {
229+ if ( ! cache . has ( cacheKey ) ) {
233230 const userRoles = await this . getRolesFromContext ( context ) ;
234231 const policies = cube . accessPolicy . filter ( policy => {
235232 const evaluatedConditions = ( policy . conditions || [ ] ) . map (
236- condition => cubeEvaluator . evaluateContextFunction ( cube , condition . if , context )
233+ condition => compilers . cubeEvaluator . evaluateContextFunction ( cube , condition . if , context )
237234 ) ;
238235 const res = this . userHasRole ( userRoles , policy . role ) && this . roleMeetsConditions ( evaluatedConditions ) ;
239236 return res ;
240237 } ) ;
241- this . rbacEvaluationCache . set ( cacheKey , policies ) ;
238+ cache . set ( cacheKey , policies ) ;
242239 }
243- return this . rbacEvaluationCache . get ( cacheKey ) ;
240+ return cache . get ( cacheKey ) ;
244241 }
245242
246243 evaluateNestedFilter ( filter , cube , context , cubeEvaluator ) {
@@ -277,7 +274,8 @@ export class CompilerApi {
277274 * - combining cube and view filters with AND
278275 */
279276 async applyRowLevelSecurity ( query , context ) {
280- const { cubeEvaluator } = await this . getCompilers ( { requestId : query . requestId } ) ;
277+ const compilers = await this . getCompilers ( { requestId : query . requestId } ) ;
278+ const { cubeEvaluator } = compilers ;
281279
282280 if ( ! cubeEvaluator . isRbacEnabled ( ) ) {
283281 return query ;
@@ -297,7 +295,7 @@ export class CompilerApi {
297295
298296 if ( cubeEvaluator . isRbacEnabledForCube ( cube ) ) {
299297 let hasRoleWithAccess = false ;
300- const userPolicies = await this . getApplicablePolicies ( cube , context , cubeEvaluator ) ;
298+ const userPolicies = await this . getApplicablePolicies ( cube , context , compilers ) ;
301299
302300 for ( const policy of userPolicies ) {
303301 hasRoleWithAccess = true ;
@@ -323,7 +321,7 @@ export class CompilerApi {
323321 query . segments . push ( {
324322 expression : ( ) => '1 = 0' ,
325323 cubeName : cube . name ,
326- name : 'RLS Access Denied ' ,
324+ name : 'rlsAccessDenied ' ,
327325 } ) ;
328326 // If we hit this condition there's no need to evaluate the rest of the policy
329327 break ;
@@ -336,7 +334,6 @@ export class CompilerApi {
336334 viewFiltersPerCubePerRole ,
337335 hasAllowAllForCube
338336 ) ;
339- console . lg ( 'RLS Filter' , JSON . stringify ( rlsFilter , null , 2 ) ) ;
340337 query . filters = query . filters || [ ] ;
341338 query . filters . push ( rlsFilter ) ;
342339 return query ;
@@ -430,8 +427,9 @@ export class CompilerApi {
430427 * It evaluates all applicable memeberLevel accessPolicies givean a context
431428 * and retains members that are allowed by any policy (most permissive set).
432429 */
433- async filterVisibilityByAccessPolicy ( cubeEvaluator , context , cubes ) {
430+ async filterVisibilityByAccessPolicy ( compilers , context , cubes ) {
434431 const isMemberVisibleInContext = { } ;
432+ const { cubeEvaluator } = compilers ;
435433
436434 if ( ! cubeEvaluator . isRbacEnabled ( ) ) {
437435 return cubes ;
@@ -440,7 +438,7 @@ export class CompilerApi {
440438 for ( const cube of cubes ) {
441439 const evaluatedCube = cubeEvaluator . cubeFromPath ( cube . config . name ) ;
442440 if ( cubeEvaluator . isRbacEnabledForCube ( evaluatedCube ) ) {
443- const applicablePolicies = await this . getApplicablePolicies ( evaluatedCube , context , cubeEvaluator ) ;
441+ const applicablePolicies = await this . getApplicablePolicies ( evaluatedCube , context , compilers ) ;
444442
445443 const computeMemberVisibility = ( item ) => {
446444 let isIncluded = false ;
@@ -498,7 +496,7 @@ export class CompilerApi {
498496 const compilers = await this . getCompilers ( restOptions ) ;
499497 const { cubes } = compilers . metaTransformer ;
500498 const filteredCubes = await this . filterVisibilityByAccessPolicy (
501- compilers . cubeEvaluator ,
499+ compilers ,
502500 requestContext ,
503501 cubes
504502 ) ;
@@ -512,15 +510,15 @@ export class CompilerApi {
512510 }
513511
514512 async metaConfigExtended ( requestContext , options ) {
515- const { metaTransformer , cubeEvaluator } = await this . getCompilers ( options ) ;
513+ const compilers = await this . getCompilers ( options ) ;
516514 const filteredCubes = await this . filterVisibilityByAccessPolicy (
517- cubeEvaluator ,
515+ compilers ,
518516 requestContext ,
519- metaTransformer ?. cubes
517+ compilers . metaTransformer ?. cubes
520518 ) ;
521519 return {
522520 metaConfig : filteredCubes ,
523- cubeDefinitions : metaTransformer ?. cubeEvaluator ?. cubeDefinitions ,
521+ cubeDefinitions : compilers . metaTransformer ?. cubeEvaluator ?. cubeDefinitions ,
524522 } ;
525523 }
526524
0 commit comments