Skip to content

Conversation

shaobo-he-aws
Copy link
Contributor

@shaobo-he-aws shaobo-he-aws commented Aug 8, 2024

Description of changes

This PR change the return type to both methods to Option<&str>. Due to the author's limited knowledge of Rust, I have to add a new function in core to get a reference to the Template. Otherwise we could let the return type be Option<SmolStr>.

Issue #, if available

#1116

Checklist for requesting a review

The change in this PR is (choose one, and delete the other options):

  • A breaking change requiring a major version bump to cedar-policy (e.g., changes to the signature of an existing API).

I confirm that this PR (choose one, and delete the other options):

  • Updates the "Unreleased" section of the CHANGELOG with a description of my change (required for major/minor version bumps).

I confirm that cedar-spec (choose one, and delete the other options):

  • Does not require updates because my change does not impact the Cedar formal model or DRT infrastructure.

Copy link
Contributor

@khieta khieta left a comment

Choose a reason for hiding this comment

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

Looks good to me. I'll leave it to a Rust expert to comment on whether get_template_ref is needed.

Copy link
Contributor

@cdisselkoen cdisselkoen left a comment

Choose a reason for hiding this comment

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

Looks good to me. I don't see a problem with the proposed Core interface

Comment on lines 460 to 468
/// Lookup a template by policy id
/// Lookup a template by policy id, returns [`Option<Arc<Template>>`]
pub fn get_template(&self, id: &PolicyID) -> Option<Arc<Template>> {
self.templates.get(id).cloned()
}

/// Lookup a template by policy id, returns [`Option<&Template>`]
pub fn get_template_ref(&self, id: &PolicyID) -> Option<&Template> {
self.templates.get(id).map(AsRef::as_ref)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think in other places we call these get_template_arc and just get_template. Should we change the other places to match this convention?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think get_template_arc and get_template make more sense to me.

Signed-off-by: Shaobo He <[email protected]>
Signed-off-by: Shaobo He <[email protected]>
@shaobo-he-aws shaobo-he-aws merged commit 4087a1a into main Aug 9, 2024
@shaobo-he-aws shaobo-he-aws deleted the 1116-make-policy-and-template-apis-consistent-wrt-annotations branch August 9, 2024 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make Policy and Template APIs consistent wrt annotations
3 participants