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

refactor/remove unnecessary syncserverrequest impl #1295

Merged
merged 7 commits into from
May 19, 2022

Conversation

taddes
Copy link
Contributor

@taddes taddes commented Apr 28, 2022

Description

This task entailed removing unnecessary impl blocks for syncserverrequest, as they were not used. The implementation of the TryFrom trait for HawkIdentifier followed by moving it into extractors.rs sufficiently tidied up the code in mod.rs scoping the functionality to where the structure is defined and various traits implemented for HawkIdentifier

In the Makefile, added a quoting to avoid certain paths with space characters breaking the build. @ethowitz was able to clear this issue up and had dealt with it in the past.

Testing

Ensuring compilation should be sufficient. Ran into some formatting deltas between CircleCI and clippy in initial tests.

Issue(s)

Closes link.
https://mozilla-hub.atlassian.net/browse/CONSVC-1693

@@ -240,7 +240,7 @@ impl FromRequest for DbTransactionPool {
}
};
let method = req.method().clone();
let user_id = match req.get_hawk_id() {
let user_id = match HawkIdentifier::try_from(&req) {
Copy link
Member

Choose a reason for hiding this comment

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

A slightly more "rusty"(?) approach to this would be:

       let user_id = HawkIdentifier::try_from(&req).map_err(|e| {
                warn!("⚠️ Bad Hawk Id: {:?}", e; "user_agent"=> useragent);
                e
            })?;

Clippy will sometimes flag constructs like these, where you're passing the Ok value back as is.

return Ok(HawkIdentifier::cmd_dummy());
}
let method = req.method().clone();
// NOTE: `connection_info()` gets a mutable reference lock on `extensions()`, so
Copy link
Member

Choose a reason for hiding this comment

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

Looking at what goes on here, the sequence is all blocking code. Is the concern that we don't want the risk of something modifying the extensions?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think Taddes added that comment (or the .clone()), but I agree that we don't need a clone here. Ref represents an immutable borrow to something in a RefCell, and many Refs can exist for a single RefCell at any given time so I don't think any locking is involved: https://docs.rs/rustc-std-workspace-std/1.0.1/std/cell/struct.RefCell.html#method.borrow

Copy link
Contributor

@ethowitz ethowitz 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, @taddes! Just a couple of suggestions 👨🏻‍💻

return Ok(HawkIdentifier::cmd_dummy());
}
let method = req.method().clone();
// NOTE: `connection_info()` gets a mutable reference lock on `extensions()`, so
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think Taddes added that comment (or the .clone()), but I agree that we don't need a clone here. Ref represents an immutable borrow to something in a RefCell, and many Refs can exist for a single RefCell at any given time so I don't think any locking is involved: https://docs.rs/rustc-std-workspace-std/1.0.1/std/cell/struct.RefCell.html#method.borrow

HawkIdentifier::extrude(req, method.as_str(), req.uri(), &ci, secrets)
}
}

impl FromRequest for HawkIdentifier {
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like our new TryFrom impl almost exactly duplicates this extractor (save the dockerflow bit) -- do you think it's worth combining them into a single trait impl?

@taddes taddes changed the title WIP Refactor/remove unnecessary syncserverrequest impl refactor/remove unnecessary syncserverrequest impl Apr 29, 2022
@ethowitz
Copy link
Contributor

ethowitz commented May 9, 2022

I think this needs another rebase after the merging of #1281. Happy to assist if it would be helpful :)

@taddes taddes force-pushed the refactor/remove-unnecessary-syncserverrequest-impl branch from ae126cc to a21073d Compare May 13, 2022 20:10
Copy link
Contributor

@ethowitz ethowitz 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 @taddes! :shipit:

@taddes taddes merged commit b696e71 into master May 19, 2022
@taddes taddes deleted the refactor/remove-unnecessary-syncserverrequest-impl branch May 19, 2022 21:37
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.

3 participants