diff --git a/Cargo.toml b/Cargo.toml index c4d9e3b187..2fe89cf8c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,4 +41,3 @@ tokio-core = "0.1" [features] test_e2e = [] -emulator = [] diff --git a/examples/container02.rs b/examples/container02.rs deleted file mode 100644 index 00bb51d2c0..0000000000 --- a/examples/container02.rs +++ /dev/null @@ -1,82 +0,0 @@ -extern crate azure_sdk_for_rust; -extern crate chrono; -extern crate env_logger; -extern crate futures; -extern crate hyper; -extern crate hyper_tls; -extern crate log; -extern crate md5; -extern crate tokio_core; - -use azure_sdk_for_rust::prelude::*; -use azure_sdk_for_rust::storage::container::PublicAccess; -use futures::future::*; -use std::error::Error; -use tokio_core::reactor::Core; - -fn main() { - env_logger::init(); - code().unwrap(); -} - -// We run a separate method to use the elegant quotation mark operator. -// A series of unwrap(), unwrap() would have achieved the same result. -fn code() -> Result<(), Box> { - let mut core = Core::new()?; - - // this will only work with the emulator - let client = Client::new("", "")?; - - // create container - let future = client - .create_container() - .with_container_name("emulcont") - .with_public_access(PublicAccess::None) - .finalize(); - core.run(future.map(|res| println!("{:?}", res)))?; - - //let data = b"something"; - - //// this is not mandatory but it helps preventing - //// spurious data to be uploaded. - //let digest = md5::compute(&data[..]); - - //let future = client - // .put_block_blob() - // .with_container_name(&container_name) - // .with_blob_name("blob0.txt") - // .with_content_type("text/plain") - // .with_body(&data[..]) - // .with_content_md5(&digest[..]) - // .finalize(); - //core.run(future.map(|res| println!("{:?}", res)))?; - - //let future = client - // .put_block_blob() - // .with_container_name(&container_name) - // .with_blob_name("blob1.txt") - // .with_content_type("text/plain") - // .with_body(&data[..]) - // .with_content_md5(&digest[..]) - // .finalize(); - //core.run(future.map(|res| println!("{:?}", res)))?; - - //let future = client - // .put_block_blob() - // .with_container_name(&container_name) - // .with_blob_name("blob2.txt") - // .with_content_type("text/plain") - // .with_body(&data[..]) - // .with_content_md5(&digest[..]) - // .finalize(); - //core.run(future.map(|res| println!("{:?}", res)))?; - - //let future = client - // .list_blobs() - // .with_container_name(&container_name) - // .with_include_metadata() - // .finalize(); - //core.run(future.map(|res| println!("{:?}", res)))?; - - Ok(()) -} diff --git a/examples/emulator00.rs b/examples/emulator00.rs new file mode 100644 index 0000000000..5a5515a66c --- /dev/null +++ b/examples/emulator00.rs @@ -0,0 +1,45 @@ +extern crate azure_sdk_for_rust; +extern crate chrono; +extern crate env_logger; +extern crate futures; +extern crate hyper; +extern crate hyper_tls; +extern crate log; +extern crate md5; +extern crate tokio_core; +extern crate url; + +use azure_sdk_for_rust::prelude::*; +use azure_sdk_for_rust::storage::container::PublicAccess; +use futures::future::*; +use std::error::Error; +use tokio_core::reactor::Core; +use url::Url; + +fn main() -> Result<(), Box> { + env_logger::init(); + + let mut core = Core::new()?; + + // this is how you use the emulator. + let blob_storage_url = "http://127.0.0.1:10000"; + let table_storage_url = "http://127.0.0.1:10002"; + let client = Client::emulator(&Url::parse(blob_storage_url)?, &Url::parse(table_storage_url)?)?; + + // create container + let future = client + .create_container() + .with_container_name("emulcont") + .with_public_access(PublicAccess::None) + .finalize(); + core.run(future.map(|res| println!("{:?}", res)))?; + + let future = client + .list_blobs() + .with_container_name("emulcont") + .with_include_metadata() + .finalize(); + core.run(future.map(|res| println!("{:?}", res)))?; + + Ok(()) +} diff --git a/src/azure/storage/client.rs b/src/azure/storage/client.rs index 77fb0e1041..169e85e61e 100644 --- a/src/azure/storage/client.rs +++ b/src/azure/storage/client.rs @@ -5,6 +5,7 @@ use azure::storage::{blob, container}; use hyper::{self, Method}; use hyper_tls; use std::borrow::Borrow; +use url::Url; pub trait Blob { fn list_blobs<'a>(&'a self) -> blob::requests::ListBlobBuilder<'a, No>; @@ -172,27 +173,36 @@ impl Container for Client { impl Client { pub fn new(account: &str, key: &str) -> Result { - use hyper; + Client::azure(account, key) + } + pub fn azure(account: &str, key: &str) -> Result { let client = hyper::Client::builder().build(hyper_tls::HttpsConnector::new(4)?); - if cfg!(feature = "emulator") { - Ok(Client { - account: "devstoreaccount1".to_owned(), - key: "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==".to_owned(), - hc: client, - blob_uri: "http://127.0.0.1:10000/devstoreaccount1".to_owned(), - table_uri: "http://127.0.0.1:10002/devstoreaccount1".to_owned(), - }) - } else { - Ok(Client { - account: account.to_owned(), - key: key.to_owned(), - hc: client, - blob_uri: format!("https://{}.blob.core.windows.net", account), - table_uri: format!("https://{}.table.core.windows.net", account), - }) - } + Ok(Client { + account: account.to_owned(), + key: key.to_owned(), + hc: client, + blob_uri: format!("https://{}.blob.core.windows.net", account), + table_uri: format!("https://{}.table.core.windows.net", account), + }) + } + + pub fn emulator(blob_storage_url: &Url, table_storage_url: &Url) -> Result { + let client = hyper::Client::builder().build(hyper_tls::HttpsConnector::new(4)?); + + let blob_uri = format!("{}devstoreaccount1", blob_storage_url.as_str()); + debug!("blob_uri == {}", blob_uri); + let table_uri = format!("{}devstoreaccount1", table_storage_url.as_str()); + debug!("table_uri == {}", table_uri); + + Ok(Client { + account: "devstoreaccount1".to_owned(), + key: "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==".to_owned(), + hc: client, + blob_uri, + table_uri, + }) } pub fn account(&self) -> &str { diff --git a/src/azure/storage/container/requests/create_builder.rs b/src/azure/storage/container/requests/create_builder.rs index 44d0ddf946..0171e36daa 100644 --- a/src/azure/storage/container/requests/create_builder.rs +++ b/src/azure/storage/container/requests/create_builder.rs @@ -216,7 +216,6 @@ impl<'a> CreateBuilder<'a, No, No> { impl<'a> CreateBuilder<'a, Yes, Yes> { pub fn finalize(self) -> impl Future { let mut uri = format!("{}/{}?restype=container", self.client().blob_uri(), self.container_name()); - println!("{}", uri); if let Some(nm) = TimeoutOption::to_uri_parameter(&self) { uri = format!("{}&{}", uri, nm);