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 delete api for lakefs service. #5107

Merged
merged 1 commit into from
Sep 10, 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
19 changes: 18 additions & 1 deletion core/src/services/lakefs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ impl Access for LakefsBackend {
list: true,
read: true,
write: true,

delete: true,
..Default::default()
});
am.into()
Expand Down Expand Up @@ -285,4 +285,21 @@ impl Access for LakefsBackend {
oio::OneShotWriter::new(LakefsWriter::new(self.core.clone(), path.to_string(), args)),
))
}

async fn delete(&self, path: &str, args: OpDelete) -> Result<RpDelete> {
// This would delete the bucket, do not perform
if self.core.root == "/" && path == "/" {
return Ok(RpDelete::default());
}

let resp = self.core.delete_object(path, &args).await?;

let status = resp.status();

match status {
StatusCode::NO_CONTENT => Ok(RpDelete::default()),
StatusCode::NOT_FOUND => Ok(RpDelete::default()),
_ => Err(parse_error(resp).await?),
}
}
}
23 changes: 23 additions & 0 deletions core/src/services/lakefs/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,29 @@ impl LakefsCore {

self.client.send(req).await
}

pub async fn delete_object(&self, path: &str, _args: &OpDelete) -> Result<Response<Buffer>> {
let p = build_abs_path(&self.root, path)
.trim_end_matches('/')
.to_string();

let url = format!(
"{}/api/v1/repositories/{}/branches/{}/objects?path={}",
self.endpoint,
self.repository,
self.branch,
percent_encode_path(&p)
);

let mut req = Request::delete(&url);

let auth_header_content = format_authorization_by_basic(&self.username, &self.password)?;
req = req.header(header::AUTHORIZATION, auth_header_content);

let req = req.body(Buffer::new()).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 @@ -11,7 +11,7 @@ This service can be used to:
- [x] read
- [x] write
- [ ] create_dir
- [ ] delete
- [x] delete
- [ ] copy
- [ ] rename
- [x] list
Expand Down
Loading