Skip to content

Commit

Permalink
Updates formatting to comply with linter.
Browse files Browse the repository at this point in the history
  • Loading branch information
chaluli committed Feb 6, 2025
1 parent 3e76529 commit b501019
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 25 deletions.
10 changes: 6 additions & 4 deletions cedar-policy-core/src/ast/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ pub struct Entity {
ancestors: HashSet<EntityUID>,

/// Set of direct ancestors (i.e., parents), as UIDs
parents : HashSet<EntityUID>,
parents: HashSet<EntityUID>,

/// Tags on this entity (RFC 82)
///
Expand Down Expand Up @@ -525,7 +525,10 @@ impl Entity {
/// That is, not only do they have the same UID, but also the same
/// attributes, attribute values, and ancestors/parents.
pub(crate) fn deep_eq(&self, other: &Self) -> bool {
self.uid == other.uid && self.attrs == other.attrs && (self.ancestors().collect::<HashSet<_>>()) == (other.ancestors().collect::<HashSet<_>>())
self.uid == other.uid
&& self.attrs == other.attrs
&& (self.ancestors().collect::<HashSet<_>>())
== (other.ancestors().collect::<HashSet<_>>())
}

/// Set the UID to the given value.
Expand Down Expand Up @@ -565,7 +568,7 @@ impl Entity {

/// Mark the given `UID` as an ancestor of this `Entity`
pub fn add_ancestor(&mut self, uid: EntityUID) {
if ! self.parents.contains(&uid) {
if !self.parents.contains(&uid) {
self.ancestors.insert(uid);
}
}
Expand All @@ -586,7 +589,6 @@ impl Entity {
/// Remove the given `UID` as a parent of this `Entity`
pub fn remove_parent(&mut self, uid: &EntityUID) {
self.parents.remove(uid);

}

/// Consume the entity and return the entity's owned Uid, attributes, ancestors, parents, and tags.
Expand Down
15 changes: 5 additions & 10 deletions cedar-policy-core/src/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl Entities {

/// Removes the [`Crate::ast::EntityUID`]s in the interator from this [`Entities`]
/// Fails if any error is encountered in the transitive closure computation.
///
///
/// If you pass [`TCComputation::AssumeAlreadyComputed`], then the caller is
/// responsible for ensuring that TC and DAG hold before calling this method
pub fn remove_entities(
Expand Down Expand Up @@ -2116,25 +2116,22 @@ mod entities_tests {

// Construct original hierarchy
let entities = Entities::from_entities(
vec![a,b,c,d,e,f],
vec![a, b, c, d, e, f],
None::<&NoEntitiesSchema>,
TCComputation::ComputeNow,
Extensions::all_available(),
)
.expect("Failed to construct entities")
// Remove D from hierarchy
.remove_entities(
vec![EntityUID::with_eid("D")],
TCComputation::ComputeNow,
)
.remove_entities(vec![EntityUID::with_eid("D")], TCComputation::ComputeNow)
.expect("Failed to remove entities");
// Post-Removal Hierarchy
// F -> A
// F -> E -> C
// B

assert_matches!(
entities.entity(&EntityUID::with_eid("D")),
entities.entity(&EntityUID::with_eid("D")),
Dereference::NoSuchEntity
);

Expand Down Expand Up @@ -2188,9 +2185,7 @@ mod schema_based_parsing_tests {
[].into_iter().collect(),
std::iter::once(r#"Action::"readOnly""#.parse().expect("valid uid")).collect(),
))),
r#"Action::"readOnly""# => Some(Arc::new(Entity::with_uid(
action.clone(),
))),
r#"Action::"readOnly""# => Some(Arc::new(Entity::with_uid(action.clone()))),
_ => None,
}
}
Expand Down
15 changes: 12 additions & 3 deletions cedar-policy-core/src/entities/json/entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use smol_str::SmolStr;
use std::sync::Arc;
use std::{collections::{HashMap, HashSet}, io::Read};
use std::{
collections::{HashMap, HashSet},
io::Read,
};

#[cfg(feature = "wasm")]
extern crate tsify;
Expand Down Expand Up @@ -248,7 +251,6 @@ impl<'e, 's, S: Schema> EntityJsonParser<'e, 's, S> {
Ok(entity)
}
}

}

/// Internal function that creates an [`Entities`] from a stream of [`EntityJson`].
Expand Down Expand Up @@ -417,7 +419,14 @@ impl<'e, 's, S: Schema> EntityJsonParser<'e, 's, S> {
})
})
.collect::<Result<_, JsonDeserializationError>>()?;
Ok(Entity::new(uid, attrs, HashSet::new(), parents, tags, self.extensions)?)
Ok(Entity::new(
uid,
attrs,
HashSet::new(),
parents,
tags,
self.extensions,
)?)
}
}

Expand Down
7 changes: 6 additions & 1 deletion cedar-policy-validator/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2691,7 +2691,12 @@ pub(crate) mod test {
let view_entity = actions.entity(&view_uid);
assert_eq!(
view_entity.unwrap(),
&Entity::new_with_attr_partial_value(view_uid, [], HashSet::new(), HashSet::from([read_uid.clone()]))
&Entity::new_with_attr_partial_value(
view_uid,
[],
HashSet::new(),
HashSet::from([read_uid.clone()])
)
);

let read_entity = actions.entity(&read_uid);
Expand Down
12 changes: 5 additions & 7 deletions cedar-policy/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,19 +509,17 @@ impl Entities {
/// Removes each of the [`EntityUID`]s in the interator
/// from this [`Entities`] structure, re-computing the transitive
/// closure after removing all edges to/from the removed entities.
///
///
/// Re-computing the transitive closure can be expensive, so it is
/// advised to not call this method in a loop.
pub fn remove_entities(
self,
entity_ids: impl IntoIterator<Item = EntityUid>,
) -> Result<Self, EntitiesError> {
Ok(Self(
self.0.remove_entities(
entity_ids.into_iter().map(|euid| euid.0),
cedar_policy_core::entities::TCComputation::ComputeNow,
)?,
))
Ok(Self(self.0.remove_entities(
entity_ids.into_iter().map(|euid| euid.0),
cedar_policy_core::entities::TCComputation::ComputeNow,
)?))
}

/// Parse an entities JSON file (in [&str] form) and add them into this
Expand Down

0 comments on commit b501019

Please sign in to comment.