diff --git a/core/src/services/lakefs/backend.rs b/core/src/services/lakefs/backend.rs index 69e59e395ffa..d3fb208cbbc4 100644 --- a/core/src/services/lakefs/backend.rs +++ b/core/src/services/lakefs/backend.rs @@ -208,7 +208,7 @@ impl Access for LakefsBackend { list: true, read: true, write: true, - + delete: true, ..Default::default() }); am.into() @@ -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 { + // 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?), + } + } } diff --git a/core/src/services/lakefs/core.rs b/core/src/services/lakefs/core.rs index 91aed0e34937..62aa065f70bf 100644 --- a/core/src/services/lakefs/core.rs +++ b/core/src/services/lakefs/core.rs @@ -171,6 +171,29 @@ impl LakefsCore { self.client.send(req).await } + + pub async fn delete_object(&self, path: &str, _args: &OpDelete) -> Result> { + 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)] diff --git a/core/src/services/lakefs/docs.md b/core/src/services/lakefs/docs.md index 892bf66b176d..662787964f2b 100644 --- a/core/src/services/lakefs/docs.md +++ b/core/src/services/lakefs/docs.md @@ -11,7 +11,7 @@ This service can be used to: - [x] read - [x] write - [ ] create_dir -- [ ] delete +- [x] delete - [ ] copy - [ ] rename - [x] list