Skip to content

Commit f6b153e

Browse files
Aaron Elinejohn-h-kastner-awscdisselkoen
committed
Addressing Comments
Co-authored-by: John Kastner <[email protected]> Co-authored-by: Craig Disselkoen <[email protected]> Signed-off-by: Aaron Eline <[email protected]>
1 parent 567eeba commit f6b153e

File tree

3 files changed

+37
-44
lines changed

3 files changed

+37
-44
lines changed

cedar-policy-core/src/ast/entity.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ impl Entity {
327327
/// Create a new `Entity` with this UID, attributes, and ancestors
328328
///
329329
/// # Errors
330-
/// - Will error if any of the Restricted Expressions in `attrs` error when evaluated
330+
/// - Will error if any of the [`RestrictedExpr]`s in `attrs` error when evaluated
331331
pub fn new(
332332
uid: EntityUID,
333333
attrs: HashMap<SmolStr, RestrictedExpr>,
@@ -355,17 +355,11 @@ impl Entity {
355355
})
356356
}
357357

358-
/// Creates a new `Entity` with this UID, ancestors, and an empty set of attributes
359-
/// Since it lacks any attributes, this method returns `Self` instead of `Result<Self>`
360-
pub fn new_empty_attrs(
361-
uid: EntityUID,
362-
ancestors: HashSet<EntityUID>,
363-
extensions: &Extensions<'_>,
364-
) -> Self {
365-
// PANIC SAFETY
366-
// Safe as the hashmap is empty
367-
#[allow(clippy::unwrap_used)]
368-
Self::new(uid, HashMap::new(), ancestors, extensions).unwrap()
358+
/// Create a new `Entity` with this UID, ancestors, and an empty set of attributes
359+
///
360+
/// Since there are no attributes, this method does not error, and returns `Self` instead of `Result<Self>`
361+
pub fn new_empty_attrs(uid: EntityUID, ancestors: HashSet<EntityUID>) -> Self {
362+
Self::new_with_attr_partial_value(uid, HashMap::new(), ancestors)
369363
}
370364

371365
/// Create a new `Entity` with this UID, attributes, and ancestors.

cedar-policy-core/src/entities.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ impl Entities {
164164
/// responsible for ensuring that TC and DAG hold before calling this method.
165165
///
166166
/// # Errors
167-
/// - [`EntitiesError::Duplicate`] if there are any duplicate entities in `entiites`
167+
/// - [`EntitiesError::Duplicate`] if there are any duplicate entities in `entities`
168168
/// - [`EntitiesError::TransitiveClosureError`] if `tc_computation ==
169169
/// TCComputation::EnforceAlreadyComputed` and the entities are not transitivly closed
170-
/// - [`EntitiesError::InvalidEntity` if `schema` is not none and any entities do not conform
170+
/// - [`EntitiesError::InvalidEntity`] if `schema` is not none and any entities do not conform
171171
/// to the schema
172172
pub fn from_entities(
173173
entities: impl IntoIterator<Item = Entity>,
@@ -824,7 +824,7 @@ mod json_parsing_tests {
824824
parser.from_json_value(json).expect("JSON is correct")
825825
}
826826

827-
/// Ensure the initial conditions of the entiites still hold
827+
/// Ensure the initial conditions of the entities still hold
828828
fn simple_entities_still_sane(e: &Entities) {
829829
let bob = r#"Test::"bob""#.parse().unwrap();
830830
let alice = e.entity(&r#"Test::"alice""#.parse().unwrap()).unwrap();

cedar-policy/src/api.rs

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,12 @@ impl Entity {
105105
}
106106

107107
/// Create a new `Entity` with this Uid, parents, and no attributes.
108-
/// This is the same as `Self::new` except the attributes are empty, and therefor it can
108+
/// This is the same as `Self::new` except the attributes are empty, and therefore it can
109109
/// return `Self` instead of `Result<Self>`
110110
pub fn new_empty_attrs(uid: EntityUid, parents: HashSet<EntityUid>) -> Self {
111111
Self(ast::Entity::new_empty_attrs(
112112
uid.into(),
113113
parents.into_iter().map(EntityUid::into).collect(),
114-
Extensions::all_available(),
115114
))
116115
}
117116

@@ -356,9 +355,9 @@ impl Entities {
356355
/// error if attributes have the wrong types (e.g., string instead of
357356
/// integer), or if required attributes are missing or superfluous
358357
/// attributes are provided.
359-
/// # Errors
360-
/// - [`EntitiesError::Duplicate`] if there are any duplicate entities in `entiites`
361-
/// - [`EntitiesError::InvalidEntity` if `schema` is not none and any entities do not conform
358+
/// ## Errors
359+
/// - [`EntitiesError::Duplicate`] if there are any duplicate entities in `entities`
360+
/// - [`EntitiesError::InvalidEntity`] if `schema` is not none and any entities do not conform
362361
/// to the schema
363362
pub fn from_entities(
364363
entities: impl IntoIterator<Item = Entity>,
@@ -386,9 +385,9 @@ impl Entities {
386385
///
387386
/// Re-computing the transitive closure can be expensive, so it is advised
388387
/// to not call this method in a loop.
389-
/// # Errors
390-
/// - [`EntitiesError::Duplicate`] if there are any duplicate entities in `entiites`
391-
/// - [`EntitiesError::InvalidEntity` if `schema` is not none and any entities do not conform
388+
/// ## Errors
389+
/// - [`EntitiesError::Duplicate`] if there are any duplicate entities in `entities`
390+
/// - [`EntitiesError::InvalidEntity`] if `schema` is not none and any entities do not conform
392391
/// to the schema
393392
pub fn add_entities(
394393
self,
@@ -420,9 +419,9 @@ impl Entities {
420419
///
421420
/// Re-computing the transitive closure can be expensive, so it is advised
422421
/// to not call this method in a loop.
423-
/// # Errors
424-
/// - [`EntitiesError::Duplicate`] if there are any duplicate entities in `entiites`
425-
/// - [`EntitiesError::InvalidEntity` if `schema` is not none and any entities do not conform
422+
/// ## Errors
423+
/// - [`EntitiesError::Duplicate`] if there are any duplicate entities in `entities`
424+
/// - [`EntitiesError::InvalidEntity`] if `schema` is not none and any entities do not conform
426425
/// to the schema
427426
/// - [`EntitiesError::Deserialization`] if there are errors while parsing the json
428427
pub fn add_entities_from_json_str(
@@ -458,9 +457,9 @@ impl Entities {
458457
///
459458
/// Re-computing the transitive closure can be expensive, so it is advised
460459
/// to not call this method in a loop.
461-
/// # Errors
462-
/// - [`EntitiesError::Duplicate`] if there are any duplicate entities in `entiites`
463-
/// - [`EntitiesError::InvalidEntity` if `schema` is not none and any entities do not conform
460+
/// ## Errors
461+
/// - [`EntitiesError::Duplicate`] if there are any duplicate entities in `entities`
462+
/// - [`EntitiesError::InvalidEntity`] if `schema` is not none and any entities do not conform
464463
/// to the schema
465464
/// - [`EntitiesError::Deserialization`] if there are errors while parsing the json
466465
pub fn add_entities_from_json_value(
@@ -497,9 +496,9 @@ impl Entities {
497496
/// Re-computing the transitive closure can be expensive, so it is advised
498497
/// to not call this method in a loop.
499498
///
500-
/// # Errors
501-
/// - [`EntitiesError::Duplicate`] if there are any duplicate entities in `entiites`
502-
/// - [`EntitiesError::InvalidEntity` if `schema` is not none and any entities do not conform
499+
/// ## Errors
500+
/// - [`EntitiesError::Duplicate`] if there are any duplicate entities in `entities`
501+
/// - [`EntitiesError::InvalidEntity`] if `schema` is not none and any entities do not conform
503502
/// to the schema
504503
/// - [`EntitiesError::Deserialization`] if there are errors while parsing the json
505504
pub fn add_entities_from_json_file(
@@ -539,9 +538,9 @@ impl Entities {
539538
/// instead of integer), or if required attributes are missing or
540539
/// superfluous attributes are provided.
541540
///
542-
/// # Errors
543-
/// - [`EntitiesError::Duplicate`] if there are any duplicate entities in `entiites`
544-
/// - [`EntitiesError::InvalidEntity` if `schema` is not none and any entities do not conform
541+
/// ## Errors
542+
/// - [`EntitiesError::Duplicate`] if there are any duplicate entities in `entities`
543+
/// - [`EntitiesError::InvalidEntity`] if `schema` is not none and any entities do not conform
545544
/// to the schema
546545
/// - [`EntitiesError::Deserialization`] if there are errors while parsing the json
547546
///
@@ -600,9 +599,9 @@ impl Entities {
600599
/// instead of integer), or if required attributes are missing or
601600
/// superfluous attributes are provided.
602601
///
603-
/// # Errors
604-
/// - [`EntitiesError::Duplicate`] if there are any duplicate entities in `entiites`
605-
/// - [`EntitiesError::InvalidEntity` if `schema` is not none and any entities do not conform
602+
/// ## Errors
603+
/// - [`EntitiesError::Duplicate`] if there are any duplicate entities in `entities`
604+
/// - [`EntitiesError::InvalidEntity`]if `schema` is not none and any entities do not conform
606605
/// to the schema
607606
/// - [`EntitiesError::Deserialization`] if there are errors while parsing the json
608607
///
@@ -658,9 +657,9 @@ impl Entities {
658657
/// instead of integer), or if required attributes are missing or
659658
/// superfluous attributes are provided.
660659
///
661-
/// # Errors
662-
/// - [`EntitiesError::Duplicate`] if there are any duplicate entities in `entiites`
663-
/// - [`EntitiesError::InvalidEntity` if `schema` is not none and any entities do not conform
660+
/// ## Errors
661+
/// - [`EntitiesError::Duplicate`] if there are any duplicate entities in `entities`
662+
/// - [`EntitiesError::InvalidEntity`] if `schema` is not none and any entities do not conform
664663
/// to the schema
665664
/// - [`EntitiesError::Deserialization`] if there are errors while parsing the json
666665
pub fn from_json_file(
@@ -1545,7 +1544,7 @@ impl Schema {
15451544

15461545
/// Returns an iterator over every entity type that can be a principal for `action` in this schema
15471546
///
1548-
/// # Errors
1547+
/// ## Errors
15491548
///
15501549
/// Returns [`None`] if `action` is not found in the schema
15511550
pub fn principals_for_action(
@@ -1559,7 +1558,7 @@ impl Schema {
15591558

15601559
/// Returns an iterator over every entity type that can be a resource for `action` in this schema
15611560
///
1562-
/// # Errors
1561+
/// ## Errors
15631562
///
15641563
/// Returns [`None`] if `action` is not found in the schema
15651564
pub fn resources_for_action(
@@ -1573,7 +1572,7 @@ impl Schema {
15731572

15741573
/// Returns an iterator over all the entity types that can be an ancestor of `ty`
15751574
///
1576-
/// # Errors
1575+
/// ## Errors
15771576
///
15781577
/// Returns [`None`] if the `ty` is not found in the schema
15791578
pub fn ancestors<'a>(

0 commit comments

Comments
 (0)