Skip to content
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: add copy api for lakefs service. #5114

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions core/src/services/lakefs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ impl Access for LakefsBackend {
read: true,
write: true,
delete: true,
copy: true,
..Default::default()
});
am.into()
Expand Down Expand Up @@ -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?),
}
}
}
35 changes: 33 additions & 2 deletions core/src/services/lakefs/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/lakefs/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This service can be used to:
- [x] write
- [ ] create_dir
- [x] delete
- [ ] copy
- [x] copy
- [ ] rename
- [x] list
- [ ] ~~presign~~
Expand Down
Loading