Skip to content

Commit

Permalink
PR Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
vadim-kovalyov committed Nov 18, 2020
1 parent 0cc59f1 commit f8f81d5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
7 changes: 6 additions & 1 deletion mqtt/policy/src/core/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct PolicyBuilder<V, M, S> {
}

impl PolicyBuilder<DefaultValidator, DefaultResourceMatcher, DefaultSubstituter> {
/// Constructs a `PolicyBuilder` from provided json policy definition and
/// Constructs a `PolicyBuilder` from provided json policy definition, with
/// default configuration.
///
/// Call to this method does not parse or validate the json, all heavy work
Expand All @@ -41,6 +41,11 @@ impl PolicyBuilder<DefaultValidator, DefaultResourceMatcher, DefaultSubstituter>
}
}

/// Constructs a `PolicyBuilder` from provided policy definition struct, with
/// default configuration.
///
/// Call to this method does not validate the definition, all heavy work
/// is done in `build` method.
pub fn from_definition(
definition: PolicyDefinition,
) -> PolicyBuilder<DefaultValidator, DefaultResourceMatcher, DefaultSubstituter> {
Expand Down
16 changes: 8 additions & 8 deletions mqtt/policy/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ pub(crate) mod tests {
/// we can only safely verify the very first statement.
#[test]
fn policy_engine_proptest(definition in arb_policy_definition()){
use itertools::Itertools;
use itertools::iproduct;

// take very first statement, which should have top priority.
let statement = &definition.statements()[0];
Expand All @@ -859,13 +859,13 @@ pub(crate) mod tests {

// collect all combos of identity/operation/resource
// in the statement.
let requests = statement.identities()
.iter()
.cartesian_product(statement.operations())
.cartesian_product(statement.resources())
.map(|item| Request::new(item.0.0, item.0.1, item.1)
.expect("unable to create a request")
).collect::<Vec<_>>();
let requests = iproduct!(
statement.identities(),
statement.operations(),
statement.resources()
)
.map(|item| Request::new(item.0, item.1, item.2).expect("unable to create a request"))
.collect::<Vec<_>>();

let policy = PolicyBuilder::from_definition(definition)
.build()
Expand Down

0 comments on commit f8f81d5

Please sign in to comment.