Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cedar-policy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Starting with version 3.2.4, changes marked with a star (*) are _language breaki

## [Unreleased]
Cedar Language Version: TBD
* Add convenience methods to see how many policies and templates a policy set has (#1179).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we put this in the Added section (three lines below)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!


### Added
- Implemented [RFC 74](https://github.com/cedar-policy/rfcs/pull/74): A new experimental API (`compute_entity_manifest`)
Expand Down
12 changes: 12 additions & 0 deletions cedar-policy/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2057,6 +2057,18 @@ impl PolicySet {
self.ast.is_empty()
}

/// Returns the number of `Template`s in the `PolicySet`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Returns the number of `Template`s in the `PolicySet`.
/// Returns the number of `Policy`s in the `PolicySet`.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, copy paste mishap, let me fix this.

///
/// This will include both static and template-linked policies.
pub fn num_of_policies(&self) -> usize {
self.policies.len()
}

/// Returns the number of `Template`s in the `PolicySet`.
pub fn num_of_templates(&self) -> usize {
self.templates.len()
}

/// Attempt to link a template and add the new template-linked policy to the policy set.
/// If link fails, the `PolicySet` is not modified.
/// Failure can happen for three reasons
Expand Down
14 changes: 7 additions & 7 deletions cedar-policy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,8 +720,8 @@ mod policy_set_tests {
)
.expect("Link failure");

assert_eq!(pset.templates().count(), 1);
assert_eq!(pset.policies().count(), 2);
assert_eq!(pset.num_of_templates(), 1);
assert_eq!(pset.num_of_policies(), 2);
assert_eq!(pset.policies().filter(|p| p.is_static()).count(), 1);

assert_eq!(
Expand Down Expand Up @@ -4211,7 +4211,7 @@ mod policy_set_est_tests {
let pset2 = PolicySet::from_json_value(json).unwrap();

// There should be 2 policies, one static and two links
assert_eq!(pset2.policies().count(), 3);
assert_eq!(pset2.num_of_policies(), 3);
let static_policy = pset2.policy(&PolicyId::new("policy")).unwrap();
assert!(static_policy.is_static());

Expand Down Expand Up @@ -4297,8 +4297,8 @@ mod policy_set_est_tests {
});

let policyset = PolicySet::from_json_value(value).unwrap();
assert_eq!(policyset.templates().count(), 0);
assert_eq!(policyset.policies().count(), 1);
assert_eq!(policyset.num_of_templates(), 0);
assert_eq!(policyset.num_of_policies(), 1);
assert!(policyset.policy(&PolicyId::new("policy1")).is_some());
}

Expand Down Expand Up @@ -4370,8 +4370,8 @@ mod policy_set_est_tests {
});

let policyset = PolicySet::from_json_value(value).unwrap();
assert_eq!(policyset.policies().count(), 2);
assert_eq!(policyset.templates().count(), 1);
assert_eq!(policyset.num_of_policies(), 2);
assert_eq!(policyset.num_of_templates(), 1);
assert!(policyset.template(&PolicyId::new("template")).is_some());
let link = policyset.policy(&PolicyId::new("link")).unwrap();
assert_eq!(link.template_id(), Some(&PolicyId::new("template")));
Expand Down
Loading