@@ -21,15 +21,15 @@ use crate::evaluator::{EvaluationError, RestrictedEvaluator};
2121use crate :: extensions:: Extensions ;
2222use crate :: parser:: Loc ;
2323use miette:: Diagnostic ;
24- use serde:: Serialize ;
24+ use serde:: { Deserialize , Serialize } ;
2525use smol_str:: SmolStr ;
2626use std:: collections:: { BTreeMap , HashMap } ;
2727use std:: sync:: Arc ;
2828use thiserror:: Error ;
2929
3030use super :: {
31- BorrowedRestrictedExpr , EntityUID , Expr , ExprKind , ExpressionConstructionError , PartialValue ,
32- RestrictedExpr , Unknown , Value , ValueKind , Var ,
31+ BorrowedRestrictedExpr , EntityType , EntityUID , Expr , ExprKind , ExpressionConstructionError ,
32+ PartialValue , RestrictedExpr , Unknown , Value , ValueKind , Var ,
3333} ;
3434
3535/// Represents the request tuple <P, A, R, C> (see the Cedar design doc).
@@ -49,6 +49,18 @@ pub struct Request {
4949 pub ( crate ) context : Option < Context > ,
5050}
5151
52+ /// Represents the principal type, resource type, and action UID.
53+ #[ derive( Debug , Clone , PartialEq , Eq , Hash , Deserialize , Serialize ) ]
54+ #[ serde( rename_all = "camelCase" ) ]
55+ pub struct RequestType {
56+ /// Principal type
57+ pub principal : EntityType ,
58+ /// Action type
59+ pub action : EntityUID ,
60+ /// Resource type
61+ pub resource : EntityType ,
62+ }
63+
5264/// An entry in a request for a Entity UID.
5365/// It may either be a concrete EUID
5466/// or an unknown in the case of partial evaluation
@@ -186,6 +198,19 @@ impl Request {
186198 pub fn context ( & self ) -> Option < & Context > {
187199 self . context . as_ref ( )
188200 }
201+
202+ /// Get the request types that correspond to this request.
203+ /// This includes the types of the principal, action, and resource.
204+ /// [`RequestType`] is used by the entity manifest.
205+ /// The context type is implied by the action's type.
206+ /// Returns `None` if the request is not fully concrete.
207+ pub fn to_request_type ( & self ) -> Option < RequestType > {
208+ Some ( RequestType {
209+ principal : self . principal ( ) . uid ( ) ?. entity_type ( ) . clone ( ) ,
210+ action : self . action ( ) . uid ( ) ?. clone ( ) ,
211+ resource : self . resource ( ) . uid ( ) ?. entity_type ( ) . clone ( ) ,
212+ } )
213+ }
189214}
190215
191216impl std:: fmt:: Display for Request {
0 commit comments