Коммит
1e5be2a780
|
@ -28,7 +28,9 @@ use self::headers::{
|
|||
BLOB_ACCESS_TIER, BLOB_CONTENT_LENGTH, BLOB_SEQUENCE_NUMBER, CLIENT_REQUEST_ID, CONTENT_MD5, DELETE_SNAPSHOTS, DELETE_TYPE_PERMANENT,
|
||||
LEASE_BREAK_PERIOD, LEASE_DURATION, LEASE_ID, LEASE_TIME, PROPOSED_LEASE_ID, REQUEST_ID, REQUEST_SERVER_ENCRYPTED,
|
||||
};
|
||||
use hyper::header::{CACHE_CONTROL, CONTENT_ENCODING, CONTENT_LANGUAGE, CONTENT_LENGTH, CONTENT_TYPE, DATE, ETAG, LAST_MODIFIED, RANGE};
|
||||
use hyper::header::{
|
||||
HeaderName, CACHE_CONTROL, CONTENT_ENCODING, CONTENT_LANGUAGE, CONTENT_LENGTH, CONTENT_TYPE, DATE, ETAG, LAST_MODIFIED, RANGE,
|
||||
};
|
||||
use uuid::Uuid;
|
||||
pub type RequestId = Uuid;
|
||||
use azure::core::errors::{AzureError, TraversingError};
|
||||
|
@ -48,6 +50,34 @@ define_encode_set! {
|
|||
}
|
||||
}
|
||||
|
||||
macro_rules! response_from_headers {
|
||||
($cn:ident, $($fh:ident -> $na:ident: $typ:ty),+) => {
|
||||
use azure::core::errors::AzureError;
|
||||
use http::HeaderMap;
|
||||
use azure::core::{
|
||||
$($fh,)+
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct $cn {
|
||||
$(pub $na: $typ),+,
|
||||
}
|
||||
|
||||
impl $cn {
|
||||
pub(crate) fn from_headers(headers: &HeaderMap) -> Result<$cn, AzureError> {
|
||||
$(
|
||||
let $na = $fh(headers)?;
|
||||
)+
|
||||
|
||||
Ok($cn {
|
||||
$($na,)+
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Yes;
|
||||
#[derive(Debug)]
|
||||
|
@ -299,7 +329,7 @@ pub trait DelimiterOption<'a> {
|
|||
fn delimiter(&self) -> Option<&'a str>;
|
||||
|
||||
fn to_uri_parameter(&self) -> Option<String> {
|
||||
if let Some(_) = self.delimiter() {
|
||||
if self.delimiter().is_some() {
|
||||
Some("delimiter".to_owned())
|
||||
} else {
|
||||
None
|
||||
|
@ -374,12 +404,12 @@ pub trait IncludeListOptions:
|
|||
{
|
||||
fn to_uri_parameter(&self) -> Option<String> {
|
||||
let mut s = String::new();
|
||||
let mut f_first = true;
|
||||
|
||||
if self.include_snapshots() {
|
||||
let mut f_first = if self.include_snapshots() {
|
||||
s.push_str("snapshots");
|
||||
f_first = false;
|
||||
}
|
||||
false
|
||||
} else {
|
||||
true
|
||||
};
|
||||
|
||||
if self.include_metadata() {
|
||||
if !f_first {
|
||||
|
@ -412,7 +442,7 @@ pub trait IncludeListOptions:
|
|||
s.push_str("deleted");
|
||||
}
|
||||
|
||||
if s.len() > 0 {
|
||||
if s.is_empty() {
|
||||
Some(format!("include={}", s))
|
||||
} else {
|
||||
None
|
||||
|
@ -769,8 +799,10 @@ pub(crate) fn last_modified_from_headers_optional(headers: &HeaderMap) -> Result
|
|||
pub(crate) fn last_modified_from_headers(headers: &HeaderMap) -> Result<DateTime<Utc>, AzureError> {
|
||||
let last_modified = headers
|
||||
.get(LAST_MODIFIED)
|
||||
.ok_or_else(|| AzureError::HeaderNotFound(LAST_MODIFIED.as_str().to_owned()))?
|
||||
.to_str()?;
|
||||
.ok_or_else(|| {
|
||||
static LM: HeaderName = LAST_MODIFIED;
|
||||
AzureError::HeaderNotFound(LM.as_str().to_owned())
|
||||
})?.to_str()?;
|
||||
let last_modified = DateTime::parse_from_rfc2822(last_modified)?;
|
||||
let last_modified = DateTime::from_utc(last_modified.naive_utc(), Utc);
|
||||
|
||||
|
@ -781,8 +813,10 @@ pub(crate) fn last_modified_from_headers(headers: &HeaderMap) -> Result<DateTime
|
|||
pub(crate) fn date_from_headers(headers: &HeaderMap) -> Result<DateTime<Utc>, AzureError> {
|
||||
let date = headers
|
||||
.get(DATE)
|
||||
.ok_or_else(|| AzureError::HeaderNotFound(DATE.as_str().to_owned()))?
|
||||
.to_str()?;
|
||||
.ok_or_else(|| {
|
||||
static D: HeaderName = DATE;
|
||||
AzureError::HeaderNotFound(D.as_str().to_owned())
|
||||
})?.to_str()?;
|
||||
let date = DateTime::parse_from_rfc2822(date)?;
|
||||
let date = DateTime::from_utc(date.naive_utc(), Utc);
|
||||
|
||||
|
@ -801,8 +835,10 @@ pub(crate) fn etag_from_headers_optional(headers: &HeaderMap) -> Result<Option<S
|
|||
pub(crate) fn etag_from_headers(headers: &HeaderMap) -> Result<String, AzureError> {
|
||||
let etag = headers
|
||||
.get(ETAG)
|
||||
.ok_or_else(|| AzureError::HeaderNotFound(ETAG.as_str().to_owned()))?
|
||||
.to_str()?
|
||||
.ok_or_else(|| {
|
||||
static E: HeaderName = ETAG;
|
||||
AzureError::HeaderNotFound(E.as_str().to_owned())
|
||||
})?.to_str()?
|
||||
.to_owned();
|
||||
|
||||
trace!("etag == {:?}", etag);
|
||||
|
|
|
@ -18,6 +18,10 @@ impl Range {
|
|||
pub fn len(&self) -> u64 {
|
||||
self.end - self.start
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.end == self.start
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
|
|
@ -121,7 +121,8 @@ impl Client {
|
|||
&format!("dbs/{}/colls", database_name),
|
||||
hyper::Method::GET,
|
||||
ResourceType::Collections,
|
||||
).body(hyper::Body::empty())?;
|
||||
)
|
||||
.body(hyper::Body::empty())?;
|
||||
|
||||
trace!("request prepared");
|
||||
|
||||
|
@ -231,7 +232,8 @@ impl Client {
|
|||
&format!("dbs/{}/colls/{}", database_name, collection_name),
|
||||
hyper::Method::GET,
|
||||
ResourceType::Collections,
|
||||
).body(hyper::Body::empty())?;
|
||||
)
|
||||
.body(hyper::Body::empty())?;
|
||||
|
||||
trace!("request prepared");
|
||||
|
||||
|
@ -314,7 +316,8 @@ impl Client {
|
|||
&format!("dbs/{}/colls/{}", database_name, collection_name),
|
||||
hyper::Method::DELETE,
|
||||
ResourceType::Collections,
|
||||
).body(hyper::Body::empty())?;
|
||||
)
|
||||
.body(hyper::Body::empty())?;
|
||||
|
||||
trace!("request prepared");
|
||||
|
||||
|
@ -351,7 +354,8 @@ impl Client {
|
|||
&format!("dbs/{}/colls", database_name),
|
||||
hyper::Method::PUT,
|
||||
ResourceType::Collections,
|
||||
).body(collection_serialized.into())?;
|
||||
)
|
||||
.body(collection_serialized.into())?;
|
||||
|
||||
trace!("request prepared");
|
||||
|
||||
|
@ -557,7 +561,7 @@ impl Client {
|
|||
let resource_link = generate_resource_link(&uri_path);
|
||||
generate_authorization(&self.auth_token, &http_method, resource_type, resource_link, &time)
|
||||
};
|
||||
self.prepare_request_with_signature(uri_path, http_method, time, auth)
|
||||
self.prepare_request_with_signature(uri_path, http_method, &time, &auth)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -571,26 +575,20 @@ impl Client {
|
|||
let time = format!("{}", chrono::Utc::now().format(TIME_FORMAT));
|
||||
|
||||
let sig = { generate_authorization(&self.auth_token, &http_method, resource_type, resource_link, &time) };
|
||||
self.prepare_request_with_signature(uri_path, http_method, time, sig)
|
||||
self.prepare_request_with_signature(uri_path, http_method, &time, &sig)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn prepare_request_with_signature(
|
||||
&self,
|
||||
uri_path: &str,
|
||||
http_method: hyper::Method,
|
||||
time: String,
|
||||
signature: String,
|
||||
) -> RequestBuilder {
|
||||
fn prepare_request_with_signature(&self, uri_path: &str, http_method: hyper::Method, time: &str, signature: &str) -> RequestBuilder {
|
||||
trace!("prepare_request::auth == {:?}", signature);
|
||||
let uri = format!("https://{}.documents.azure.com/{}", self.auth_token.account(), uri_path);
|
||||
let mut request = hyper::Request::builder();
|
||||
request
|
||||
.method(http_method)
|
||||
.uri(uri)
|
||||
.header(HEADER_DATE, time.as_str())
|
||||
.header(HEADER_DATE, time)
|
||||
.header(HEADER_VERSION, HeaderValue::from_static(AZURE_VERSION))
|
||||
.header(header::AUTHORIZATION, signature.as_str());
|
||||
.header(header::AUTHORIZATION, signature);
|
||||
request
|
||||
}
|
||||
}
|
||||
|
@ -725,7 +723,8 @@ mon, 01 jan 1900 01:00:00 gmt
|
|||
"mindflavor".to_owned(),
|
||||
TokenType::Master,
|
||||
"8F8xXXOptJxkblM1DBXW7a6NMI5oE8NnwPGYBmwxLCKfejOK7B7yhcCHMGvN3PBrlMLIOeol1Hv9RCdzAZR5sg==",
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let ret = generate_authorization(
|
||||
&auth_token,
|
||||
|
@ -750,7 +749,8 @@ mon, 01 jan 1900 01:00:00 gmt
|
|||
"mindflavor".to_owned(),
|
||||
TokenType::Master,
|
||||
"dsZQi3KtZmCv1ljt3VNWNm7sQUF1y5rJfC6kv5JiwvW0EndXdDku/dkKBp8/ufDToSxL",
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let ret = generate_authorization(&auth_token, &hyper::Method::GET, ResourceType::Databases, "dbs/ToDoList", &time);
|
||||
|
||||
|
|
|
@ -356,7 +356,7 @@ impl<'a> BlobStreamBuilder<'a, Yes, Yes, Yes> {
|
|||
|
||||
let snapshot = self.snapshot.to_owned();
|
||||
let timeout = self.timeout.to_owned();
|
||||
let lease_id = self.lease_id.map(|v| v.clone());
|
||||
let lease_id = self.lease_id.cloned();
|
||||
let client_request_id = self.client_request_id.map(|v| v.to_owned());
|
||||
let increment = self.increment;
|
||||
|
||||
|
|
|
@ -190,7 +190,7 @@ impl Blob {
|
|||
copy_status_description,
|
||||
incremental_copy,
|
||||
server_encrypted,
|
||||
access_tier_inferred: access_tier_inferred,
|
||||
access_tier_inferred,
|
||||
access_tier_change_time,
|
||||
deleted_time,
|
||||
remaining_retention_days,
|
||||
|
@ -221,20 +221,24 @@ impl Blob {
|
|||
|
||||
let content_length = h
|
||||
.get(header::CONTENT_LENGTH)
|
||||
.ok_or_else(|| AzureError::HeaderNotFound(header::CONTENT_LENGTH.as_str().to_owned()))?
|
||||
.to_str()?
|
||||
.ok_or_else(|| {
|
||||
static CL: header::HeaderName = header::CONTENT_LENGTH;
|
||||
AzureError::HeaderNotFound(CL.as_str().to_owned())
|
||||
})?.to_str()?
|
||||
.parse::<u64>()?;
|
||||
trace!("content_length == {:?}", content_length);
|
||||
|
||||
let last_modified = h
|
||||
.get_as_str(header::LAST_MODIFIED)
|
||||
.ok_or_else(|| AzureError::HeaderNotFound(header::LAST_MODIFIED.as_str().to_owned()))?;
|
||||
let last_modified = h.get_as_str(header::LAST_MODIFIED).ok_or_else(|| {
|
||||
static LM: header::HeaderName = header::LAST_MODIFIED;
|
||||
AzureError::HeaderNotFound(LM.as_str().to_owned())
|
||||
})?;
|
||||
let last_modified = from_azure_time(last_modified)?;
|
||||
trace!("last_modified == {:?}", last_modified);
|
||||
|
||||
let etag = h
|
||||
.get_as_string(header::ETAG)
|
||||
.ok_or_else(|| AzureError::HeaderNotFound(header::ETAG.as_str().to_owned()))?;
|
||||
let etag = h.get_as_string(header::ETAG).ok_or_else(|| {
|
||||
static E: header::HeaderName = header::ETAG;
|
||||
AzureError::HeaderNotFound(E.as_str().to_owned())
|
||||
})?;
|
||||
trace!("etag == {:?}", etag);
|
||||
|
||||
let x_ms_blob_sequence_number = h.get_as_u64(BLOB_SEQUENCE_NUMBER);
|
||||
|
|
|
@ -310,7 +310,7 @@ impl<'a> AcquireBlobLeaseBuilder<'a, Yes, Yes, Yes> {
|
|||
|
||||
let req = self.client().perform_request(
|
||||
&uri,
|
||||
Method::PUT,
|
||||
&Method::PUT,
|
||||
|ref mut request| {
|
||||
request.header(LEASE_ACTION, "acquire");
|
||||
LeaseDurationRequired::add_header(&self, request);
|
||||
|
|
|
@ -262,7 +262,7 @@ impl<'a> BreakBlobLeaseBuilder<'a, Yes, Yes, Yes> {
|
|||
|
||||
let req = self.client().perform_request(
|
||||
&uri,
|
||||
Method::PUT,
|
||||
&Method::PUT,
|
||||
|ref mut request| {
|
||||
request.header(LEASE_ACTION, "break");
|
||||
LeaseBreakPeriodRequired::add_header(&self, request);
|
||||
|
|
|
@ -335,7 +335,7 @@ impl<'a> ChangeBlobLeaseBuilder<'a, Yes, Yes, Yes, Yes> {
|
|||
|
||||
let req = self.client().perform_request(
|
||||
&uri,
|
||||
Method::PUT,
|
||||
&Method::PUT,
|
||||
|ref mut request| {
|
||||
LeaseIdRequired::add_header(&self, request);
|
||||
request.header(LEASE_ACTION, "change");
|
||||
|
|
|
@ -464,7 +464,7 @@ impl<'a> ClearPageBuilder<'a, Yes, Yes, Yes> {
|
|||
|
||||
let req = self.client().perform_request(
|
||||
&uri,
|
||||
Method::PUT,
|
||||
&Method::PUT,
|
||||
|ref mut request| {
|
||||
BA512RangeRequired::add_header(&self, request);
|
||||
request.header(PAGE_WRITE, "clear");
|
||||
|
|
|
@ -314,7 +314,7 @@ impl<'a> DeleteBlobBuilder<'a, Yes, Yes, Yes> {
|
|||
|
||||
let req = self.client().perform_request(
|
||||
&uri,
|
||||
Method::DELETE,
|
||||
&Method::DELETE,
|
||||
|ref mut request| {
|
||||
DeleteSnapshotsMethodRequired::add_header(&self, request);
|
||||
LeaseIdOption::add_header(&self, request);
|
||||
|
|
|
@ -309,7 +309,7 @@ impl<'a> DeleteBlobSnapshotBuilder<'a, Yes, Yes, Yes> {
|
|||
|
||||
let req = self.client().perform_request(
|
||||
&uri,
|
||||
Method::DELETE,
|
||||
&Method::DELETE,
|
||||
|ref mut request| {
|
||||
LeaseIdOption::add_header(&self, request);
|
||||
ClientRequestIdOption::add_header(&self, request);
|
||||
|
|
|
@ -336,7 +336,7 @@ impl<'a> GetBlobBuilder<'a, Yes, Yes> {
|
|||
|
||||
let req = self.client().perform_request(
|
||||
&uri,
|
||||
Method::GET,
|
||||
&Method::GET,
|
||||
|ref mut request| {
|
||||
if let Some(r) = self.range() {
|
||||
LeaseIdOption::add_header(&self, request);
|
||||
|
|
|
@ -314,7 +314,7 @@ impl<'a> GetBlockListBuilder<'a, Yes, Yes, Yes> {
|
|||
|
||||
let req = self.client().perform_request(
|
||||
&uri,
|
||||
Method::GET,
|
||||
&Method::GET,
|
||||
|ref mut request| {
|
||||
LeaseIdOption::add_header(&self, request);
|
||||
ClientRequestIdOption::add_header(&self, request);
|
||||
|
|
|
@ -543,7 +543,7 @@ impl<'a> ListBlobBuilder<'a, Yes> {
|
|||
|
||||
trace!("list blob uri = {}", uri);
|
||||
|
||||
let req = self.client().perform_request(&uri, Method::GET, |_| {}, None);
|
||||
let req = self.client().perform_request(&uri, &Method::GET, |_| {}, None);
|
||||
|
||||
done(req).from_err().and_then(move |future_response| {
|
||||
check_status_extract_headers_and_body_as_string(future_response, StatusCode::OK)
|
||||
|
|
|
@ -518,7 +518,7 @@ impl<'a> PutAppendBlobBuilder<'a, Yes, Yes> {
|
|||
|
||||
let req = self.client().perform_request(
|
||||
&uri,
|
||||
Method::PUT,
|
||||
&Method::PUT,
|
||||
|ref mut request| {
|
||||
ContentTypeOption::add_header(&self, request);
|
||||
ContentEncodingOption::add_header(&self, request);
|
||||
|
@ -536,6 +536,6 @@ impl<'a> PutAppendBlobBuilder<'a, Yes, Yes> {
|
|||
done(req)
|
||||
.from_err()
|
||||
.and_then(move |response| check_status_extract_headers_and_body(response, StatusCode::CREATED))
|
||||
.and_then(move |(headers, _body)| done(PutBlobResponse::from_headers(&headers)).and_then(|pbbr| ok(pbbr)))
|
||||
.and_then(move |(headers, _body)| done(PutBlobResponse::from_headers(&headers)).and_then(ok))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -679,7 +679,7 @@ impl<'a> PutBlockBlobBuilder<'a, Yes, Yes, Yes> {
|
|||
|
||||
let req = self.client().perform_request(
|
||||
&uri,
|
||||
Method::PUT,
|
||||
&Method::PUT,
|
||||
|ref mut request| {
|
||||
ContentTypeOption::add_header(&self, request);
|
||||
ContentEncodingOption::add_header(&self, request);
|
||||
|
@ -698,6 +698,6 @@ impl<'a> PutBlockBlobBuilder<'a, Yes, Yes, Yes> {
|
|||
done(req)
|
||||
.from_err()
|
||||
.and_then(move |response| check_status_extract_headers_and_body(response, StatusCode::CREATED))
|
||||
.and_then(move |(headers, _body)| done(PutBlockBlobResponse::from_headers(&headers)).and_then(|pbbr| ok(pbbr)))
|
||||
.and_then(move |(headers, _body)| done(PutBlockBlobResponse::from_headers(&headers)).and_then(ok))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -438,7 +438,7 @@ impl<'a> PutBlockBuilder<'a, Yes, Yes, Yes, Yes> {
|
|||
|
||||
let req = self.client().perform_request(
|
||||
&uri,
|
||||
Method::PUT,
|
||||
&Method::PUT,
|
||||
|ref mut request| {
|
||||
ContentMD5Option::add_header(&self, request);
|
||||
LeaseIdOption::add_header(&self, request);
|
||||
|
|
|
@ -681,7 +681,7 @@ where
|
|||
|
||||
let req = self.client().perform_request(
|
||||
&uri,
|
||||
Method::PUT,
|
||||
&Method::PUT,
|
||||
|ref mut request| {
|
||||
ContentTypeOption::add_header(&self, request);
|
||||
ContentEncodingOption::add_header(&self, request);
|
||||
|
@ -699,6 +699,6 @@ where
|
|||
done(req)
|
||||
.from_err()
|
||||
.and_then(move |response| check_status_extract_headers_and_body(response, StatusCode::CREATED))
|
||||
.and_then(move |(headers, _body)| done(PutBlockListResponse::from_headers(&headers)).and_then(|pbbr| ok(pbbr)))
|
||||
.and_then(move |(headers, _body)| done(PutBlockListResponse::from_headers(&headers)).and_then(ok))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -761,7 +761,7 @@ impl<'a> PutPageBlobBuilder<'a, Yes, Yes, Yes> {
|
|||
|
||||
let req = self.client().perform_request(
|
||||
&uri,
|
||||
Method::PUT,
|
||||
&Method::PUT,
|
||||
|ref mut request| {
|
||||
PageBlobLengthRequired::add_header(&self, request);
|
||||
SequenceNumberOption::add_header(&self, request);
|
||||
|
@ -782,6 +782,6 @@ impl<'a> PutPageBlobBuilder<'a, Yes, Yes, Yes> {
|
|||
done(req)
|
||||
.from_err()
|
||||
.and_then(move |response| check_status_extract_headers_and_body(response, StatusCode::CREATED))
|
||||
.and_then(move |(headers, _body)| done(PutBlobResponse::from_headers(&headers)).and_then(|pbbr| ok(pbbr)))
|
||||
.and_then(move |(headers, _body)| done(PutBlobResponse::from_headers(&headers)).and_then(ok))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -262,7 +262,7 @@ impl<'a> ReleaseBlobLeaseBuilder<'a, Yes, Yes, Yes> {
|
|||
|
||||
let req = self.client().perform_request(
|
||||
&uri,
|
||||
Method::PUT,
|
||||
&Method::PUT,
|
||||
|ref mut request| {
|
||||
LeaseIdRequired::add_header(&self, request);
|
||||
request.header(LEASE_ACTION, "release");
|
||||
|
|
|
@ -261,7 +261,7 @@ impl<'a> RenewBlobLeaseBuilder<'a, Yes, Yes, Yes> {
|
|||
|
||||
let req = self.client().perform_request(
|
||||
&uri,
|
||||
Method::PUT,
|
||||
&Method::PUT,
|
||||
|ref mut request| {
|
||||
LeaseIdRequired::add_header(&self, request);
|
||||
request.header(LEASE_ACTION, "renew");
|
||||
|
|
|
@ -618,7 +618,7 @@ impl<'a> UpdatePageBuilder<'a, Yes, Yes, Yes, Yes> {
|
|||
|
||||
let req = self.client().perform_request(
|
||||
&uri,
|
||||
Method::PUT,
|
||||
&Method::PUT,
|
||||
|ref mut request| {
|
||||
BA512RangeRequired::add_header(&self, request);
|
||||
ContentMD5Option::add_header(&self, request);
|
||||
|
|
|
@ -2,8 +2,8 @@ use azure::core::lease::LeaseId;
|
|||
use azure::core::RequestId;
|
||||
use chrono::{DateTime, Utc};
|
||||
|
||||
response_from_headers!(AcquireBlobLeaseResponse ,
|
||||
|
||||
response_from_headers!(AcquireBlobLeaseResponse,
|
||||
|
||||
etag_from_headers -> etag: String,
|
||||
last_modified_from_headers -> last_modified: DateTime<Utc>,
|
||||
lease_id_from_headers -> lease_id: LeaseId,
|
||||
|
|
|
@ -1,31 +1,3 @@
|
|||
macro_rules! response_from_headers {
|
||||
($cn:ident, $($fh:ident -> $na:ident: $typ:ty),+) => {
|
||||
use azure::core::errors::AzureError;
|
||||
use http::HeaderMap;
|
||||
use azure::core::{
|
||||
$($fh,)+
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct $cn {
|
||||
$(pub $na: $typ),+,
|
||||
}
|
||||
|
||||
impl $cn {
|
||||
pub(crate) fn from_headers(headers: &HeaderMap) -> Result<$cn, AzureError> {
|
||||
$(
|
||||
let $na = $fh(headers)?;
|
||||
)+
|
||||
|
||||
Ok($cn {
|
||||
$($na,)+
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
mod delete_blob_response;
|
||||
pub use self::delete_blob_response::DeleteBlobResponse;
|
||||
mod release_blob_lease_response;
|
||||
|
|
|
@ -196,7 +196,7 @@ impl Client {
|
|||
pub(crate) fn perform_request<F>(
|
||||
&self,
|
||||
uri: &str,
|
||||
method: Method,
|
||||
method: &Method,
|
||||
headers_func: F,
|
||||
request_body: Option<&[u8]>,
|
||||
) -> Result<hyper::client::ResponseFuture, AzureError>
|
||||
|
@ -209,7 +209,7 @@ impl Client {
|
|||
pub(crate) fn perform_table_request<F>(
|
||||
&self,
|
||||
segment: &str,
|
||||
method: Method,
|
||||
method: &Method,
|
||||
headers_func: F,
|
||||
request_str: Option<&[u8]>,
|
||||
) -> Result<hyper::client::ResponseFuture, AzureError>
|
||||
|
@ -219,7 +219,7 @@ impl Client {
|
|||
debug!("segment: {}, method: {:?}", segment, method,);
|
||||
perform_request(
|
||||
&self.hc,
|
||||
(self.get_uri_prefix(&ServiceType::Table) + segment).as_str(),
|
||||
(self.get_uri_prefix(ServiceType::Table) + segment).as_str(),
|
||||
method,
|
||||
&self.key,
|
||||
headers_func,
|
||||
|
@ -229,10 +229,10 @@ impl Client {
|
|||
}
|
||||
|
||||
/// Uri scheme + authority e.g. http://myaccount.table.core.windows.net/
|
||||
pub(crate) fn get_uri_prefix(&self, service_type: &ServiceType) -> String {
|
||||
pub(crate) fn get_uri_prefix(&self, service_type: ServiceType) -> String {
|
||||
"https://".to_owned()
|
||||
+ self.account()
|
||||
+ match *service_type {
|
||||
+ match service_type {
|
||||
ServiceType::Blob => SERVICE_SUFFIX_BLOB,
|
||||
ServiceType::Table => SERVICE_SUFFIX_TABLE,
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ use chrono::{DateTime, Utc};
|
|||
use http::request::Builder;
|
||||
use http::HeaderMap;
|
||||
use hyper::header;
|
||||
use hyper::header::HeaderName;
|
||||
use std::collections::HashMap;
|
||||
use std::{fmt, str::FromStr};
|
||||
use url::percent_encoding::utf8_percent_encode;
|
||||
|
@ -82,14 +83,20 @@ impl Container {
|
|||
pub fn from_response(name: String, headers: &HeaderMap) -> Result<Container, AzureError> {
|
||||
let last_modified = match headers.get(header::LAST_MODIFIED) {
|
||||
Some(last_modified) => last_modified.to_str()?,
|
||||
None => return Err(AzureError::MissingHeaderError(header::LAST_MODIFIED.as_str().to_owned())),
|
||||
None => {
|
||||
static LM: header::HeaderName = header::LAST_MODIFIED;
|
||||
return Err(AzureError::MissingHeaderError(LM.as_str().to_owned()));
|
||||
}
|
||||
};
|
||||
let last_modified = DateTime::parse_from_rfc2822(last_modified)?;
|
||||
let last_modified = DateTime::from_utc(last_modified.naive_utc(), Utc);
|
||||
|
||||
let e_tag = match headers.get(header::ETAG) {
|
||||
Some(e_tag) => e_tag.to_str()?.to_owned(),
|
||||
None => return Err(AzureError::MissingHeaderError(header::ETAG.as_str().to_owned())),
|
||||
None => {
|
||||
static ETAG: HeaderName = header::ETAG;
|
||||
return Err(AzureError::MissingHeaderError(ETAG.as_str().to_owned()));
|
||||
}
|
||||
};
|
||||
|
||||
let lease_status = match headers.get(LEASE_STATUS) {
|
||||
|
|
|
@ -266,7 +266,7 @@ impl<'a> AcquireLeaseBuilder<'a, Yes, Yes> {
|
|||
|
||||
let req = self.client().perform_request(
|
||||
&uri,
|
||||
Method::PUT,
|
||||
&Method::PUT,
|
||||
|ref mut request| {
|
||||
ClientRequestIdOption::add_header(&self, request);
|
||||
LeaseIdOption::add_header(&self, request);
|
||||
|
@ -280,6 +280,6 @@ impl<'a> AcquireLeaseBuilder<'a, Yes, Yes> {
|
|||
done(req)
|
||||
.from_err()
|
||||
.and_then(move |future_response| check_status_extract_headers_and_body(future_response, StatusCode::CREATED))
|
||||
.and_then(|(headers, _body)| done(AcquireLeaseResponse::from_response(&headers)))
|
||||
.and_then(|(headers, _body)| done(AcquireLeaseResponse::from_headers(&headers)))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -203,7 +203,7 @@ impl<'a> BreakLeaseBuilder<'a, Yes> {
|
|||
|
||||
let req = self.client().perform_request(
|
||||
&uri,
|
||||
Method::PUT,
|
||||
&Method::PUT,
|
||||
|ref mut request| {
|
||||
ClientRequestIdOption::add_header(&self, request);
|
||||
LeaseIdOption::add_header(&self, request);
|
||||
|
@ -216,6 +216,6 @@ impl<'a> BreakLeaseBuilder<'a, Yes> {
|
|||
done(req)
|
||||
.from_err()
|
||||
.and_then(move |future_response| check_status_extract_headers_and_body(future_response, StatusCode::ACCEPTED))
|
||||
.and_then(|(headers, _body)| done(BreakLeaseResponse::from_response(&headers)))
|
||||
.and_then(|(headers, _body)| done(BreakLeaseResponse::from_headers(&headers)))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -226,7 +226,7 @@ impl<'a> CreateBuilder<'a, Yes, Yes> {
|
|||
|
||||
let req = self.client().perform_request(
|
||||
&uri,
|
||||
Method::PUT,
|
||||
&Method::PUT,
|
||||
|ref mut request| {
|
||||
ClientRequestIdOption::add_header(&self, request);
|
||||
PublicAccessRequired::add_header(&self, request);
|
||||
|
|
|
@ -158,7 +158,7 @@ impl<'a> DeleteBuilder<'a, Yes> {
|
|||
|
||||
let req = self.client().perform_request(
|
||||
&uri,
|
||||
Method::DELETE,
|
||||
&Method::DELETE,
|
||||
|ref mut request| {
|
||||
ClientRequestIdOption::add_header(&self, request);
|
||||
LeaseIdOption::add_header(&self, request);
|
||||
|
|
|
@ -84,7 +84,7 @@ impl<'a> GetACLBuilder<'a, Yes> {
|
|||
|
||||
let req = self.client().perform_request(
|
||||
&uri,
|
||||
Method::GET,
|
||||
&Method::GET,
|
||||
|ref mut request| {
|
||||
ClientRequestIdOption::add_header(&self, request);
|
||||
LeaseIdOption::add_header(&self, request);
|
||||
|
|
|
@ -84,7 +84,7 @@ impl<'a> GetPropertiesBuilder<'a, Yes> {
|
|||
|
||||
let req = self.client().perform_request(
|
||||
&uri,
|
||||
Method::HEAD,
|
||||
&Method::HEAD,
|
||||
|ref mut request| {
|
||||
ClientRequestIdOption::add_header(&self, request);
|
||||
LeaseIdOption::add_header(&self, request);
|
||||
|
|
|
@ -102,7 +102,7 @@ impl<'a> ListBuilder<'a> {
|
|||
|
||||
let req = self.client().perform_request(
|
||||
&uri,
|
||||
Method::GET,
|
||||
&Method::GET,
|
||||
|ref mut request| {
|
||||
ClientRequestIdOption::add_header(&self, request);
|
||||
},
|
||||
|
|
|
@ -190,7 +190,7 @@ impl<'a> ReleaseLeaseBuilder<'a, Yes, Yes> {
|
|||
|
||||
let req = self.client().perform_request(
|
||||
&uri,
|
||||
Method::PUT,
|
||||
&Method::PUT,
|
||||
|ref mut request| {
|
||||
ClientRequestIdOption::add_header(&self, request);
|
||||
LeaseIdRequired::add_header(&self, request);
|
||||
|
@ -202,6 +202,6 @@ impl<'a> ReleaseLeaseBuilder<'a, Yes, Yes> {
|
|||
done(req)
|
||||
.from_err()
|
||||
.and_then(move |future_response| check_status_extract_headers_and_body(future_response, StatusCode::OK))
|
||||
.and_then(|(headers, _body)| done(ReleaseLeaseResponse::from_response(&headers)))
|
||||
.and_then(|(headers, _body)| done(ReleaseLeaseResponse::from_headers(&headers)))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -190,7 +190,7 @@ impl<'a> RenewLeaseBuilder<'a, Yes, Yes> {
|
|||
|
||||
let req = self.client().perform_request(
|
||||
&uri,
|
||||
Method::PUT,
|
||||
&Method::PUT,
|
||||
|ref mut request| {
|
||||
ClientRequestIdOption::add_header(&self, request);
|
||||
LeaseIdRequired::add_header(&self, request);
|
||||
|
@ -202,6 +202,6 @@ impl<'a> RenewLeaseBuilder<'a, Yes, Yes> {
|
|||
done(req)
|
||||
.from_err()
|
||||
.and_then(move |future_response| check_status_extract_headers_and_body(future_response, StatusCode::OK))
|
||||
.and_then(|(headers, _body)| done(RenewLeaseResponse::from_response(&headers)))
|
||||
.and_then(|(headers, _body)| done(RenewLeaseResponse::from_headers(&headers)))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ impl<'a> SetACLBuilder<'a, Yes, Yes> {
|
|||
|
||||
let req = self.client().perform_request(
|
||||
&uri,
|
||||
Method::PUT,
|
||||
&Method::PUT,
|
||||
|ref mut request| {
|
||||
ClientRequestIdOption::add_header(&self, request);
|
||||
LeaseIdOption::add_header(&self, request);
|
||||
|
|
|
@ -1,58 +1,12 @@
|
|||
use azure::core::errors::AzureError;
|
||||
use azure::core::headers;
|
||||
use azure::core::lease::LeaseId;
|
||||
use azure::core::RequestId;
|
||||
use chrono::{DateTime, FixedOffset};
|
||||
use http::header;
|
||||
use http::HeaderMap;
|
||||
use uuid::Uuid;
|
||||
use chrono::{DateTime, Utc};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct AcquireLeaseResponse {
|
||||
pub etag: String,
|
||||
pub last_modified: DateTime<FixedOffset>,
|
||||
pub lease_id: LeaseId,
|
||||
pub request_id: RequestId,
|
||||
pub date: DateTime<FixedOffset>,
|
||||
}
|
||||
response_from_headers!(AcquireLeaseResponse ,
|
||||
|
||||
impl AcquireLeaseResponse {
|
||||
pub(crate) fn from_response(headers: &HeaderMap) -> Result<AcquireLeaseResponse, AzureError> {
|
||||
let etag = match headers.get(header::ETAG) {
|
||||
Some(etag) => etag.to_str()?.to_owned(),
|
||||
None => return Err(AzureError::MissingHeaderError(header::ETAG.as_str().to_owned())),
|
||||
};
|
||||
|
||||
let last_modified = match headers.get(header::LAST_MODIFIED) {
|
||||
Some(last_modified) => last_modified.to_str()?,
|
||||
None => return Err(AzureError::MissingHeaderError(header::LAST_MODIFIED.as_str().to_owned())),
|
||||
};
|
||||
let last_modified = DateTime::parse_from_rfc2822(last_modified)?;
|
||||
|
||||
let request_id = match headers.get(headers::REQUEST_ID) {
|
||||
Some(request_id) => request_id.to_str()?,
|
||||
None => return Err(AzureError::MissingHeaderError(headers::REQUEST_ID.to_owned())),
|
||||
};
|
||||
let request_id = Uuid::parse_str(request_id)?;
|
||||
|
||||
let date = match headers.get(header::DATE) {
|
||||
Some(date) => date.to_str()?,
|
||||
None => return Err(AzureError::MissingHeaderError(header::DATE.as_str().to_owned())),
|
||||
};
|
||||
let date = DateTime::parse_from_rfc2822(date)?;
|
||||
|
||||
let lease_id = match headers.get(headers::LEASE_ID) {
|
||||
Some(lease_id) => lease_id.to_str()?,
|
||||
None => return Err(AzureError::MissingHeaderError(headers::LEASE_ID.to_owned())),
|
||||
};
|
||||
let lease_id = Uuid::parse_str(lease_id)?;
|
||||
|
||||
Ok(AcquireLeaseResponse {
|
||||
etag,
|
||||
last_modified,
|
||||
lease_id,
|
||||
request_id,
|
||||
date,
|
||||
})
|
||||
}
|
||||
}
|
||||
etag_from_headers -> etag: String,
|
||||
last_modified_from_headers -> last_modified: DateTime<Utc>,
|
||||
lease_id_from_headers -> lease_id: LeaseId,
|
||||
request_id_from_headers -> request_id: RequestId,
|
||||
date_from_headers -> date: DateTime<Utc>
|
||||
);
|
||||
|
|
|
@ -1,56 +1,12 @@
|
|||
use azure::core::errors::AzureError;
|
||||
use azure::core::headers;
|
||||
use azure::core::RequestId;
|
||||
use chrono::{DateTime, FixedOffset};
|
||||
use http::header;
|
||||
use http::HeaderMap;
|
||||
use uuid::Uuid;
|
||||
use chrono::{DateTime, Utc};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct BreakLeaseResponse {
|
||||
pub etag: String,
|
||||
pub last_modified: DateTime<FixedOffset>,
|
||||
pub request_id: RequestId,
|
||||
pub lease_time: u8,
|
||||
pub date: DateTime<FixedOffset>,
|
||||
}
|
||||
response_from_headers!(BreakLeaseResponse,
|
||||
|
||||
etag_from_headers -> etag: String,
|
||||
last_modified_from_headers -> last_modified: DateTime<Utc>,
|
||||
lease_time_from_headers -> lease_time: u8,
|
||||
request_id_from_headers -> request_id: RequestId,
|
||||
date_from_headers -> date: DateTime<Utc>
|
||||
);
|
||||
|
||||
impl BreakLeaseResponse {
|
||||
pub(crate) fn from_response(headers: &HeaderMap) -> Result<BreakLeaseResponse, AzureError> {
|
||||
let etag = match headers.get(header::ETAG) {
|
||||
Some(etag) => etag.to_str()?.to_owned(),
|
||||
None => return Err(AzureError::MissingHeaderError(header::ETAG.as_str().to_owned())),
|
||||
};
|
||||
|
||||
let last_modified = match headers.get(header::LAST_MODIFIED) {
|
||||
Some(last_modified) => last_modified.to_str()?,
|
||||
None => return Err(AzureError::MissingHeaderError(header::LAST_MODIFIED.as_str().to_owned())),
|
||||
};
|
||||
let last_modified = DateTime::parse_from_rfc2822(last_modified)?;
|
||||
|
||||
let request_id = match headers.get(headers::REQUEST_ID) {
|
||||
Some(request_id) => request_id.to_str()?,
|
||||
None => return Err(AzureError::MissingHeaderError(headers::REQUEST_ID.to_owned())),
|
||||
};
|
||||
let request_id = Uuid::parse_str(request_id)?;
|
||||
|
||||
let date = match headers.get(header::DATE) {
|
||||
Some(date) => date.to_str()?,
|
||||
None => return Err(AzureError::MissingHeaderError(header::DATE.as_str().to_owned())),
|
||||
};
|
||||
let date = DateTime::parse_from_rfc2822(date)?;
|
||||
|
||||
let lease_time = match headers.get(headers::LEASE_TIME) {
|
||||
Some(lease_time) => lease_time.to_str()?.parse()?,
|
||||
None => return Err(AzureError::MissingHeaderError(headers::LEASE_TIME.to_owned())),
|
||||
};
|
||||
|
||||
Ok(BreakLeaseResponse {
|
||||
etag,
|
||||
last_modified,
|
||||
request_id,
|
||||
lease_time,
|
||||
date,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,12 +26,18 @@ impl GetACLResponse {
|
|||
|
||||
let etag = match headers.get(header::ETAG) {
|
||||
Some(etag) => etag.to_str()?,
|
||||
None => return Err(AzureError::MissingHeaderError(header::ETAG.as_str().to_owned())),
|
||||
None => {
|
||||
static E: header::HeaderName = header::ETAG;
|
||||
return Err(AzureError::MissingHeaderError(E.as_str().to_owned()));
|
||||
}
|
||||
};
|
||||
|
||||
let last_modified = match headers.get(header::LAST_MODIFIED) {
|
||||
Some(last_modified) => last_modified.to_str()?,
|
||||
None => return Err(AzureError::MissingHeaderError(header::LAST_MODIFIED.as_str().to_owned())),
|
||||
None => {
|
||||
static LM: header::HeaderName = header::LAST_MODIFIED;
|
||||
return Err(AzureError::MissingHeaderError(LM.as_str().to_owned()));
|
||||
}
|
||||
};
|
||||
let last_modified = DateTime::parse_from_rfc2822(last_modified)?;
|
||||
|
||||
|
@ -42,7 +48,10 @@ impl GetACLResponse {
|
|||
|
||||
let date = match headers.get(header::DATE) {
|
||||
Some(date) => date.to_str()?,
|
||||
None => return Err(AzureError::MissingHeaderError(header::DATE.as_str().to_owned())),
|
||||
None => {
|
||||
static D: header::HeaderName = header::DATE;
|
||||
return Err(AzureError::MissingHeaderError(D.as_str().to_owned()));
|
||||
}
|
||||
};
|
||||
let date = DateTime::parse_from_rfc2822(date)?;
|
||||
|
||||
|
|
|
@ -23,7 +23,10 @@ impl GetPropertiesResponse {
|
|||
|
||||
let date = match headers.get(header::DATE) {
|
||||
Some(date) => DateTime::parse_from_rfc2822(date.to_str()?)?,
|
||||
None => return Err(AzureError::MissingHeaderError(header::DATE.as_str().to_owned())),
|
||||
None => {
|
||||
static D: header::HeaderName = header::DATE;
|
||||
return Err(AzureError::MissingHeaderError(D.as_str().to_owned()));
|
||||
}
|
||||
};
|
||||
|
||||
let container = Container::from_response(container_name, headers)?;
|
||||
|
|
|
@ -1,49 +1,11 @@
|
|||
use azure::core::errors::AzureError;
|
||||
use azure::core::headers;
|
||||
use azure::core::RequestId;
|
||||
use chrono::{DateTime, FixedOffset};
|
||||
use http::header;
|
||||
use http::HeaderMap;
|
||||
use uuid::Uuid;
|
||||
use chrono::{DateTime, Utc};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct ReleaseLeaseResponse {
|
||||
pub etag: String,
|
||||
pub last_modified: DateTime<FixedOffset>,
|
||||
pub request_id: RequestId,
|
||||
pub date: DateTime<FixedOffset>,
|
||||
}
|
||||
response_from_headers!(ReleaseLeaseResponse ,
|
||||
|
||||
etag_from_headers -> etag: String,
|
||||
last_modified_from_headers -> last_modified: DateTime<Utc>,
|
||||
request_id_from_headers -> request_id: RequestId,
|
||||
date_from_headers -> date: DateTime<Utc>
|
||||
);
|
||||
|
||||
impl ReleaseLeaseResponse {
|
||||
pub(crate) fn from_response(headers: &HeaderMap) -> Result<ReleaseLeaseResponse, AzureError> {
|
||||
let etag = match headers.get(header::ETAG) {
|
||||
Some(etag) => etag.to_str()?.to_owned(),
|
||||
None => return Err(AzureError::MissingHeaderError(header::ETAG.as_str().to_owned())),
|
||||
};
|
||||
|
||||
let last_modified = match headers.get(header::LAST_MODIFIED) {
|
||||
Some(last_modified) => last_modified.to_str()?,
|
||||
None => return Err(AzureError::MissingHeaderError(header::LAST_MODIFIED.as_str().to_owned())),
|
||||
};
|
||||
let last_modified = DateTime::parse_from_rfc2822(last_modified)?;
|
||||
|
||||
let request_id = match headers.get(headers::REQUEST_ID) {
|
||||
Some(request_id) => request_id.to_str()?,
|
||||
None => return Err(AzureError::MissingHeaderError(headers::REQUEST_ID.to_owned())),
|
||||
};
|
||||
let request_id = Uuid::parse_str(request_id)?;
|
||||
|
||||
let date = match headers.get(header::DATE) {
|
||||
Some(date) => date.to_str()?,
|
||||
None => return Err(AzureError::MissingHeaderError(header::DATE.as_str().to_owned())),
|
||||
};
|
||||
let date = DateTime::parse_from_rfc2822(date)?;
|
||||
|
||||
Ok(ReleaseLeaseResponse {
|
||||
etag,
|
||||
last_modified,
|
||||
request_id,
|
||||
date,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ use ring::{digest::SHA256, hmac};
|
|||
use std::fmt::Write;
|
||||
use url;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum ServiceType {
|
||||
Blob,
|
||||
// Queue, File,
|
||||
|
@ -22,7 +23,7 @@ const AZURE_VERSION: &str = "2017-11-09";
|
|||
pub const HEADER_VERSION: &str = "x-ms-version"; //=> [String] }
|
||||
pub const HEADER_DATE: &str = "x-ms-date"; //=> [String] }
|
||||
|
||||
fn generate_authorization(h: &HeaderMap, u: &url::Url, method: Method, hmac_key: &str, service_type: ServiceType) -> String {
|
||||
fn generate_authorization(h: &HeaderMap, u: &url::Url, method: &Method, hmac_key: &str, service_type: ServiceType) -> String {
|
||||
let str_to_sign = string_to_sign(h, u, method, service_type);
|
||||
|
||||
// debug!("\nstr_to_sign == {:?}\n", str_to_sign);
|
||||
|
@ -53,8 +54,8 @@ fn add_if_exists<K: header::AsHeaderName>(h: &HeaderMap, key: K) -> &str {
|
|||
}
|
||||
|
||||
#[allow(unknown_lints)]
|
||||
#[allow(needless_pass_by_value)]
|
||||
fn string_to_sign(h: &HeaderMap, u: &url::Url, method: Method, service_type: ServiceType) -> String {
|
||||
#[clippy::needless_pass_by_value]
|
||||
fn string_to_sign(h: &HeaderMap, u: &url::Url, method: &Method, service_type: ServiceType) -> String {
|
||||
match service_type {
|
||||
ServiceType::Table => {
|
||||
let mut s = String::new();
|
||||
|
@ -226,11 +227,11 @@ fn lexy_sort(vec: &url::form_urlencoded::Parse, query_param: &str) -> Vec<(Strin
|
|||
}
|
||||
|
||||
#[allow(unknown_lints)]
|
||||
#[allow(too_many_arguments)]
|
||||
#[clippy::too_many_arguments]
|
||||
pub fn perform_request<F>(
|
||||
client: &hyper::Client<hyper_tls::HttpsConnector<hyper::client::HttpConnector>>,
|
||||
uri: &str,
|
||||
http_method: Method,
|
||||
http_method: &Method,
|
||||
azure_key: &str,
|
||||
headers_func: F,
|
||||
request_body: Option<&[u8]>,
|
||||
|
@ -317,7 +318,7 @@ mod test {
|
|||
headers.insert(HEADER_DATE, format_header_value(time).unwrap());
|
||||
headers.insert(HEADER_VERSION, header::HeaderValue::from_static(AZURE_VERSION));
|
||||
|
||||
let s = string_to_sign(&headers, &u, method, service_type);
|
||||
let s = string_to_sign(&headers, &u, &method, service_type);
|
||||
|
||||
assert_eq!(
|
||||
s,
|
||||
|
|
|
@ -41,7 +41,7 @@ impl TableService {
|
|||
TableName: table_name.into(),
|
||||
}).unwrap();
|
||||
debug!("body == {}", body);
|
||||
let req = self.request_with_default_header(TABLE_TABLES, Method::POST, Some(body));
|
||||
let req = self.request_with_default_header(TABLE_TABLES, &Method::POST, Some(body));
|
||||
|
||||
done(req)
|
||||
.from_err()
|
||||
|
@ -55,7 +55,7 @@ impl TableService {
|
|||
row_key: &str,
|
||||
) -> impl Future<Item = Option<T>, Error = AzureError> {
|
||||
let path = &entity_path(table_name, partition_key, row_key);
|
||||
let req = self.request_with_default_header(path, Method::GET, None);
|
||||
let req = self.request_with_default_header(path, &Method::GET, None);
|
||||
done(req).from_err().and_then(move |future_response| {
|
||||
extract_status_and_body(future_response).and_then(move |(status, body)| {
|
||||
if status == StatusCode::NOT_FOUND {
|
||||
|
@ -87,7 +87,7 @@ impl TableService {
|
|||
path.push_str(clause);
|
||||
}
|
||||
|
||||
let req = self.request_with_default_header(path.as_str(), Method::GET, None);
|
||||
let req = self.request_with_default_header(path.as_str(), &Method::GET, None);
|
||||
|
||||
done(req).from_err().and_then(move |future_response| {
|
||||
check_status_extract_body(future_response, StatusCode::OK).and_then(move |body| {
|
||||
|
@ -103,7 +103,7 @@ impl TableService {
|
|||
T: Serialize,
|
||||
{
|
||||
let obj_ser = serde_json::to_string(entity)?;
|
||||
self.request_with_default_header(table_name, Method::POST, Some(&obj_ser))
|
||||
self.request_with_default_header(table_name, &Method::POST, Some(&obj_ser))
|
||||
}
|
||||
|
||||
pub fn insert_entity<T: Serialize>(&self, table_name: &str, entity: &T) -> impl Future<Item = (), Error = AzureError> {
|
||||
|
@ -126,7 +126,7 @@ impl TableService {
|
|||
{
|
||||
let body = &serde_json::to_string(entity)?;
|
||||
let path = &entity_path(table_name, partition_key, row_key);
|
||||
self.request_with_default_header(path, Method::PUT, Some(body))
|
||||
self.request_with_default_header(path, &Method::PUT, Some(body))
|
||||
}
|
||||
|
||||
pub fn update_entity<T: Serialize>(
|
||||
|
@ -145,7 +145,7 @@ impl TableService {
|
|||
pub fn delete_entity(&self, table_name: &str, partition_key: &str, row_key: &str) -> impl Future<Item = (), Error = AzureError> {
|
||||
let path = &entity_path(table_name, partition_key, row_key);
|
||||
|
||||
let req = self.request(path, Method::DELETE, None, |ref mut request| {
|
||||
let req = self.request(path, &Method::DELETE, None, |ref mut request| {
|
||||
request.header(header::ACCEPT, HeaderValue::from_static(get_json_mime_nometadata()));
|
||||
request.header(header::IF_MATCH, header::HeaderValue::from_static("*"));
|
||||
});
|
||||
|
@ -161,13 +161,13 @@ impl TableService {
|
|||
batch_items: &[BatchItem<T>],
|
||||
) -> impl Future<Item = (), Error = AzureError> {
|
||||
let payload = &generate_batch_payload(
|
||||
self.client.get_uri_prefix(&ServiceType::Table).as_str(),
|
||||
self.client.get_uri_prefix(ServiceType::Table).as_str(),
|
||||
table_name,
|
||||
partition_key,
|
||||
batch_items,
|
||||
);
|
||||
|
||||
let req = self.request("$batch", Method::POST, Some(payload), |ref mut request| {
|
||||
let req = self.request("$batch", &Method::POST, Some(payload), |ref mut request| {
|
||||
request.header(header::CONTENT_TYPE, header::HeaderValue::from_static(get_batch_mime()));
|
||||
});
|
||||
done(req).from_err().and_then(move |future_response| {
|
||||
|
@ -180,7 +180,7 @@ impl TableService {
|
|||
})
|
||||
}
|
||||
|
||||
fn request_with_default_header(&self, segment: &str, method: Method, request_str: Option<&str>) -> Result<ResponseFuture, AzureError> {
|
||||
fn request_with_default_header(&self, segment: &str, method: &Method, request_str: Option<&str>) -> Result<ResponseFuture, AzureError> {
|
||||
self.request(segment, method, request_str, |ref mut request| {
|
||||
request.header(header::ACCEPT, HeaderValue::from_static(get_json_mime_nometadata()));
|
||||
if request_str.is_some() {
|
||||
|
@ -189,7 +189,7 @@ impl TableService {
|
|||
})
|
||||
}
|
||||
|
||||
fn request<F>(&self, segment: &str, method: Method, request_str: Option<&str>, headers_func: F) -> Result<ResponseFuture, AzureError>
|
||||
fn request<F>(&self, segment: &str, method: &Method, request_str: Option<&str>, headers_func: F) -> Result<ResponseFuture, AzureError>
|
||||
where
|
||||
F: FnOnce(&mut ::http::request::Builder),
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче