Struct oso::Oso[][src]

pub struct Oso { /* fields omitted */ }

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

impl Oso[src]

pub fn new() -> Self[src]

Create a new instance of Oso. Each instance is separate and can have different rules and classes loaded into it.

pub fn is_allowed<Actor, Action, Resource>(
    &mut self,
    actor: Actor,
    action: Action,
    resource: Resource
) -> Result<bool> where
    Actor: ToPolar,
    Action: ToPolar,
    Resource: ToPolar
[src]

High level interface for authorization decisions. Makes an allow query with the given actor, action and resource and returns true or false.

pub fn clear_rules(&mut self)[src]

Clear out all files and rules that have been loaded.

pub fn load_file<P: AsRef<Path>>(&mut self, file: P) -> Result<()>[src]

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

pub fn load_str(&mut self, s: &str) -> Result<()>[src]

Load a string of polar source directly.

Examples

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

pub fn query(&mut self, s: &str) -> Result<Query>[src]

Query the knowledge base. This can be an allow query or any other polar expression.

Examples

oso.query("x = 1 or x = 2");

#[must_use = "Query that is not consumed does nothing."]pub fn query_rule(
    &mut self,
    name: &str,
    args: impl ToPolarList
) -> Result<Query>
[src]

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"}]);

pub fn register_class(&mut self, class: Class) -> Result<()>[src]

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

pub fn register_constant<V: ToPolar + Send + Sync>(
    &mut self,
    value: V,
    name: &str
) -> Result<()>
[src]

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

Trait Implementations

impl Clone for Oso[src]

impl Default for Oso[src]

Auto Trait Implementations

impl !RefUnwindSafe for Oso

impl Send for Oso

impl Sync for Oso

impl Unpin for Oso

impl !UnwindSafe for Oso

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.