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

Commit 080dc59

Browse files
author
Francesco Cogno
authored
Azure storage queue partial implementation (#320)
1 parent 2afd8bd commit 080dc59

27 files changed

+1310
-25
lines changed

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ members = [
77
"azure_sdk_storage_blob",
88
"azure_sdk_storage_core",
99
"azure_sdk_storage_table",
10-
"azure_sdk_cosmos"
10+
"azure_sdk_cosmos",
11+
"azure_sdk_storage_queue"
1112
]

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.43.6"
3+
version = "0.43.7"
44
description = "Rust wrappers around Microsoft Azure REST APIs - Core crate"
55
readme = "README.md"
66
authors = ["Francesco Cogno <[email protected]>", "Max Gortman <[email protected]>", "Dong Liu <[email protected]>"]

azure_sdk_core/src/errors.rs

-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
use crate::{enumerations::ParsingError, range::ParseError};
2-
use base64;
3-
use chrono;
4-
use http;
52
use http::header::ToStrError;
63
use hyper::{self, body, Body, StatusCode};
7-
use serde_json;
8-
use serde_xml_rs;
9-
use std;
104
use std::io::Error as IOError;
115
use std::num;
126
use std::num::ParseIntError;
137
use std::str;
148
use std::str::ParseBoolError;
159
use std::string;
1610
use url::ParseError as URLParseError;
17-
use uuid;
1811
use xml::BuilderError as XMLError;
1912

2013
quick_error! {

azure_sdk_core/src/lib.rs

+48-8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use crate::lease::LeaseId;
3636
use http::request::Builder;
3737
use http::HeaderMap;
3838
use std::collections::HashMap;
39+
use std::convert::TryFrom;
3940
mod stored_access_policy;
4041
pub use self::stored_access_policy::{StoredAccessPolicy, StoredAccessPolicyList};
4142
pub mod prelude;
@@ -486,6 +487,14 @@ pub trait IncludeMetadataSupport {
486487

487488
pub trait IncludeMetadataOption {
488489
fn include_metadata(&self) -> bool;
490+
491+
fn to_uri_parameter(&self) -> Option<&'static str> {
492+
if self.include_metadata() {
493+
Some("include=metadata")
494+
} else {
495+
None
496+
}
497+
}
489498
}
490499

491500
pub trait IncludeCopySupport {
@@ -524,31 +533,31 @@ pub trait IncludeListOptions:
524533

525534
if self.include_metadata() {
526535
if !f_first {
527-
s.push_str(",");
536+
s.push(',');
528537
}
529538
s.push_str("metadata");
530539
f_first = false;
531540
}
532541

533542
if self.include_uncommitted_blobs() {
534543
if !f_first {
535-
s.push_str(",");
544+
s.push(',');
536545
}
537546
s.push_str("uncommittedblobs");
538547
f_first = false;
539548
}
540549

541550
if self.include_copy() {
542551
if !f_first {
543-
s.push_str(",");
552+
s.push(',');
544553
}
545554
s.push_str("copy");
546555
f_first = false;
547556
}
548557

549558
if self.include_deleted() {
550559
if !f_first {
551-
s.push_str(",");
560+
s.push(',');
552561
}
553562
s.push_str("deleted");
554563
}
@@ -935,6 +944,10 @@ pub fn request_id_from_headers(headers: &HeaderMap) -> Result<RequestId, AzureEr
935944
Ok(Uuid::parse_str(request_id)?)
936945
}
937946

947+
pub fn client_request_id_from_headers_optional(headers: &HeaderMap) -> Option<String> {
948+
headers.get_as_str(CLIENT_REQUEST_ID).map(|s| s.to_owned())
949+
}
950+
938951
pub fn content_md5_from_headers_optional(
939952
headers: &HeaderMap,
940953
) -> Result<Option<[u8; 16]>, AzureError> {
@@ -945,6 +958,29 @@ pub fn content_md5_from_headers_optional(
945958
}
946959
}
947960

961+
#[derive(Debug, Clone)]
962+
pub struct CommonStorageResponseHeaders {
963+
pub request_id: RequestId,
964+
pub client_request_id: Option<String>,
965+
pub version: String,
966+
pub date: DateTime<Utc>,
967+
pub server: String,
968+
}
969+
970+
impl TryFrom<&HeaderMap> for CommonStorageResponseHeaders {
971+
type Error = AzureError;
972+
973+
fn try_from(headers: &HeaderMap) -> Result<Self, Self::Error> {
974+
Ok(Self {
975+
request_id: request_id_from_headers(headers)?,
976+
client_request_id: client_request_id_from_headers_optional(headers),
977+
version: version_from_headers(headers)?.to_owned(),
978+
date: date_from_headers(headers)?,
979+
server: server_from_headers(headers)?.to_owned(),
980+
})
981+
}
982+
}
983+
948984
pub fn content_md5_from_headers(headers: &HeaderMap) -> Result<[u8; 16], AzureError> {
949985
let content_md5 = headers
950986
.get(CONTENT_MD5)
@@ -998,10 +1034,8 @@ pub fn content_crc64_from_headers(headers: &HeaderMap) -> Result<[u8; 8], AzureE
9981034
pub fn consistency_from_headers(headers: &HeaderMap) -> Result<Consistency, AzureError> {
9991035
if let Some(content_crc64) = content_crc64_from_headers_optional(headers)? {
10001036
return Ok(Consistency::Crc64(content_crc64));
1001-
} else {
1002-
if let Some(content_md5) = content_md5_from_headers_optional(headers)? {
1003-
return Ok(Consistency::Md5(content_md5));
1004-
}
1037+
} else if let Some(content_md5) = content_md5_from_headers_optional(headers)? {
1038+
return Ok(Consistency::Md5(content_md5));
10051039
}
10061040

10071041
Err(AzureError::HeadersNotFound(vec![
@@ -1045,6 +1079,12 @@ pub fn continuation_token_from_headers_optional(
10451079
}
10461080
}
10471081

1082+
#[inline]
1083+
pub fn utc_date_from_rfc2822(date: &str) -> Result<DateTime<Utc>, AzureError> {
1084+
let date = DateTime::parse_from_rfc2822(date)?;
1085+
Ok(DateTime::from_utc(date.naive_utc(), Utc))
1086+
}
1087+
10481088
pub fn date_from_headers(headers: &HeaderMap) -> Result<DateTime<Utc>, AzureError> {
10491089
let date = headers
10501090
.get(DATE)

azure_sdk_core/src/parsing.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::errors::TraversingError;
2-
use chrono;
32
use xml::Element;
43
use xml::Xml::{CharacterNode, ElementNode};
54

azure_sdk_storage_core/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "azure_sdk_storage_core"
3-
version = "0.44.3"
3+
version = "0.44.4"
44
description = "Rust wrappers around Microsoft Azure REST APIs - Core storage crate"
55
readme = "README.md"
66
authors = ["Francesco Cogno <[email protected]>", "Max Gortman <[email protected]>", "Dong Liu <[email protected]>"]
@@ -15,7 +15,7 @@ categories = ["api-bindings"]
1515
edition = "2018"
1616

1717
[dependencies]
18-
azure_sdk_core = { path = "../azure_sdk_core", version = "0.43.5" }
18+
azure_sdk_core = { path = "../azure_sdk_core", version = "0.43.6" }
1919
ring = "0.16"
2020
base64 = "0.12"
2121
chrono = "0.4"

azure_sdk_storage_core/src/bearer_token_client.rs

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub struct BearerTokenClient<'a> {
1414
hc: hyper::Client<HttpsConnector<hyper::client::HttpConnector>>,
1515
blob_uri: String,
1616
table_uri: String,
17+
queue_uri: String,
1718
}
1819

1920
impl<'a> BearerTokenClient<'a> {
@@ -25,10 +26,12 @@ impl<'a> BearerTokenClient<'a> {
2526
) -> Self {
2627
let blob_uri = format!("https://{}.blob.core.windows.net", account);
2728
let table_uri = format!("https://{}.table.core.windows.net", account);
29+
let queue_uri = format!("https://{}.queue.core.windows.net", account);
2830

2931
Self {
3032
account,
3133
bearer_token,
34+
queue_uri,
3235
hc,
3336
blob_uri,
3437
table_uri,
@@ -90,6 +93,11 @@ impl<'a> Client for BearerTokenClient<'a> {
9093
&self.table_uri
9194
}
9295

96+
#[inline]
97+
fn queue_uri(&self) -> &str {
98+
&self.queue_uri
99+
}
100+
93101
#[inline]
94102
fn perform_request(
95103
&self,

azure_sdk_storage_core/src/client.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ pub trait HttpHeaderAdder {
1313
fn add_headers(&self, builder: ::http::request::Builder) -> ::http::request::Builder;
1414
}
1515

16-
pub trait Client: Send + Sync {
16+
pub trait Client: std::fmt::Debug + Send + Sync {
1717
fn blob_uri(&self) -> &str;
1818
fn table_uri(&self) -> &str;
19+
fn queue_uri(&self) -> &str;
1920

2021
/// Uri scheme + authority e.g. http://myaccount.table.core.windows.net/
2122
#[inline]
@@ -53,6 +54,9 @@ where
5354
fn table_uri(&self) -> &str {
5455
self.as_ref().table_uri()
5556
}
57+
fn queue_uri(&self) -> &str {
58+
self.as_ref().queue_uri()
59+
}
5660

5761
fn perform_request(
5862
&self,
@@ -87,6 +91,9 @@ where
8791
fn table_uri(&self) -> &str {
8892
self.as_ref().table_uri()
8993
}
94+
fn queue_uri(&self) -> &str {
95+
self.as_ref().queue_uri()
96+
}
9097

9198
fn perform_request(
9299
&self,
@@ -133,6 +140,7 @@ pub fn with_azure_sas(account: &str, sas_token: &str) -> KeyClient {
133140
client,
134141
format!("https://{}.blob.core.windows.net", account),
135142
format!("https://{}.table.core.windows.net", account),
143+
format!("https://{}.queue.core.windows.net", account),
136144
)
137145
}
138146

@@ -146,6 +154,7 @@ pub fn with_access_key(account: &str, key: &str) -> KeyClient {
146154
client,
147155
format!("https://{}.blob.core.windows.net", account),
148156
format!("https://{}.table.core.windows.net", account),
157+
format!("https://{}.queue.core.windows.net", account),
149158
)
150159
}
151160

@@ -167,6 +176,7 @@ pub fn from_connection_string(connection_string: &str) -> Result<KeyClient, Azur
167176
client,
168177
format!("https://{}.blob.core.windows.net", account),
169178
format!("https://{}.table.core.windows.net", account),
179+
format!("https://{}.queue.core.windows.net", account),
170180
))
171181
}
172182
ConnectionString {
@@ -180,6 +190,7 @@ pub fn from_connection_string(connection_string: &str) -> Result<KeyClient, Azur
180190
client,
181191
format!("https://{}.blob.core.windows.net", account),
182192
format!("https://{}.table.core.windows.net", account),
193+
format!("https://{}.queue.core.windows.net", account),
183194
)),
184195
ConnectionString {
185196
account_name: Some(account),
@@ -192,6 +203,7 @@ pub fn from_connection_string(connection_string: &str) -> Result<KeyClient, Azur
192203
client,
193204
format!("https://{}.blob.core.windows.net", account),
194205
format!("https://{}.table.core.windows.net", account),
206+
format!("https://{}.queue.core.windows.net", account),
195207
)),
196208
_ => {
197209
Err(AzureError::GenericErrorWithText(
@@ -219,6 +231,8 @@ pub fn with_emulator(blob_storage_url: &Url, table_storage_url: &Url) -> KeyClie
219231
debug!("blob_uri == {}", blob_uri);
220232
let table_uri = format!("{}devstoreaccount1", table_storage_url.as_str());
221233
debug!("table_uri == {}", table_uri);
234+
let queue_uri = format!("{}devstoreaccount1", table_storage_url.as_str());
235+
debug!("queue_uri == {}", queue_uri);
222236

223237
KeyClient::new(
224238
"devstoreaccount1".to_owned(),
@@ -228,5 +242,6 @@ pub fn with_emulator(blob_storage_url: &Url, table_storage_url: &Url) -> KeyClie
228242
client,
229243
blob_uri,
230244
table_uri,
245+
queue_uri,
231246
)
232247
}

azure_sdk_storage_core/src/key_client.rs

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub struct KeyClient {
1414
hc: hyper::Client<HttpsConnector<hyper::client::HttpConnector>>,
1515
blob_uri: String,
1616
table_uri: String,
17+
queue_uri: String,
1718
}
1819

1920
pub(crate) fn get_sas_token_parms(sas_token: &str) -> Vec<(String, String)> {
@@ -37,6 +38,7 @@ impl KeyClient {
3738
hc: hyper::Client<HttpsConnector<hyper::client::HttpConnector>>,
3839
blob_uri: String,
3940
table_uri: String,
41+
queue_uri: String,
4042
) -> Self {
4143
Self {
4244
account,
@@ -45,6 +47,7 @@ impl KeyClient {
4547
hc,
4648
blob_uri,
4749
table_uri,
50+
queue_uri,
4851
}
4952
}
5053

@@ -67,6 +70,11 @@ impl Client for KeyClient {
6770
&self.table_uri
6871
}
6972

73+
#[inline]
74+
fn queue_uri(&self) -> &str {
75+
&self.queue_uri
76+
}
77+
7078
fn perform_request(
7179
&self,
7280
uri: &str,

azure_sdk_storage_core/src/rest_client.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ fn canonicalize_header(h: &HeaderMap) -> String {
406406
.filter(|(k, _v)| k.as_str().starts_with("x-ms"))
407407
.map(|(k, _)| k.as_str())
408408
.collect::<Vec<_>>();
409-
v_headers.sort();
409+
v_headers.sort_unstable();
410410

411411
let mut can = String::new();
412412

@@ -434,7 +434,7 @@ fn canonicalized_resource<CE: ClientEndpoint>(client_endpoint: &CE, u: &url::Url
434434
{
435435
let mut path = String::new();
436436
for p in paths {
437-
path.push_str("/");
437+
path.push('/');
438438
path.push_str(&*p);
439439
}
440440

0 commit comments

Comments
 (0)