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]
impl Oso
[src]pub fn new() -> Self
[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]
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]
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]
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]
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 query(&self, s: &str) -> Result<Query>
[src]
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]
#[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]
pub fn register_class(&mut self, class: Class) -> Result<()>
[src]Register a rust type as a Polar class.
See [oso::Class
] docs.
Trait Implementations
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> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> Instrument for T
[src]
impl<T> Instrument for T
[src]fn instrument(self, span: Span) -> Instrumented<Self>
[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]
fn in_current_span(self) -> Instrumented<Self>
[src]impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
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]
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