You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2024/09/19 08:04:41 UTC
(opendal) branch main updated: feat: add copy api for lakefs service. (#5114)
This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git
The following commit(s) were added to refs/heads/main by this push:
new 465e17c86f feat: add copy api for lakefs service. (#5114)
465e17c86f is described below
commit 465e17c86fc7bf9d1a865a2eb1a38af60d28a897
Author: Guangdong Liu <li...@gmail.com>
AuthorDate: Thu Sep 19 16:04:35 2024 +0800
feat: add copy api for lakefs service. (#5114)
* 1
* 1
---
core/src/services/lakefs/backend.rs | 12 ++++++++++++
core/src/services/lakefs/core.rs | 35 +++++++++++++++++++++++++++++++++--
core/src/services/lakefs/docs.md | 2 +-
3 files changed, 46 insertions(+), 3 deletions(-)
diff --git a/core/src/services/lakefs/backend.rs b/core/src/services/lakefs/backend.rs
index 6dab46e45f..ac50a73323 100644
--- a/core/src/services/lakefs/backend.rs
+++ b/core/src/services/lakefs/backend.rs
@@ -210,6 +210,7 @@ impl Access for LakefsBackend {
read: true,
write: true,
delete: true,
+ copy: true,
..Default::default()
});
am.into()
@@ -303,4 +304,15 @@ impl Access for LakefsBackend {
_ => Err(parse_error(resp).await?),
}
}
+
+ async fn copy(&self, from: &str, to: &str, _args: OpCopy) -> Result<RpCopy> {
+ let resp = self.core.copy_object(from, to).await?;
+
+ let status = resp.status();
+
+ match status {
+ StatusCode::CREATED => Ok(RpCopy::default()),
+ _ => Err(parse_error(resp).await?),
+ }
+ }
}
diff --git a/core/src/services/lakefs/core.rs b/core/src/services/lakefs/core.rs
index 62aa065f70..33e7fd8bc0 100644
--- a/core/src/services/lakefs/core.rs
+++ b/core/src/services/lakefs/core.rs
@@ -15,12 +15,12 @@
// specific language governing permissions and limitations
// under the License.
-use std::fmt::Debug;
-
use http::header;
use http::Request;
use http::Response;
use serde::Deserialize;
+use std::collections::HashMap;
+use std::fmt::Debug;
use crate::raw::*;
use crate::*;
@@ -194,6 +194,37 @@ impl LakefsCore {
self.client.send(req).await
}
+
+ pub async fn copy_object(&self, path: &str, dest: &str) -> Result<Response<Buffer>> {
+ let p = build_abs_path(&self.root, path)
+ .trim_end_matches('/')
+ .to_string();
+ let d = build_abs_path(&self.root, dest)
+ .trim_end_matches('/')
+ .to_string();
+
+ let url = format!(
+ "{}/api/v1/repositories/{}/branches/{}/objects/copy?dest_path={}",
+ self.endpoint,
+ self.repository,
+ self.branch,
+ percent_encode_path(&d)
+ );
+
+ let mut req = Request::post(&url);
+
+ let auth_header_content = format_authorization_by_basic(&self.username, &self.password)?;
+ req = req.header(header::AUTHORIZATION, auth_header_content);
+ req = req.header(header::CONTENT_TYPE, "application/json");
+ let mut map = HashMap::new();
+ map.insert("src_path", p);
+
+ let req = req
+ .body(serde_json::to_vec(&map).unwrap().into())
+ .map_err(new_request_build_error)?;
+
+ self.client.send(req).await
+ }
}
#[derive(Deserialize, Eq, PartialEq, Debug)]
diff --git a/core/src/services/lakefs/docs.md b/core/src/services/lakefs/docs.md
index 662787964f..039b031c64 100644
--- a/core/src/services/lakefs/docs.md
+++ b/core/src/services/lakefs/docs.md
@@ -12,7 +12,7 @@ This service can be used to:
- [x] write
- [ ] create_dir
- [x] delete
-- [ ] copy
+- [x] copy
- [ ] rename
- [x] list
- [ ] ~~presign~~