This repository contains a simple hello world program demonstrating typical usage of the Cedar Rust APIs.
The file src/main.rs
provides example code for the key steps an application takes to use Cedar. These include (1) parsing policies from text; (2) creating access requests and asking whether the request is authorized by the policies; (3) making requests that have an optional context
(in addition to a principal, action, and resource); (4) providing entities with a request, which are application data relevant to the request; and (5) validating that policies are consistent with a provided schema.
The following are functions that demonstrate elements of the above.
parse_policy
: parsing a policy and extract some of its componentsjson_context
: constructing a requestcontext
from JSON valuesentity_json
: constructing entities from JSONentity_objects
: constructing entities from Rust objectsvalidate
: validating a policy
This example expects that the cedar
repository is cloned into the toplevel (../cedar-examples
) directory. You can instruct Cargo to use your local version of cedar-policy
by adding path = "../cedar/cedar-policy"
to Cargo.toml.
cargo run