Skip to content

Commit

Permalink
feat: add delete api for lakefs service. (#5107)
Browse files Browse the repository at this point in the history
1
  • Loading branch information
liugddx authored Sep 10, 2024
1 parent 0805ddd commit feae7d2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
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

0 comments on commit feae7d2

Please sign in to comment.