-
Notifications
You must be signed in to change notification settings - Fork 257
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: Use opendal to replace object_store #978
Open
Xuanwo
wants to merge
21
commits into
loco-rs:master
Choose a base branch
from
Xuanwo:storage-refactor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
cfad6c8
refactor: Use opendal to replace object_store
Xuanwo 2c52ec0
Merge branch 'master' into storage-refactor
Xuanwo 96b20a7
Fix clippy
Xuanwo 8c2d1af
Merge remote-tracking branch 'refs/remotes/xuanwo/storage-refactor' i…
Xuanwo 110c002
Merge branch 'master' into storage-refactor
Xuanwo c08558f
Merge branch 'master' into storage-refactor
jondot 02bcf38
Fix aws test
Xuanwo bc9d81e
Fix fs test
Xuanwo ee0776c
Add fallback for services doesn't have copy and rename support
Xuanwo 2bfda4f
Merge branch 'master' into storage-refactor
Xuanwo e20ede3
Merge branch 'master' into storage-refactor
Xuanwo a746b16
Merge branch 'master' into storage-refactor
jondot a68d2d0
Fix style
Xuanwo 3cf1ce4
Don't load imds in CI
Xuanwo 9df0f15
Add allow anonymouse
Xuanwo 2cc9f48
Merge branch 'master' into storage-refactor
Xuanwo 8838446
Merge remote-tracking branch 'origin/master' into storage-refactor
Xuanwo cdc4763
Fix exists handling
Xuanwo 8c71fb1
Fix wrong behavior
Xuanwo 41ff261
Merge branch 'master' into storage-refactor
kaplanelad bf53f81
Merge branch 'master' into storage-refactor
kaplanelad 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 |
---|---|---|
@@ -1,30 +1,23 @@ | ||
use object_store::gcp::GoogleCloudStorageBuilder; | ||
use opendal::{services::Gcs, Operator}; | ||
|
||
use super::{object_store_adapter::ObjectStoreAdapter, StoreDriver}; | ||
use crate::Result; | ||
use super::StoreDriver; | ||
use crate::storage::{drivers::opendal_adapter::OpendalAdapter, StorageResult}; | ||
|
||
/// Create new GCP storage. | ||
/// | ||
/// # Examples | ||
///``` | ||
/// use loco_rs::storage::drivers::gcp; | ||
/// let gcp_driver = gcp::new("key", "account_key", "service_account"); | ||
/// let gcp_driver = gcp::new("key", "credential_path"); | ||
/// ``` | ||
/// | ||
/// # Errors | ||
/// | ||
/// When could not initialize the client instance | ||
pub fn new( | ||
bucket_name: &str, | ||
service_account_key: &str, | ||
service_account: &str, | ||
) -> Result<Box<dyn StoreDriver>> { | ||
let gcs = GoogleCloudStorageBuilder::new() | ||
.with_bucket_name(bucket_name) | ||
.with_service_account_key(service_account_key) | ||
.with_service_account_path(service_account) | ||
.build() | ||
.map_err(Box::from)?; | ||
pub fn new(bucket_name: &str, credential_path: &str) -> StorageResult<Box<dyn StoreDriver>> { | ||
let gcs = Gcs::default() | ||
.bucket(bucket_name) | ||
.credential_path(credential_path); | ||
|
||
Ok(Box::new(ObjectStoreAdapter::new(Box::new(gcs)))) | ||
Ok(Box::new(OpendalAdapter::new(Operator::new(gcs)?.finish()))) | ||
} |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
use object_store::memory::InMemory; | ||
use opendal::{services::Memory, Operator}; | ||
|
||
use super::{object_store_adapter::ObjectStoreAdapter, StoreDriver}; | ||
use super::StoreDriver; | ||
use crate::storage::drivers::opendal_adapter::OpendalAdapter; | ||
|
||
/// Create new in-memory storage. | ||
/// | ||
|
@@ -9,7 +10,15 @@ use super::{object_store_adapter::ObjectStoreAdapter, StoreDriver}; | |
/// use loco_rs::storage::drivers::mem; | ||
/// let mem_storage = mem::new(); | ||
/// ``` | ||
/// | ||
/// # Panics | ||
/// | ||
/// Panics if the memory service built failed. | ||
#[must_use] | ||
pub fn new() -> Box<dyn StoreDriver> { | ||
Box::new(ObjectStoreAdapter::new(Box::new(InMemory::new()))) | ||
Box::new(OpendalAdapter::new( | ||
Operator::new(Memory::default()) | ||
.expect("memory service must build with success") | ||
.finish(), | ||
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. same question |
||
)) | ||
} |
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
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.
Can we handle this without panic?
Would it make more sense to return a Result instead?
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.
Hi, I'm willing to return an error if changing the signature is allowed. This PR tries it's best to not change the exposed public API.
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.
I think it is better than I don't expect.
What do you think? it should't affect the users, right? Only framework changes