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

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>(
    &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 get_allowed_actions<Actor, Resource, T>(
    &self,
    actor: Actor,
    resource: Resource
) -> Result<HashSet<T>> where
    Actor: ToPolar,
    Resource: ToPolar,
    T: FromPolar + Eq + Hash
[src]

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)?;

pub fn clear_rules(&self)[src]

Clear out all files and rules that have been loaded.

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

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

pub fn load_str(&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(&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(&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]

fn clone(&self) -> Oso[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Default for Oso[src]

fn default() -> Self[src]

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

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]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T> Instrument for T[src]

fn instrument(self, span: Span) -> Instrumented<Self>[src]

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

fn in_current_span(self) -> Instrumented<Self>[src]

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

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

pub fn into(self) -> U[src]

Performs the conversion.

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

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

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

recently added

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

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.