-
Notifications
You must be signed in to change notification settings - Fork 24
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Certainly could
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)?; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this 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)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
principal: &A::Principal, | ||
resource: &A::Resource, |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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?
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.