16
16
17
17
//! This module contains the batched evaluator implementation and the (internal) definition of [`EntityLoader`]
18
18
19
+ pub mod err;
20
+
19
21
use std:: collections:: { HashMap , HashSet } ;
20
22
use std:: iter;
21
23
use std:: sync:: Arc ;
22
24
23
- use crate :: ast:: { Entity , EntityUID , EntityUIDEntry , Expr , PolicyID , Request } ;
25
+ use crate :: ast:: { Entity , EntityUID , EntityUIDEntry , Request } ;
24
26
use crate :: authorizer:: Decision ;
27
+ use crate :: batched_evaluator:: err:: { BatchedEvalError , InsufficientIterationsError } ;
25
28
use crate :: entities:: TCComputation ;
26
29
use crate :: tpe:: entities:: PartialEntity ;
27
- use crate :: tpe:: err:: {
28
- BatchedEvalError , InsufficientIterationsError , NonstaticPolicyError , PartialRequestError ,
29
- TPEError ,
30
- } ;
30
+ use crate :: tpe:: err:: { PartialRequestError , TPEError } ;
31
+ use crate :: tpe:: policy_expr_map;
31
32
use crate :: tpe:: request:: { PartialEntityUID , PartialRequest } ;
32
33
use crate :: tpe:: residual:: Residual ;
33
34
use crate :: tpe:: response:: { ResidualPolicy , Response } ;
34
- use crate :: validator:: typecheck:: { PolicyCheck , Typechecker } ;
35
- use crate :: validator:: types:: Type ;
36
35
use crate :: validator:: ValidatorSchema ;
37
36
use crate :: { ast:: PolicySet , extensions:: Extensions } ;
38
37
@@ -47,38 +46,6 @@ pub trait EntityLoader {
47
46
fn load_entities ( & mut self , uids : & HashSet < EntityUID > ) -> HashMap < EntityUID , Option < Entity > > ;
48
47
}
49
48
50
- pub ( crate ) fn policy_expr_map < ' a > (
51
- request : & ' a PartialRequest ,
52
- ps : & ' a PolicySet ,
53
- schema : & ValidatorSchema ,
54
- ) -> std:: result:: Result < HashMap < & ' a PolicyID , Expr < Option < Type > > > , TPEError > {
55
- let mut exprs = HashMap :: new ( ) ;
56
- let tc = Typechecker :: new ( schema, crate :: validator:: ValidationMode :: Strict ) ;
57
- let env = request. find_request_env ( schema) ?;
58
- for p in ps. policies ( ) {
59
- if !p. is_static ( ) {
60
- return Err ( NonstaticPolicyError . into ( ) ) ;
61
- }
62
- let t = p. template ( ) ;
63
- match tc. typecheck_by_single_request_env ( t, & env) {
64
- PolicyCheck :: Success ( expr) => {
65
- exprs. insert ( p. id ( ) , expr) ;
66
- }
67
- PolicyCheck :: Fail ( errs) => {
68
- return Err ( TPEError :: Validation ( errs) ) ;
69
- }
70
- PolicyCheck :: Irrelevant ( errs, expr) => {
71
- if errs. is_empty ( ) {
72
- exprs. insert ( p. id ( ) , expr) ;
73
- } else {
74
- return Err ( TPEError :: Validation ( errs) ) ;
75
- }
76
- }
77
- }
78
- }
79
- Ok ( exprs)
80
- }
81
-
82
49
fn concrete_request_to_partial (
83
50
request : & Request ,
84
51
schema : & ValidatorSchema ,
0 commit comments