pub struct Oso { /* private fields */ }
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§
source§impl Oso
impl Oso
sourcepub fn new() -> Self
pub fn new() -> Self
Create a new instance of Oso. Each instance is separate and can have different rules and classes loaded into it.
sourcepub fn is_allowed<Actor, Action, Resource>(
&self,
actor: Actor,
action: Action,
resource: Resource
) -> Result<bool>
pub fn is_allowed<Actor, Action, Resource>( &self, actor: Actor, action: Action, resource: Resource ) -> Result<bool>
High level interface for authorization decisions. Makes an allow query with the given actor, action and resource and returns true or false.
sourcepub fn get_allowed_actions<Actor, Resource, T>(
&self,
actor: Actor,
resource: Resource
) -> Result<HashSet<T>>
pub fn get_allowed_actions<Actor, Resource, T>( &self, actor: Actor, resource: Resource ) -> Result<HashSet<T>>
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)?;
sourcepub fn clear_rules(&mut self) -> Result<()>
pub fn clear_rules(&mut self) -> Result<()>
Clear out all files and rules that have been loaded.
sourcepub fn load_file<P: AsRef<Path>>(&mut self, filename: P) -> Result<()>
👎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
pub fn load_file<P: AsRef<Path>>(&mut self, filename: P) -> Result<()>
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.htmlLoad a file containing Polar rules. All Polar files must end in .polar
.
sourcepub fn load_files<P: AsRef<Path>>(&mut self, filenames: Vec<P>) -> Result<()>
pub fn load_files<P: AsRef<Path>>(&mut self, filenames: Vec<P>) -> Result<()>
Load files containing Polar rules. All Polar files must end in .polar
.
sourcepub fn query_rule(&self, name: &str, args: impl ToPolarList) -> Result<Query>
pub fn query_rule(&self, name: &str, args: impl ToPolarList) -> Result<Query>
sourcepub fn register_class(&mut self, class: Class) -> Result<()>
pub fn register_class(&mut self, class: Class) -> Result<()>
Register a rust type as a Polar class.
See [oso::Class
] docs.