-
Notifications
You must be signed in to change notification settings - Fork 18
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: Allow custom configuration of S3Client
#102
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
dfa9e1e
feat: Allow custom configuration of `S3Client`
morgsmccauley 15cde97
feat: Make `S3Client` easier to work with from outside
morgsmccauley 5907da9
feat: Use custom `S3Client` if configured
morgsmccauley a382843
chore: Remove unused crates
morgsmccauley 88f23a4
refactor: Merge duplicate `impl`s
morgsmccauley 120b1b0
Update src/s3_fetchers.rs
morgsmccauley 039a609
Update src/s3_fetchers.rs
morgsmccauley 58bcb7d
feat: derive `Clone` for `S3Client` errors
morgsmccauley 421b70a
chore: Update `CHANGELOG.md`
morgsmccauley e6d2e47
Bump the version to 0.7.8
khorolets File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
use std::error::Error; | ||
use std::sync::Arc; | ||
|
||
use async_trait::async_trait; | ||
|
||
pub type S3ClientError = Arc<dyn Error + Send + Sync + 'static>; | ||
|
||
#[derive(Debug, thiserror::Error, Clone)] | ||
pub struct GetObjectBytesError(pub S3ClientError); | ||
|
||
impl std::ops::Deref for GetObjectBytesError { | ||
type Target = S3ClientError; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl std::fmt::Display for GetObjectBytesError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "GetObjectBytesError: {}", self.0) | ||
} | ||
} | ||
|
||
impl From<aws_sdk_s3::error::SdkError<aws_sdk_s3::operation::get_object::GetObjectError>> | ||
for GetObjectBytesError | ||
{ | ||
fn from( | ||
error: aws_sdk_s3::error::SdkError<aws_sdk_s3::operation::get_object::GetObjectError>, | ||
) -> Self { | ||
Self(Arc::new(error)) | ||
} | ||
} | ||
|
||
impl From<aws_smithy_types::byte_stream::error::Error> for GetObjectBytesError { | ||
fn from(error: aws_smithy_types::byte_stream::error::Error) -> Self { | ||
Self(Arc::new(error)) | ||
} | ||
} | ||
|
||
#[derive(Debug, thiserror::Error, Clone)] | ||
pub struct ListCommonPrefixesError(pub S3ClientError); | ||
|
||
impl std::fmt::Display for ListCommonPrefixesError { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "ListCommonPrefixesError: {}", self.0) | ||
} | ||
} | ||
|
||
impl std::ops::Deref for ListCommonPrefixesError { | ||
type Target = S3ClientError; | ||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
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. Essentially some helpers to make these errors easier to work with |
||
|
||
impl From<aws_sdk_s3::error::SdkError<aws_sdk_s3::operation::list_objects_v2::ListObjectsV2Error>> | ||
for ListCommonPrefixesError | ||
{ | ||
fn from( | ||
error: aws_sdk_s3::error::SdkError< | ||
aws_sdk_s3::operation::list_objects_v2::ListObjectsV2Error, | ||
>, | ||
) -> Self { | ||
Self(Arc::new(error)) | ||
} | ||
} | ||
|
||
#[async_trait] | ||
pub trait S3Client: Send + Sync { | ||
async fn get_object_bytes( | ||
&self, | ||
bucket: &str, | ||
prefix: &str, | ||
) -> Result<Vec<u8>, GetObjectBytesError>; | ||
|
||
async fn list_common_prefixes( | ||
&self, | ||
bucket: &str, | ||
start_after_prefix: &str, | ||
) -> Result<Vec<String>, ListCommonPrefixesError>; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Dereference the
Box
, and pass a reference to the underlying trait object.