Struct oso::Oso [−][src]
pub struct Oso { /* fields omitted */ }
Expand description
Oso is the main struct you interact with. It is an instance of the Oso authorization library and contains the polar language knowledge base and query engine.
Implementations
Create a new instance of Oso. Each instance is separate and can have different rules and classes loaded into it.
High level interface for authorization decisions. Makes an allow query with the given actor, action and resource and returns true or false.
Get the actions actor is allowed to take on resource. Returns a std::collections::HashSet of actions, typed according the return value.
Examples
oso.load_str(r#"allow(actor: Actor{name: "sally"}, action, resource: Widget{id: 1}) if
action in ["CREATE", "READ"];"#);
// get a HashSet of oso::Actions
let actions: HashSet<Action> = oso.get_allowed_actions(actor, resource)?;
// or Strings
let actions: HashSet<String> = oso.get_allowed_actions(actor, resource)?;
Clear out all files and rules that have been loaded.
👎 Deprecated since 0.20.1: Oso::load_file
has been deprecated in favor of Oso::load_files
as of the 0.20 release.
Please see changelog for migration instructions: https://docs.osohq.com/project/changelogs/2021-09-15.html
Oso::load_file
has been deprecated in favor of Oso::load_files
as of the 0.20 release.
Please see changelog for migration instructions: https://docs.osohq.com/project/changelogs/2021-09-15.html
Load a file containing Polar rules. All Polar files must end in .polar
.
Load files containing Polar rules. All Polar files must end in .polar
.
Query the knowledge base. This can be an allow query or any other polar expression.
Examples
oso.query("x = 1 or x = 2");
Query the knowledge base but with a rule name and argument list. This allows you to pass in rust values.
Examples
oso.query_rule("is_admin", vec![User{name: "steve"}]);
Register a rust type as a Polar class.
See [oso::Class
] docs.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Oso
impl !UnwindSafe for Oso
Blanket Implementations
Mutably borrows from an owned value. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more