This commit is contained in:
Francesco Cogno 2018-12-07 16:51:36 +01:00
Родитель 2218a66f78
Коммит b636dec2fb
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 20883E192428EA7A
5 изменённых файлов: 73 добавлений и 102 удалений

Просмотреть файл

@ -41,4 +41,3 @@ tokio-core = "0.1"
[features]
test_e2e = []
emulator = []

Просмотреть файл

@ -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<Error>> {
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(())
}

45
examples/emulator00.rs Normal file
Просмотреть файл

@ -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<Error>> {
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(())
}

Просмотреть файл

@ -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<Client, AzureError> {
use hyper;
Client::azure(account, key)
}
pub fn azure(account: &str, key: &str) -> Result<Client, AzureError> {
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<Client, AzureError> {
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 {

Просмотреть файл

@ -216,7 +216,6 @@ impl<'a> CreateBuilder<'a, No, No> {
impl<'a> CreateBuilder<'a, Yes, Yes> {
pub fn finalize(self) -> impl Future<Item = (), Error = AzureError> {
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);