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

Commit

Permalink
Azure storage queue partial implementation (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
Francesco Cogno authored Sep 29, 2020
1 parent 2afd8bd commit 080dc59
Show file tree
Hide file tree
Showing 27 changed files with 1,310 additions and 25 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ members = [
"azure_sdk_storage_blob",
"azure_sdk_storage_core",
"azure_sdk_storage_table",
"azure_sdk_cosmos"
"azure_sdk_cosmos",
"azure_sdk_storage_queue"
]
2 changes: 1 addition & 1 deletion azure_sdk_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "azure_sdk_core"
version = "0.43.6"
version = "0.43.7"
description = "Rust wrappers around Microsoft Azure REST APIs - Core crate"
readme = "README.md"
authors = ["Francesco Cogno <francesco.cogno@outlook.com>", "Max Gortman <mgortman@microsoft.com>", "Dong Liu <doliu@microsoft.com>"]
Expand Down
7 changes: 0 additions & 7 deletions azure_sdk_core/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
use crate::{enumerations::ParsingError, range::ParseError};
use base64;
use chrono;
use http;
use http::header::ToStrError;
use hyper::{self, body, Body, StatusCode};
use serde_json;
use serde_xml_rs;
use std;
use std::io::Error as IOError;
use std::num;
use std::num::ParseIntError;
use std::str;
use std::str::ParseBoolError;
use std::string;
use url::ParseError as URLParseError;
use uuid;
use xml::BuilderError as XMLError;

quick_error! {
Expand Down
56 changes: 48 additions & 8 deletions azure_sdk_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use crate::lease::LeaseId;
use http::request::Builder;
use http::HeaderMap;
use std::collections::HashMap;
use std::convert::TryFrom;
mod stored_access_policy;
pub use self::stored_access_policy::{StoredAccessPolicy, StoredAccessPolicyList};
pub mod prelude;
Expand Down Expand Up @@ -486,6 +487,14 @@ pub trait IncludeMetadataSupport {

pub trait IncludeMetadataOption {
fn include_metadata(&self) -> bool;

fn to_uri_parameter(&self) -> Option<&'static str> {
if self.include_metadata() {
Some("include=metadata")
} else {
None
}
}
}

pub trait IncludeCopySupport {
Expand Down Expand Up @@ -524,31 +533,31 @@ pub trait IncludeListOptions:

if self.include_metadata() {
if !f_first {
s.push_str(",");
s.push(',');
}
s.push_str("metadata");
f_first = false;
}

if self.include_uncommitted_blobs() {
if !f_first {
s.push_str(",");
s.push(',');
}
s.push_str("uncommittedblobs");
f_first = false;
}

if self.include_copy() {
if !f_first {
s.push_str(",");
s.push(',');
}
s.push_str("copy");
f_first = false;
}

if self.include_deleted() {
if !f_first {
s.push_str(",");
s.push(',');
}
s.push_str("deleted");
}
Expand Down Expand Up @@ -935,6 +944,10 @@ pub fn request_id_from_headers(headers: &HeaderMap) -> Result<RequestId, AzureEr
Ok(Uuid::parse_str(request_id)?)
}

pub fn client_request_id_from_headers_optional(headers: &HeaderMap) -> Option<String> {
headers.get_as_str(CLIENT_REQUEST_ID).map(|s| s.to_owned())
}

pub fn content_md5_from_headers_optional(
headers: &HeaderMap,
) -> Result<Option<[u8; 16]>, AzureError> {
Expand All @@ -945,6 +958,29 @@ pub fn content_md5_from_headers_optional(
}
}

#[derive(Debug, Clone)]
pub struct CommonStorageResponseHeaders {
pub request_id: RequestId,
pub client_request_id: Option<String>,
pub version: String,
pub date: DateTime<Utc>,
pub server: String,
}

impl TryFrom<&HeaderMap> for CommonStorageResponseHeaders {
type Error = AzureError;

fn try_from(headers: &HeaderMap) -> Result<Self, Self::Error> {
Ok(Self {
request_id: request_id_from_headers(headers)?,
client_request_id: client_request_id_from_headers_optional(headers),
version: version_from_headers(headers)?.to_owned(),
date: date_from_headers(headers)?,
server: server_from_headers(headers)?.to_owned(),
})
}
}

pub fn content_md5_from_headers(headers: &HeaderMap) -> Result<[u8; 16], AzureError> {
let content_md5 = headers
.get(CONTENT_MD5)
Expand Down Expand Up @@ -998,10 +1034,8 @@ pub fn content_crc64_from_headers(headers: &HeaderMap) -> Result<[u8; 8], AzureE
pub fn consistency_from_headers(headers: &HeaderMap) -> Result<Consistency, AzureError> {
if let Some(content_crc64) = content_crc64_from_headers_optional(headers)? {
return Ok(Consistency::Crc64(content_crc64));
} else {
if let Some(content_md5) = content_md5_from_headers_optional(headers)? {
return Ok(Consistency::Md5(content_md5));
}
} else if let Some(content_md5) = content_md5_from_headers_optional(headers)? {
return Ok(Consistency::Md5(content_md5));
}

Err(AzureError::HeadersNotFound(vec![
Expand Down Expand Up @@ -1045,6 +1079,12 @@ pub fn continuation_token_from_headers_optional(
}
}

#[inline]
pub fn utc_date_from_rfc2822(date: &str) -> Result<DateTime<Utc>, AzureError> {
let date = DateTime::parse_from_rfc2822(date)?;
Ok(DateTime::from_utc(date.naive_utc(), Utc))
}

pub fn date_from_headers(headers: &HeaderMap) -> Result<DateTime<Utc>, AzureError> {
let date = headers
.get(DATE)
Expand Down
1 change: 0 additions & 1 deletion azure_sdk_core/src/parsing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::errors::TraversingError;
use chrono;
use xml::Element;
use xml::Xml::{CharacterNode, ElementNode};

Expand Down
4 changes: 2 additions & 2 deletions azure_sdk_storage_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "azure_sdk_storage_core"
version = "0.44.3"
version = "0.44.4"
description = "Rust wrappers around Microsoft Azure REST APIs - Core storage crate"
readme = "README.md"
authors = ["Francesco Cogno <francesco.cogno@outlook.com>", "Max Gortman <mgortman@microsoft.com>", "Dong Liu <doliu@microsoft.com>"]
Expand All @@ -15,7 +15,7 @@ categories = ["api-bindings"]
edition = "2018"

[dependencies]
azure_sdk_core = { path = "../azure_sdk_core", version = "0.43.5" }
azure_sdk_core = { path = "../azure_sdk_core", version = "0.43.6" }
ring = "0.16"
base64 = "0.12"
chrono = "0.4"
Expand Down
8 changes: 8 additions & 0 deletions azure_sdk_storage_core/src/bearer_token_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct BearerTokenClient<'a> {
hc: hyper::Client<HttpsConnector<hyper::client::HttpConnector>>,
blob_uri: String,
table_uri: String,
queue_uri: String,
}

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

Self {
account,
bearer_token,
queue_uri,
hc,
blob_uri,
table_uri,
Expand Down Expand Up @@ -90,6 +93,11 @@ impl<'a> Client for BearerTokenClient<'a> {
&self.table_uri
}

#[inline]
fn queue_uri(&self) -> &str {
&self.queue_uri
}

#[inline]
fn perform_request(
&self,
Expand Down
17 changes: 16 additions & 1 deletion azure_sdk_storage_core/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ pub trait HttpHeaderAdder {
fn add_headers(&self, builder: ::http::request::Builder) -> ::http::request::Builder;
}

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

/// Uri scheme + authority e.g. http://myaccount.table.core.windows.net/
#[inline]
Expand Down Expand Up @@ -53,6 +54,9 @@ where
fn table_uri(&self) -> &str {
self.as_ref().table_uri()
}
fn queue_uri(&self) -> &str {
self.as_ref().queue_uri()
}

fn perform_request(
&self,
Expand Down Expand Up @@ -87,6 +91,9 @@ where
fn table_uri(&self) -> &str {
self.as_ref().table_uri()
}
fn queue_uri(&self) -> &str {
self.as_ref().queue_uri()
}

fn perform_request(
&self,
Expand Down Expand Up @@ -133,6 +140,7 @@ pub fn with_azure_sas(account: &str, sas_token: &str) -> KeyClient {
client,
format!("https://{}.blob.core.windows.net", account),
format!("https://{}.table.core.windows.net", account),
format!("https://{}.queue.core.windows.net", account),
)
}

Expand All @@ -146,6 +154,7 @@ pub fn with_access_key(account: &str, key: &str) -> KeyClient {
client,
format!("https://{}.blob.core.windows.net", account),
format!("https://{}.table.core.windows.net", account),
format!("https://{}.queue.core.windows.net", account),
)
}

Expand All @@ -167,6 +176,7 @@ pub fn from_connection_string(connection_string: &str) -> Result<KeyClient, Azur
client,
format!("https://{}.blob.core.windows.net", account),
format!("https://{}.table.core.windows.net", account),
format!("https://{}.queue.core.windows.net", account),
))
}
ConnectionString {
Expand All @@ -180,6 +190,7 @@ pub fn from_connection_string(connection_string: &str) -> Result<KeyClient, Azur
client,
format!("https://{}.blob.core.windows.net", account),
format!("https://{}.table.core.windows.net", account),
format!("https://{}.queue.core.windows.net", account),
)),
ConnectionString {
account_name: Some(account),
Expand All @@ -192,6 +203,7 @@ pub fn from_connection_string(connection_string: &str) -> Result<KeyClient, Azur
client,
format!("https://{}.blob.core.windows.net", account),
format!("https://{}.table.core.windows.net", account),
format!("https://{}.queue.core.windows.net", account),
)),
_ => {
Err(AzureError::GenericErrorWithText(
Expand Down Expand Up @@ -219,6 +231,8 @@ pub fn with_emulator(blob_storage_url: &Url, table_storage_url: &Url) -> KeyClie
debug!("blob_uri == {}", blob_uri);
let table_uri = format!("{}devstoreaccount1", table_storage_url.as_str());
debug!("table_uri == {}", table_uri);
let queue_uri = format!("{}devstoreaccount1", table_storage_url.as_str());
debug!("queue_uri == {}", queue_uri);

KeyClient::new(
"devstoreaccount1".to_owned(),
Expand All @@ -228,5 +242,6 @@ pub fn with_emulator(blob_storage_url: &Url, table_storage_url: &Url) -> KeyClie
client,
blob_uri,
table_uri,
queue_uri,
)
}
8 changes: 8 additions & 0 deletions azure_sdk_storage_core/src/key_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct KeyClient {
hc: hyper::Client<HttpsConnector<hyper::client::HttpConnector>>,
blob_uri: String,
table_uri: String,
queue_uri: String,
}

pub(crate) fn get_sas_token_parms(sas_token: &str) -> Vec<(String, String)> {
Expand All @@ -37,6 +38,7 @@ impl KeyClient {
hc: hyper::Client<HttpsConnector<hyper::client::HttpConnector>>,
blob_uri: String,
table_uri: String,
queue_uri: String,
) -> Self {
Self {
account,
Expand All @@ -45,6 +47,7 @@ impl KeyClient {
hc,
blob_uri,
table_uri,
queue_uri,
}
}

Expand All @@ -67,6 +70,11 @@ impl Client for KeyClient {
&self.table_uri
}

#[inline]
fn queue_uri(&self) -> &str {
&self.queue_uri
}

fn perform_request(
&self,
uri: &str,
Expand Down
4 changes: 2 additions & 2 deletions azure_sdk_storage_core/src/rest_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ fn canonicalize_header(h: &HeaderMap) -> String {
.filter(|(k, _v)| k.as_str().starts_with("x-ms"))
.map(|(k, _)| k.as_str())
.collect::<Vec<_>>();
v_headers.sort();
v_headers.sort_unstable();

let mut can = String::new();

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

Expand Down
Loading

0 comments on commit 080dc59

Please sign in to comment.