1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//! # An authorization library with json-based policy definition.
//! Define your authorization rules in a simple `Identity` (I), `Operation` (O),
//! `Resource` (R) model. Evaluate requests against your policy rules.
//!
//! Supports the following customizations:
//! * variable rules and custom variables,
//! * custom resource matching,
//! * custom validation,
//! * default decision if no rules match.
//!
//! ## Examples
//!
//! ```rust
//! use allow_me::{Decision, PolicyBuilder, Request};
//!
//! let json = r#"{
//!     "statements": [
//!         {
//!             "effect": "allow",
//!             "identities": [
//!                 "actor_a"
//!             ],
//!             "operations": [
//!                 "write"
//!             ],
//!             "resources": [
//!                 "resource_1"
//!             ]
//!         }
//!     ]
//! }"#;
//!
//! // Construct the policy.
//! let policy = PolicyBuilder::from_json(json).build().unwrap();
//!
//! // Prepare request (e.g. from user input).
//! let request = Request::new("actor_a", "write", "resource_1").unwrap();
//!
//! // Evaluate the request.
//! match policy.evaluate(&request).unwrap() {
//!     Decision::Allowed => println!("Allowed"),
//!     Decision::Denied => {
//!         panic!("Denied!")
//!     }
//! };
//! ```
//!
//! See more in Examples folder.
//!

#![deny(rust_2018_idioms, warnings)]
#![deny(clippy::all, clippy::pedantic)]
#![allow(
    clippy::module_name_repetitions,
    clippy::must_use_candidate,
    clippy::missing_errors_doc
)]

mod core;
mod errors;
pub mod matcher;
mod substituter;
mod validator;

pub use crate::core::{Decision, Effect, Policy, Request};
pub use crate::core::{PolicyBuilder, PolicyDefinition, Statement};
pub use crate::errors::{Error, Result};
pub use crate::matcher::ResourceMatcher;
pub use crate::substituter::{DefaultSubstituter, Substituter, VariableIter};
pub use crate::validator::{DefaultValidator, PolicyValidator};