Caller context#
parcel_runtime::Caller supplies the values rules read through ctx. Construct a caller for a person, agent, or service; tests can use mock values.
Caller fields#
Field |
Type |
Meaning |
|---|---|---|
|
|
Caller identifier. |
|
|
Organization identifier. |
|
|
Purpose of the request. |
|
|
Application-defined service or access tier. |
|
|
Numeric clearance level. |
|
|
Data classification the caller is cleared for. |
|
|
Role names. |
|
|
Time used to evaluate the request. |
|
|
Custom values declared under |
Constructors and methods#
impl Caller {
pub fn new(id: &str, tenant: &str, purpose: &str) -> Caller;
pub fn with_roles(self, roles: &[&str]) -> Caller;
pub fn at(self, now: chrono::DateTime<chrono::Utc>) -> Caller;
}
Method |
Arguments and result |
|---|---|
|
Copies the three identifiers into a new caller. Other strings are empty, clearance is |
|
Replaces the role list with the supplied names. Consumes and returns the caller. |
|
Replaces |
These methods are infallible. Fields are public and can also be changed directly.
Example#
use parcel_runtime::Caller;
let mut caller = Caller::new("supplier-analyst", "globex", "purchasing")
.with_roles(&["analyst"]);
caller.clearance = 2;
caller.classification = "internal".into();
assert_eq!(caller.tenant, "globex");
A rule such as row.supplier_id == ctx.tenant now compares the supplier identifier with globex. Caller holds context values; constructing one does not authenticate the caller.
Evaluate access#
Functions below are in parcel_runtime::plan; Result<T> means Result<T, RuntimeError>.
pub fn refusal(
cc: &CompiledContract, caller: &Caller,
) -> Result<Option<String>>;
pub fn param_values(
cc: &CompiledContract, caller: &Caller,
) -> Result<ParamValues>;
pub fn active_shapes<'a>(
cc: &'a CompiledContract, caller: &Caller,
) -> Result<Vec<&'a ShapeRule>>;
Function |
Parameters |
Return value |
|---|---|---|
|
|
The first refusing |
|
The same contract and caller. |
DataFusion parameter values for the contract’s |
|
The same contract and caller. |
References to shape rules whose |
Expression evaluation failures return RuntimeError. A refusal is an Ok(Some(rule_id)), not an execution error.
For a compiled artifacts: Compilation and the caller above:
match parcel_runtime::plan::refusal(&artifacts.contract, &caller)? {
Some(rule_id) => println!("Refused by {rule_id}"),
None => println!("Caller passed the decision rules"),
}
Row access counts are returned by selectivity.