-
Notifications
You must be signed in to change notification settings - Fork 107
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
fix(rpc): Refactor the cookie-based RPC authentication #8940
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.
Thank you! This is an excellent refactor, it fixes the issues mentioned in the PR description, and the new With
trait looks like it'll be very useful later/elsewhere in Zebra (I'm looking forward to using it in the parameters::network::testnet
module).
/// A trait for updating an object, consuming it and returning the updated version. | ||
pub trait With<T> { | ||
/// Updates `self` with an instance of type `T` and returns the updated version of `self`. | ||
fn with(self, _: T) -> Self; | ||
} |
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.
This looks great, good idea!
Optional: This could be useful elsewhere in Zebra as well, such as in the testnet::ParametersBuilder
, so it might fit better in zebra-chain
, but it could also be moved in whenever we try implementing it for other structs.
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.
I'm glad you like it. :) It pretty much randomly occurred to me to do it this way. It seems to go well with something like let foo = if cond1 {Foo::...with(...)} else if cond2 {Foo::...with(...)} else {Foo::...with(...)}
.
Yea, let's move it somewhere else if we're using it in other places.
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.
We could maybe add a macro which could take an arbitrary number of arguments: ...with!(a, b, c)
.
Co-authored-by: Arya <aryasolhi@gmail.com>
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 really good and it works. Thanks for the refactor!
* add a cookie auth system for the rpc endpoint * fix rand import * fixes based on cookie method research * add and use `cookie_dir` config, rpc client changes * add missing dependency * add a enable_cookie auth option to config and use it in all tests * get rid of the unauthenticated method * change config in qa python tests to run unauthenticated * change return types in cookie methods * change comment * fix(rpc): Refactor the cookie-based RPC authentication (#8940) * Refactor the cookie-based RPC authentication * Rephrase docs * Apply suggestions from code review Co-authored-by: Arya <aryasolhi@gmail.com> --------- Co-authored-by: Arya <aryasolhi@gmail.com> * clippy --------- Co-authored-by: Marek <mail@marek.onl> Co-authored-by: Arya <aryasolhi@gmail.com>
Motivation
Resolve #8900 (comment) and #8900 (comment).
Solution
FixHttpRequestMiddleware
toHttpRequestMiddleware
since it doesn't contain only fixes anymore but also serves as an authentication layer.Tests
No new tests.
PR Author's Checklist
PR Reviewer's Checklist