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.

Load a file containing polar rules. All polar files must end in .polar

Load a string of polar source directly.

Examples

oso.load_str("allow(a, b, c) if true;");

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.

Register a rust type as a Polar constant. See [oso::Class] docs.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.