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

Commit f016621

Browse files
authored
Merge pull request #126 from MindFlavor/issue/119/pr
Azure REST API bump to 2018-03-28 and implemented get_account_information
2 parents d04bdfb + c40bafe commit f016621

File tree

22 files changed

+281
-21
lines changed

22 files changed

+281
-21
lines changed

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ members = [
55
"azure_sdk_service_bus",
66
"azure_sdk_storage_blob",
77
"azure_sdk_storage_core",
8-
"azure_sdk_storage_table"
8+
"azure_sdk_storage_table",
9+
"azure_sdk_storage_account"
910
]

README.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# Microsoft Azure SDK for Rust
22

3-
[![docs](https://docs.rs/azure_sdk_for_rust/badge.svg)](https://docs.rs/azure_sdk_for_rust/0.20.0/azure_sdk_for_rust)
3+
[![docs](https://docs.rs/azure_sdk_for_rust/badge.svg)](https://docs.rs/azure_sdk_for_rust/0.20.1/azure_sdk_for_rust)
44

55
[![legal](https://img.shields.io/github/license/mindflavor/AzureSDKForRust.svg)](LICENSE)
66

77
[![Build Status](https://travis-ci.org/MindFlavor/AzureSDKForRust.svg?branch=master)](https://travis-ci.org/MindFlavor/AzureSDKForRust) [![Coverage Status](https://coveralls.io/repos/MindFlavor/AzureSDKForRust/badge.svg?branch=master&service=github)](https://coveralls.io/github/MindFlavor/AzureSDKForRust?branch=master) ![stability-unstable](https://img.shields.io/badge/stability-unstable-yellow.svg)
88

99
[![Crate](https://img.shields.io/crates/v/azure_sdk_for_rust.svg)](https://crates.io/crates/azure_sdk_for_rust) [![cratedown](https://img.shields.io/crates/d/azure_sdk_for_rust.svg)](https://crates.io/crates/azure_sdk_for_rust) [![cratelastdown](https://img.shields.io/crates/dv/azure_sdk_for_rust.svg)](https://crates.io/crates/azure_sdk_for_rust)
1010

11-
[![tag](https://img.shields.io/github/tag/mindflavor/AzureSDKForRust.svg)](https://github.com/MindFlavor/AzureSDKForRust/tree/0.20.0)
12-
[![release](https://img.shields.io/github/release/mindflavor/AzureSDKForRust.svg)](https://github.com/MindFlavor/AzureSDKForRust/releases/tag/0.20.0)
13-
[![commitssince](https://img.shields.io/github/commits-since/mindflavor/AzureSDKForRust/0.20.0.svg)](https://github.com/MindFlavor/AzureSDKForRust/commits/master)
11+
[![tag](https://img.shields.io/github/tag/mindflavor/AzureSDKForRust.svg)](https://github.com/MindFlavor/AzureSDKForRust/tree/0.20.1)
12+
[![release](https://img.shields.io/github/release/mindflavor/AzureSDKForRust.svg)](https://github.com/MindFlavor/AzureSDKForRust/releases/tag/0.20.1)
13+
[![commitssince](https://img.shields.io/github/commits-since/mindflavor/AzureSDKForRust/0.20.1.svg)](https://github.com/MindFlavor/AzureSDKForRust/commits/master)
1414

1515
[![GitHub contributors](https://img.shields.io/github/contributors/MindFlavor/AzureSDKForRust.svg)](https://github.com/MindFlavor/AzureSDKForRust/graphs/contributors)
1616

@@ -298,6 +298,9 @@ cargo test --features=test_e2e
298298

299299
cd ../azure_sdk_storage_blob
300300
cargo test --features=test_e2e
301+
302+
cd ../azure_sdk_storage_account
303+
cargo test --features=test_e2e
301304
```
302305

303306
### Windows
@@ -316,6 +319,9 @@ cargo test --features=test_e2e
316319
317320
cd ../azure_sdk_storage_blob
318321
cargo test --features=test_e2e
322+
323+
cd ../azure_sdk_storage_account
324+
cargo test --features=test_e2e
319325
```
320326

321327
## License

azure_sdk_core/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "azure_sdk_core"
3-
version = "0.20.0"
3+
version = "0.20.1"
44
description = "Rust wrappers around Microsoft Azure REST APIs - Core crate"
55
readme = "README.md"
66
authors = ["Francesco Cogno <francesco.cogno@outlook.com>", "Max Gortman <mgortman@microsoft.com>", "Dong Liu <doliu@microsoft.com>"]

azure_sdk_core/src/headers.rs

+2
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ pub const PAGE_WRITE: &str = "x-ms-page-write";
3333
pub const REQUEST_SERVER_ENCRYPTED: &str = "x-ms-request-server-encrypted";
3434
pub const DELETE_TYPE_PERMANENT: &str = "x-ms-delete-type-permanent";
3535
pub const DELETE_SNAPSHOTS: &str = "x-ms-delete-snapshots";
36+
pub const SKU_NAME: &str = "x-ms-sku-name";
37+
pub const ACCOUNT_KIND: &str = "x-ms-account-kind";

azure_sdk_core/src/lib.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ pub mod range;
4545
use url::percent_encoding;
4646
pub mod headers;
4747
use self::headers::{
48-
BLOB_ACCESS_TIER, BLOB_CONTENT_LENGTH, BLOB_SEQUENCE_NUMBER, CLIENT_REQUEST_ID, CONTENT_MD5, DELETE_SNAPSHOTS, DELETE_TYPE_PERMANENT,
49-
LEASE_BREAK_PERIOD, LEASE_DURATION, LEASE_ID, LEASE_TIME, PROPOSED_LEASE_ID, REQUEST_ID, REQUEST_SERVER_ENCRYPTED,
48+
ACCOUNT_KIND, BLOB_ACCESS_TIER, BLOB_CONTENT_LENGTH, BLOB_SEQUENCE_NUMBER, CLIENT_REQUEST_ID, CONTENT_MD5, DELETE_SNAPSHOTS,
49+
DELETE_TYPE_PERMANENT, LEASE_BREAK_PERIOD, LEASE_DURATION, LEASE_ID, LEASE_TIME, PROPOSED_LEASE_ID, REQUEST_ID,
50+
REQUEST_SERVER_ENCRYPTED, SKU_NAME,
5051
};
5152
use hyper::header::{
5253
HeaderName, CACHE_CONTROL, CONTENT_ENCODING, CONTENT_LANGUAGE, CONTENT_LENGTH, CONTENT_TYPE, DATE, ETAG, LAST_MODIFIED, RANGE,
@@ -810,6 +811,24 @@ pub fn date_from_headers(headers: &HeaderMap) -> Result<DateTime<Utc>, AzureErro
810811
Ok(date)
811812
}
812813

814+
pub fn sku_name_from_headers(headers: &HeaderMap) -> Result<String, AzureError> {
815+
let sku_name = headers
816+
.get(SKU_NAME)
817+
.ok_or_else(|| AzureError::HeaderNotFound(SKU_NAME.to_owned()))?
818+
.to_str()?;
819+
trace!("sku_name == {:?}", sku_name);
820+
Ok(sku_name.to_owned())
821+
}
822+
823+
pub fn account_kind_from_headers(headers: &HeaderMap) -> Result<String, AzureError> {
824+
let account_kind = headers
825+
.get(ACCOUNT_KIND)
826+
.ok_or_else(|| AzureError::HeaderNotFound(ACCOUNT_KIND.to_owned()))?
827+
.to_str()?;
828+
trace!("account_kind == {:?}", account_kind);
829+
Ok(account_kind.to_owned())
830+
}
831+
813832
pub fn etag_from_headers_optional(headers: &HeaderMap) -> Result<Option<String>, AzureError> {
814833
if headers.contains_key(ETAG) {
815834
Ok(Some(etag_from_headers(headers)?))

azure_sdk_cosmos/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "azure_sdk_cosmos"
3-
version = "0.20.0"
3+
version = "0.20.1"
44
description = "Rust wrappers around Microsoft Azure REST APIs - Azure Cosmos DB crate"
55
readme = "README.md"
66
authors = ["Francesco Cogno <francesco.cogno@outlook.com>", "Max Gortman <mgortman@microsoft.com>"]
@@ -15,7 +15,7 @@ categories = ["api-bindings"]
1515
edition = "2018"
1616

1717
[dependencies]
18-
azure_sdk_core = { path="../azure_sdk_core", version = "0.20.0" }
18+
azure_sdk_core = { path="../azure_sdk_core", version = "0.20.1" }
1919
ring = "0.14"
2020
md5 = "0.6"
2121
RustyXML = "0.1"

azure_sdk_service_bus/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "azure_sdk_service_bus"
3-
version = "0.20.0"
3+
version = "0.20.1"
44
description = "Rust wrappers around Microsoft Azure REST APIs - Service Bus crate"
55
readme = "README.md"
66
authors = ["Francesco Cogno <francesco.cogno@outlook.com>", "Max Gortman <mgortman@microsoft.com>", "Dong Liu <doliu@microsoft.com>"]
@@ -15,7 +15,7 @@ categories = ["api-bindings"]
1515
edition = "2018"
1616

1717
[dependencies]
18-
azure_sdk_core = { path="../azure_sdk_core", version = "0.20.0" }
18+
azure_sdk_core = { path="../azure_sdk_core", version = "0.20.1" }
1919
ring = "0.14"
2020
md5 = "0.6"
2121
RustyXML = "0.1"

azure_sdk_storage_account/Cargo.toml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
[package]
2+
name = "azure_sdk_storage_account"
3+
version = "0.20.1"
4+
description = "Rust wrappers around Microsoft Azure REST APIs - Blob storage account crate"
5+
readme = "README.md"
6+
authors = ["Francesco Cogno <francesco.cogno@outlook.com>", "Max Gortman <mgortman@microsoft.com>"]
7+
license = "Apache-2.0"
8+
repository = "https://github.com/MindFlavor/AzureSDKForRust"
9+
documentation = "http://mindflavor.github.io/AzureSDKForRust/azure_sdk_for_rust/index.html"
10+
homepage = "https://github.com/MindFlavor/AzureSDKForRust"
11+
12+
keywords = ["sdk", "azure", "rest", "iot", "cloud"]
13+
categories = ["api-bindings"]
14+
15+
edition = "2018"
16+
17+
[dependencies]
18+
azure_sdk_core = { path="../azure_sdk_core", version = "0.20.1" }
19+
azure_sdk_storage_core = { path="../azure_sdk_storage_core", version = "0.20.1" }
20+
ring = "0.14"
21+
md5 = "0.6"
22+
RustyXML = "0.1"
23+
base64 = "0.10"
24+
chrono = "0.4"
25+
env_logger = "0.6"
26+
futures = "0.1"
27+
http = "0.1"
28+
hyper = "0.12"
29+
log = "0.4"
30+
mime = "0.3"
31+
quick-error = "1.2"
32+
serde = "1.0"
33+
serde_derive = "1.0"
34+
serde_json = "1.0"
35+
serde-xml-rs = "0.3"
36+
time = "0.1"
37+
url = "1.7"
38+
uuid = { version = "0.7", features = ["v4"] }
39+
smallvec = { version = "0.6", features = ["serde"] }
40+
bytes = "0.4"
41+
hyper-rustls = "0.16"
42+
43+
[dev-dependencies]
44+
tokio-core = "0.1"
45+
46+
[features]
47+
test_e2e = []
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use azure_sdk_storage_account::prelude::*;
2+
use azure_sdk_storage_core::prelude::*;
3+
use futures::future::*;
4+
use std::error::Error;
5+
use tokio_core::reactor::Core;
6+
7+
fn main() {
8+
code().unwrap();
9+
}
10+
11+
// We run a separate method to use the elegant quotation mark operator.
12+
// A series of unwrap(), unwrap() would have achieved the same result.
13+
fn code() -> Result<(), Box<dyn Error>> {
14+
// First we retrieve the account name and master key from environment variables.
15+
let account = std::env::var("STORAGE_ACCOUNT").expect("Set env variable STORAGE_ACCOUNT first!");
16+
let master_key = std::env::var("STORAGE_MASTER_KEY").expect("Set env variable STORAGE_MASTER_KEY first!");
17+
18+
let mut core = Core::new()?;
19+
20+
let client = Client::new(&account, &master_key)?;
21+
22+
let future = {
23+
client.get_account_information().finalize().map(|response| {
24+
println!("{:?}", response);
25+
})
26+
};
27+
28+
core.run(future)?;
29+
30+
Ok(())
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pub mod requests;
2+
pub mod responses;
3+
4+
#[derive(Debug, Clone, PartialEq)]
5+
pub struct Account {
6+
pub sku_name: String,
7+
pub kind: String,
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "GetAccountInformationBuilder",
3+
"extra_types": [ "'a" ],
4+
"extra_wheres": [],
5+
"constructor_fields": [
6+
{
7+
"name": "client",
8+
"field_type": "&'a Client",
9+
"trait_get": "ClientRequired<'a>"
10+
}
11+
],
12+
"fields": [
13+
]
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use crate::account::responses::GetAccountInformationResponse;
2+
use azure_sdk_core::errors::{check_status_extract_headers_and_body, AzureError};
3+
use azure_sdk_storage_core::client::Client;
4+
use azure_sdk_storage_core::ClientRequired;
5+
use futures::future::done;
6+
use futures::prelude::*;
7+
use hyper::{Method, StatusCode};
8+
9+
#[derive(Debug, Clone)]
10+
pub struct GetAccountInformationBuilder<'a> {
11+
client: &'a Client,
12+
}
13+
14+
impl<'a> GetAccountInformationBuilder<'a> {
15+
pub(crate) fn new(client: &'a Client) -> GetAccountInformationBuilder<'a> {
16+
GetAccountInformationBuilder { client }
17+
}
18+
}
19+
20+
impl<'a> ClientRequired<'a> for GetAccountInformationBuilder<'a> {
21+
fn client(&self) -> &'a Client {
22+
self.client
23+
}
24+
}
25+
26+
// methods callable regardless
27+
impl<'a> GetAccountInformationBuilder<'a> {
28+
#[inline]
29+
pub fn finalize(self) -> impl Future<Item = GetAccountInformationResponse, Error = AzureError> {
30+
let uri = format!("{}/?restype=account&comp=properties", self.client.blob_uri());
31+
trace!("uri == {:?}", uri);
32+
33+
let req = self.client().perform_request(&uri, &Method::GET, |ref mut _request| {}, None);
34+
35+
done(req)
36+
.from_err()
37+
.and_then(move |future_response| check_status_extract_headers_and_body(future_response, StatusCode::OK))
38+
.and_then(move |(headers, _body)| done(GetAccountInformationResponse::from_headers(&headers)))
39+
}
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mod get_account_information_builder;
2+
pub use self::get_account_information_builder::GetAccountInformationBuilder;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use azure_sdk_core::errors::AzureError;
2+
use azure_sdk_core::{account_kind_from_headers, date_from_headers, request_id_from_headers, sku_name_from_headers, RequestId};
3+
use chrono::{DateTime, Utc};
4+
use http::HeaderMap;
5+
6+
#[derive(Debug, Clone)]
7+
pub struct GetAccountInformationResponse {
8+
pub request_id: RequestId,
9+
pub date: DateTime<Utc>,
10+
pub sku_name: String,
11+
pub account_kind: String,
12+
}
13+
14+
impl GetAccountInformationResponse {
15+
pub(crate) fn from_headers(headers: &HeaderMap) -> Result<GetAccountInformationResponse, AzureError> {
16+
let request_id = request_id_from_headers(headers)?;
17+
let date = date_from_headers(headers)?;
18+
let sku_name = sku_name_from_headers(headers)?;
19+
let account_kind = account_kind_from_headers(headers)?;
20+
21+
Ok(GetAccountInformationResponse {
22+
request_id,
23+
date,
24+
sku_name,
25+
account_kind,
26+
})
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mod get_account_information_response;
2+
pub use get_account_information_response::GetAccountInformationResponse;

azure_sdk_storage_account/src/lib.rs

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#![recursion_limit = "128"]
2+
3+
extern crate base64;
4+
extern crate chrono;
5+
extern crate futures;
6+
extern crate http;
7+
extern crate hyper;
8+
extern crate hyper_rustls;
9+
extern crate md5;
10+
extern crate ring;
11+
extern crate time;
12+
extern crate url;
13+
extern crate uuid;
14+
extern crate xml;
15+
#[macro_use]
16+
extern crate log;
17+
extern crate quick_error;
18+
extern crate serde;
19+
#[macro_use]
20+
extern crate serde_derive;
21+
extern crate bytes;
22+
extern crate serde_json;
23+
extern crate serde_xml_rs;
24+
extern crate smallvec;
25+
26+
#[macro_use]
27+
extern crate azure_sdk_core;
28+
extern crate azure_sdk_storage_core;
29+
pub mod account;
30+
pub mod prelude;
31+
32+
use azure_sdk_storage_core::client::Client;
33+
34+
pub trait Account {
35+
fn get_account_information<'a>(&'a self) -> account::requests::GetAccountInformationBuilder<'a>;
36+
}
37+
38+
impl Account for Client {
39+
fn get_account_information<'a>(&'a self) -> account::requests::GetAccountInformationBuilder<'a> {
40+
account::requests::GetAccountInformationBuilder::new(self)
41+
}
42+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub use crate::Account as AccountTrait;
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![cfg(all(test, feature = "test_e2e"))]
2+
use azure_sdk_storage_blob::prelude::*;
3+
use azure_sdk_storage_core::prelude::*;
4+
use tokio_core::reactor::Core;
5+
6+
#[test]
7+
fn get_account_information() {
8+
let account = std::env::var("STORAGE_ACCOUNT").expect("Set env variable STORAGE_ACCOUNT first!");
9+
let master_key = std::env::var("STORAGE_MASTER_KEY").expect("Set env variable STORAGE_MASTER_KEY first!");
10+
let mut core = Core::new().unwrap();
11+
12+
let client = Client::new(&account, &master_key).unwrap();
13+
14+
// we just test the call works, we don't check the return value since the
15+
// values depend on the Azure storage account
16+
core.run(client.get_account_information().finalize()).unwrap();
17+
}

azure_sdk_storage_blob/Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "azure_sdk_storage_blob"
3-
version = "0.20.0"
3+
version = "0.20.1"
44
description = "Rust wrappers around Microsoft Azure REST APIs - Blob storage crate"
55
readme = "README.md"
66
authors = ["Francesco Cogno <francesco.cogno@outlook.com>", "Max Gortman <mgortman@microsoft.com>", "Dong Liu <doliu@microsoft.com>"]
@@ -15,8 +15,8 @@ categories = ["api-bindings"]
1515
edition = "2018"
1616

1717
[dependencies]
18-
azure_sdk_core = { path="../azure_sdk_core", version = "0.20.0" }
19-
azure_sdk_storage_core = { path="../azure_sdk_storage_core", version = "0.20.0" }
18+
azure_sdk_core = { path="../azure_sdk_core", version = "0.20.1" }
19+
azure_sdk_storage_core = { path="../azure_sdk_storage_core", version = "0.20.1" }
2020
ring = "0.14"
2121
md5 = "0.6"
2222
RustyXML = "0.1"

0 commit comments

Comments
 (0)