-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow custom configuration of
S3Client
(#102)
* feat: Allow custom configuration of `S3Client` * feat: Make `S3Client` easier to work with from outside * feat: Use custom `S3Client` if configured * chore: Remove unused crates * refactor: Merge duplicate `impl`s * Update src/s3_fetchers.rs Co-authored-by: Bohdan Khorolets <[email protected]> * Update src/s3_fetchers.rs Co-authored-by: Bohdan Khorolets <[email protected]> * feat: derive `Clone` for `S3Client` errors * chore: Update `CHANGELOG.md` * Bump the version to 0.7.8 --------- Co-authored-by: Bohdan Khorolets <[email protected]>
- Loading branch information
1 parent
464cf7d
commit f440546
Showing
6 changed files
with
268 additions
and
189 deletions.
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 | ||
} | ||
} | ||
|
||
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.