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

feat: add Sign trait #459

Merged
merged 10 commits into from
Aug 6, 2024
Merged

Conversation

flaneur2020
Copy link
Contributor

background: apache/opendal#4960 (comment)

this PR introduced a Sign trait, which is suitable on the cases like when we want customize signing logics like apache/iceberg-rust#506

@Xuanwo
Copy link
Owner

Xuanwo commented Aug 6, 2024

Thanks a lot for your PR! However I'm thinking of a big refactor that build a Sign for entire reqsign. And we can remove the SignableRequest concept entirely by just support http. Do you have interest in this?

@flaneur2020
Copy link
Contributor Author

hmm, it'd be a big refactor, but i have interest about this.

let me have a try, but maybe it's better to make this refactor in a seperate pr.

i'll change the newly added Sign trait to http first.

src/aws/v4.rs Outdated

async fn sign(
&self,
req: &mut http::request::Request<T>,
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 found that it's not that easy to get the mut ref of the Parts inside http::request::Request<T>, to mut the req, it seems that it's still easier to pass &mut http::request::Request<T> here if we'd like to pass a concerete Request struct here.

Copy link
Owner

Choose a reason for hiding this comment

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

i found that it's not that easy to get the mut ref of the Parts inside http::request::Request<T>, to mut the req

Would you like to elaborate further? It should be as straightforward as into_parts and from_parts. I want to avoid introduce an generice body in sign.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we have to have the ownership of Request in the caller side, like this:

let (mut parts, body) = req.into_parts();
signer.sign(mut parts);
let req = Request::from_parts(parts, body);

if all you have is a &mut Request, you can not easily get the parts from it in the caller site.

Copy link
Owner

@Xuanwo Xuanwo Aug 6, 2024

Choose a reason for hiding this comment

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

I proposed an RFC to http: hyperium/http#712


we have to have the ownership of Request in the caller side, like this:

In read use cases, caller will always have the ownership of Request. I still think it's better for us to just take Parts in our API. So all imples and users don't need to play with Body generic type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this RFC makes sense.

i've made the changes, PTAL

Copy link
Contributor Author

@flaneur2020 flaneur2020 Aug 7, 2024

Choose a reason for hiding this comment

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

if hyperium/http is not planned to exposes parts_mut() (in hyperium/http#712 (comment)), i'm afraid that it might be better api to allow accepting a generic parameter in the Sign trait.

in the current code base, there're a lot of call sites that only have got &mut Request instead of an owned Request. it's hard to get the mutable reference of Parts.

Copy link
Owner

@Xuanwo Xuanwo Aug 7, 2024

Choose a reason for hiding this comment

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

I strongly disagree with accepting a generic parameter. I prefer refactoring the entire codebase.


In opendal, we use reqsign in this way:

let req = balabala_build_request();
sign(&mut req);
client.send(req)

So it's totally fine for me to have:

let (head, body) = balabala_build_request().into_parts();
sign(&mut head);
client.send(Request::from_parts(head, body))

@flaneur2020 flaneur2020 marked this pull request as ready for review August 6, 2024 05:14
@flaneur2020 flaneur2020 requested a review from Xuanwo August 6, 2024 05:49
src/request.rs Show resolved Hide resolved
src/sign.rs Outdated Show resolved Hide resolved
src/sign.rs Outdated Show resolved Hide resolved
src/sign.rs Outdated Show resolved Hide resolved
@flaneur2020 flaneur2020 changed the title refactor: add Sign trait feat: add Sign trait Aug 6, 2024
Copy link
Owner

@Xuanwo Xuanwo 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. Thanks a lot for carrying this work!

@Xuanwo Xuanwo merged commit d85f554 into Xuanwo:main Aug 6, 2024
19 checks passed
@flaneur2020 flaneur2020 deleted the refactor/add-sign-trait branch August 9, 2024 06:53
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.

2 participants