Add delete_bucket API

This commit is contained in:
Aditya Manthramurthy 2019-05-30 16:52:02 -07:00
parent 035fced940
commit 334533cff1
2 changed files with 39 additions and 3 deletions

View File

@ -17,8 +17,17 @@ fn main() {
rt::run(rt::lazy(|| { rt::run(rt::lazy(|| {
// let c = get_local_default_server(); // let c = get_local_default_server();
let c = minio::Client::get_play_client(); let c = minio::Client::get_play_client();
c.get_bucket_location("txp")
let region_req = c
.get_bucket_location("yyy")
.map(|res| println!("{}", res.to_string())) .map(|res| println!("{}", res.to_string()))
.map_err(|err| println!("{:?}", err)) .map_err(|err| println!("{:?}", err));
let del_req = c
.delete_bucket("yyy")
.map(|_| println!("Deleted!"))
.map_err(|err| println!("del err: {:?}", err));
del_req.join(region_req).map(|_| ())
})); }));
} }

View File

@ -117,7 +117,7 @@ impl Client {
pub fn get_play_client() -> Client { pub fn get_play_client() -> Client {
Client { Client {
server: "https://play.min.io:9000".parse::<Uri>().unwrap(), server: "https://play.min.io:9000".parse::<Uri>().unwrap(),
region: Region::empty(), region: Region::new("us-east-1"),
conn_client: { conn_client: {
let https = HttpsConnector::new(4).unwrap(); let https = HttpsConnector::new(4).unwrap();
ConnClient::HttpsCC(client::Client::builder().build::<_, hyper::Body>(https)) ConnClient::HttpsCC(client::Client::builder().build::<_, hyper::Body>(https))
@ -163,6 +163,33 @@ impl Client {
.and_then(|s| xml::parse_bucket_location(s)) .and_then(|s| xml::parse_bucket_location(s))
}) })
} }
pub fn delete_bucket(&self, b: &str) -> impl Future<Item = (), Error = Err> {
let qp = HashMap::new();
let mut hmap = HeaderMap::new();
self.add_host_header(&mut hmap);
let body_hash_hdr = (
HeaderName::from_static("x-amz-content-sha256"),
HeaderValue::from_static("UNSIGNED-PAYLOAD"),
);
hmap.insert(body_hash_hdr.0.clone(), body_hash_hdr.1.clone());
let s3_req = S3Req {
method: Method::DELETE,
bucket: Some(b.to_string()),
object: None,
headers: hmap,
query: qp,
body: Body::empty(),
ts: time::now_utc(),
};
let sign_hdrs = sign::sign_v4(&s3_req, &self);
println!("signout: {:?}", sign_hdrs);
let req_result = api::mk_request(&s3_req, &self, &sign_hdrs);
let conn_client = self.conn_client.clone();
run_req_future(req_result, conn_client).and_then(|_| Ok(()))
}
} }
fn run_req_future( fn run_req_future(