Skip to content
This repository was archived by the owner on Oct 6, 2020. It is now read-only.

Commit b636dec

Browse files
committed
Implemented builder pattern
1 parent 2218a66 commit b636dec

File tree

5 files changed

+73
-102
lines changed

5 files changed

+73
-102
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,3 @@ tokio-core = "0.1"
4141

4242
[features]
4343
test_e2e = []
44-
emulator = []

examples/container02.rs

Lines changed: 0 additions & 82 deletions
This file was deleted.

examples/emulator00.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
extern crate azure_sdk_for_rust;
2+
extern crate chrono;
3+
extern crate env_logger;
4+
extern crate futures;
5+
extern crate hyper;
6+
extern crate hyper_tls;
7+
extern crate log;
8+
extern crate md5;
9+
extern crate tokio_core;
10+
extern crate url;
11+
12+
use azure_sdk_for_rust::prelude::*;
13+
use azure_sdk_for_rust::storage::container::PublicAccess;
14+
use futures::future::*;
15+
use std::error::Error;
16+
use tokio_core::reactor::Core;
17+
use url::Url;
18+
19+
fn main() -> Result<(), Box<Error>> {
20+
env_logger::init();
21+
22+
let mut core = Core::new()?;
23+
24+
// this is how you use the emulator.
25+
let blob_storage_url = "http://127.0.0.1:10000";
26+
let table_storage_url = "http://127.0.0.1:10002";
27+
let client = Client::emulator(&Url::parse(blob_storage_url)?, &Url::parse(table_storage_url)?)?;
28+
29+
// create container
30+
let future = client
31+
.create_container()
32+
.with_container_name("emulcont")
33+
.with_public_access(PublicAccess::None)
34+
.finalize();
35+
core.run(future.map(|res| println!("{:?}", res)))?;
36+
37+
let future = client
38+
.list_blobs()
39+
.with_container_name("emulcont")
40+
.with_include_metadata()
41+
.finalize();
42+
core.run(future.map(|res| println!("{:?}", res)))?;
43+
44+
Ok(())
45+
}

src/azure/storage/client.rs

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use azure::storage::{blob, container};
55
use hyper::{self, Method};
66
use hyper_tls;
77
use std::borrow::Borrow;
8+
use url::Url;
89

910
pub trait Blob {
1011
fn list_blobs<'a>(&'a self) -> blob::requests::ListBlobBuilder<'a, No>;
@@ -172,27 +173,36 @@ impl Container for Client {
172173

173174
impl Client {
174175
pub fn new(account: &str, key: &str) -> Result<Client, AzureError> {
175-
use hyper;
176+
Client::azure(account, key)
177+
}
176178

179+
pub fn azure(account: &str, key: &str) -> Result<Client, AzureError> {
177180
let client = hyper::Client::builder().build(hyper_tls::HttpsConnector::new(4)?);
178181

179-
if cfg!(feature = "emulator") {
180-
Ok(Client {
181-
account: "devstoreaccount1".to_owned(),
182-
key: "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==".to_owned(),
183-
hc: client,
184-
blob_uri: "http://127.0.0.1:10000/devstoreaccount1".to_owned(),
185-
table_uri: "http://127.0.0.1:10002/devstoreaccount1".to_owned(),
186-
})
187-
} else {
188-
Ok(Client {
189-
account: account.to_owned(),
190-
key: key.to_owned(),
191-
hc: client,
192-
blob_uri: format!("https://{}.blob.core.windows.net", account),
193-
table_uri: format!("https://{}.table.core.windows.net", account),
194-
})
195-
}
182+
Ok(Client {
183+
account: account.to_owned(),
184+
key: key.to_owned(),
185+
hc: client,
186+
blob_uri: format!("https://{}.blob.core.windows.net", account),
187+
table_uri: format!("https://{}.table.core.windows.net", account),
188+
})
189+
}
190+
191+
pub fn emulator(blob_storage_url: &Url, table_storage_url: &Url) -> Result<Client, AzureError> {
192+
let client = hyper::Client::builder().build(hyper_tls::HttpsConnector::new(4)?);
193+
194+
let blob_uri = format!("{}devstoreaccount1", blob_storage_url.as_str());
195+
debug!("blob_uri == {}", blob_uri);
196+
let table_uri = format!("{}devstoreaccount1", table_storage_url.as_str());
197+
debug!("table_uri == {}", table_uri);
198+
199+
Ok(Client {
200+
account: "devstoreaccount1".to_owned(),
201+
key: "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==".to_owned(),
202+
hc: client,
203+
blob_uri,
204+
table_uri,
205+
})
196206
}
197207

198208
pub fn account(&self) -> &str {

src/azure/storage/container/requests/create_builder.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ impl<'a> CreateBuilder<'a, No, No> {
216216
impl<'a> CreateBuilder<'a, Yes, Yes> {
217217
pub fn finalize(self) -> impl Future<Item = (), Error = AzureError> {
218218
let mut uri = format!("{}/{}?restype=container", self.client().blob_uri(), self.container_name());
219-
println!("{}", uri);
220219

221220
if let Some(nm) = TimeoutOption::to_uri_parameter(&self) {
222221
uri = format!("{}&{}", uri, nm);

0 commit comments

Comments
 (0)