-
Notifications
You must be signed in to change notification settings - Fork 25
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
Move 'sign_with_time' method to 'S3Action' #28
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
/target | ||
Cargo.lock | ||
cobertura.xml | ||
|
||
.idea | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,6 +117,18 @@ impl<'a> ListObjectsV2<'a> { | |
|
||
Ok(parsed) | ||
} | ||
} | ||
|
||
impl<'a> S3Action<'a> for ListObjectsV2<'a> { | ||
const METHOD: Method = Method::Get; | ||
|
||
fn query_mut(&mut self) -> &mut Map<'a> { | ||
&mut self.query | ||
} | ||
|
||
fn headers_mut(&mut self) -> &mut Map<'a> { | ||
&mut self.headers | ||
} | ||
|
||
fn sign_with_time(&self, expires_in: Duration, time: &OffsetDateTime) -> Url { | ||
let url = self.bucket.base_url().clone(); | ||
|
@@ -139,23 +151,6 @@ impl<'a> ListObjectsV2<'a> { | |
} | ||
} | ||
|
||
impl<'a> S3Action<'a> for ListObjectsV2<'a> { | ||
const METHOD: Method = Method::Get; | ||
|
||
fn sign(&self, expires_in: Duration) -> Url { | ||
let now = OffsetDateTime::now_utc(); | ||
self.sign_with_time(expires_in, &now) | ||
} | ||
Comment on lines
-145
to
-148
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ...you can remove all of these Basically if a trait has a default implementation for a certain function it'll use it when you do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Of course. I'm familiar with the concept. I just did the brainless work of C&P :D |
||
|
||
fn query_mut(&mut self) -> &mut Map<'a> { | ||
&mut self.query | ||
} | ||
|
||
fn headers_mut(&mut self) -> &mut Map<'a> { | ||
&mut self.headers | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use time::OffsetDateTime; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,12 +30,17 @@ pub mod list_objects_v2; | |
mod multipart_upload; | ||
mod put_object; | ||
|
||
use time::OffsetDateTime; | ||
|
||
/// A request which can be signed | ||
pub trait S3Action<'a> { | ||
const METHOD: Method; | ||
|
||
/// Sign a request for this action, using `METHOD` for the [`Method`] | ||
fn sign(&self, expires_in: Duration) -> Url; | ||
fn sign(&self, expires_in: Duration) -> Url { | ||
let now = OffsetDateTime::now_utc(); | ||
self.sign_with_time(expires_in, &now) | ||
} | ||
|
||
/// Get a mutable reference to the query string of this action | ||
fn query_mut(&mut self) -> &mut Map<'a>; | ||
|
@@ -45,4 +50,8 @@ pub trait S3Action<'a> { | |
/// Headers specified here must also be present in the final request, | ||
/// with the same value specified, otherwise the S3 API will return an error. | ||
fn headers_mut(&mut self) -> &mut Map<'a>; | ||
|
||
/// Takes the time at which the URL should be signed | ||
/// Used for testing purposes | ||
fn sign_with_time(&self, expires_in: Duration, time: &OffsetDateTime) -> Url; | ||
Comment on lines
+54
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This refers to line 38 but I can't seem to be able to comment a line which hasn't been changed so I'll comment this one instead: Could you add a default implementation of sign: fn sign(&self, expires_in: Duration) -> Url {
let now = OffsetDateTime::now_utc();
self.sign_with_time(expires_in, &now)
} so that... (continues in the other comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitely 👍 |
||
} |
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.
Do we want this @guerinoni?
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.
Your repo - your rules. I can remove it if is a big problem.
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.
For me it's ok, maybe for who use this IDE can be handy
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.
👍 let's leave it then