Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type level is_authorized guarding #71

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Type level is_authorized guarding #71

wants to merge 6 commits into from

Conversation

aaronjeline
Copy link
Contributor

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link
Contributor

@john-h-kastner-aws john-h-kastner-aws left a comment

Choose a reason for hiding this comment

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

very cool

pub struct GetList;
impl Action for GetList {
fn action() -> &'static EntityUid {
&ACTION_GET_LIST
Copy link
Contributor

Choose a reason for hiding this comment

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

Could these functions be the only source of truth for the action EntityUid?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Certainly could

tinytodo/src/witnesses.rs Show resolved Hide resolved
self.is_authorized(&r.uid, &*ACTION_EDIT_SHARE, &r.list)?;
let list = self.entities.get_list(&r.list)?;
let proof = self.is_authorized::<actions::EditShare>(&r.uid, &r.list)?;
let list = self.entities.get_list(&r.list, &proof)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Is this different than the witness design pattern? https://willcrichton.net/rust-api-type-patterns/witnesses.html If not, I'd suggest using witness as the parameter name.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

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 great

self.is_authorized(&r.uid, &*ACTION_EDIT_SHARE, &r.list)?;
let list = self.entities.get_list(&r.list)?;
let proof = self.is_authorized::<actions::EditShare>(&r.uid, &r.list)?;
let list = self.entities.get_list(&r.list, &proof)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Comment on lines +396 to +397
principal: &A::Principal,
resource: &A::Resource,
Copy link
Contributor

Choose a reason for hiding this comment

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

very nice, restricting the prnicipal and resource args to is_authorized() on the type level as well

pub struct SealedBundle(Entities);

impl SealedBundle {
pub fn unwrap(self, _proof: impl ReadAll) -> Entities {
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the difference between impl ReadAll and AuthWitness<impl ReadAll> here?

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.

4 participants