Skip to content

Commit

Permalink
Even more cleanup (#859)
Browse files Browse the repository at this point in the history
  • Loading branch information
rylev authored Jun 27, 2022
1 parent 34ce004 commit 169fd92
Show file tree
Hide file tree
Showing 32 changed files with 97 additions and 203 deletions.
4 changes: 2 additions & 2 deletions sdk/data_tables/src/requests/submit_transaction_builder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{prelude::*, responses::*};
use azure_core::Method;
use azure_core::{
error::{Error, ErrorKind, ResultExt},
error::{Error, ErrorKind},
prelude::*,
};
use std::convert::TryInto;
Expand Down Expand Up @@ -39,7 +39,7 @@ impl<'a> SubmitTransactionBuilder<'a> {

self.timeout.append_to_url_query(&mut url);

let payload = batch.to_string().map_kind(ErrorKind::DataConversion)?;
let payload = batch.to_string()?;

let mut request = self.partition_key_client.prepare_request(
url.as_str(),
Expand Down
3 changes: 1 addition & 2 deletions sdk/identity/src/refresh_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ pub async fn exchange(
} else {
return Err(
ErrorKind::http_response_from_body(rsp_status.as_u16(), &rsp_body).into_error(),
)
.map_kind(ErrorKind::Credential);
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ impl TokenCredential for ImdsManagedIdentityCredential {
return Err(
ErrorKind::http_response_from_body(rsp_status, &rsp_body).into_error()
)
.map_kind(ErrorKind::Credential)
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions sdk/storage/src/core/parsing_xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ pub fn traverse<'a>(
path,
ignore_empty_leaf
);
// debug!("path.len() == {:?}", path.len());

if path.is_empty() {
return Ok(vec![node]);
Expand All @@ -57,8 +56,6 @@ pub fn traverse<'a>(
let mut curnode = node;

for (x, item) in path.iter().enumerate() {
// debug!("x == {}, path[x] == {}", x, path[x]);

let vec = find_subnodes(curnode, item);
if vec.is_empty() {
if (x + 1) >= path.len() && ignore_empty_leaf {
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage/src/core/xml.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use azure_core::error::{Error, ErrorKind, ResultExt};
use azure_core::error::{ErrorKind, ResultExt};

/// The UTF8 [byte order marker](https://en.wikipedia.org/wiki/Byte_order_mark)
const UTF8_BOM: [u8; 3] = [0xEF, 0xBB, 0xBF];

/// Reads the XML from bytes.
pub fn read_xml<'de, T: serde::de::Deserialize<'de>>(body: &[u8]) -> Result<T, Error> {
pub fn read_xml<'de, T: serde::de::Deserialize<'de>>(body: &[u8]) -> azure_core::Result<T> {
serde_xml_rs::from_reader(slice_bom(body))
.context(ErrorKind::DataConversion, "failed to deserialize xml")
}
Expand Down
10 changes: 2 additions & 8 deletions sdk/storage_blobs/src/blob/operations/put_block.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
use crate::prelude::*;
use azure_core::{
error::{ErrorKind, ResultExt},
headers::*,
prelude::*,
RequestId,
};
use azure_core::{headers::*, prelude::*, RequestId};
use azure_storage::{headers::consistency_from_headers, ConsistencyCRC64, ConsistencyMD5};
use bytes::Bytes;
use chrono::{DateTime, Utc};
Expand Down Expand Up @@ -74,8 +69,7 @@ pub struct PutBlockResponse {

impl PutBlockResponse {
pub(crate) fn from_headers(headers: &Headers) -> azure_core::Result<PutBlockResponse> {
let (content_md5, content_crc64) =
consistency_from_headers(headers).map_kind(ErrorKind::DataConversion)?;
let (content_md5, content_crc64) = consistency_from_headers(headers)?;
let request_id = request_id_from_headers(headers)?;
let date = date_from_headers(headers)?;
let request_server_encrypted = request_server_encrypted_from_headers(headers)?;
Expand Down
10 changes: 2 additions & 8 deletions sdk/storage_blobs/src/blob/operations/put_block_blob.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
use crate::prelude::*;
use azure_core::{
error::{ErrorKind, ResultExt},
headers::*,
prelude::*,
RequestId,
};
use azure_core::{headers::*, prelude::*, RequestId};
use azure_storage::{headers::consistency_from_headers, ConsistencyCRC64, ConsistencyMD5};
use bytes::Bytes;
use chrono::{DateTime, Utc};
Expand Down Expand Up @@ -105,8 +100,7 @@ impl PutBlockBlobResponse {
pub fn from_headers(headers: &Headers) -> azure_core::Result<PutBlockBlobResponse> {
let etag = etag_from_headers(headers)?;
let last_modified = last_modified_from_headers(headers)?;
let (content_md5, content_crc64) =
consistency_from_headers(headers).map_kind(ErrorKind::DataConversion)?;
let (content_md5, content_crc64) = consistency_from_headers(headers)?;
let request_id = request_id_from_headers(headers)?;
let date = date_from_headers(headers)?;
let request_server_encrypted = request_server_encrypted_from_headers(headers)?;
Expand Down
9 changes: 2 additions & 7 deletions sdk/storage_blobs/src/blob/operations/put_block_list.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
use crate::prelude::*;
use azure_core::{
error::{ErrorKind, ResultExt},
headers::*,
prelude::*,
RequestId,
};
use azure_core::{headers::*, prelude::*, RequestId};
use azure_storage::{headers::content_md5_from_headers, ConsistencyMD5};
use bytes::Bytes;
use chrono::{DateTime, Utc};
Expand Down Expand Up @@ -115,7 +110,7 @@ impl PutBlockListResponse {
pub(crate) fn from_headers(headers: &Headers) -> azure_core::Result<PutBlockListResponse> {
let etag = etag_from_headers(headers)?;
let last_modified = last_modified_from_headers(headers)?;
let content_md5 = content_md5_from_headers(headers).map_kind(ErrorKind::DataConversion)?;
let content_md5 = content_md5_from_headers(headers)?;
let request_id = request_id_from_headers(headers)?;
let date = date_from_headers(headers)?;
let request_server_encrypted = request_server_encrypted_from_headers(headers)?;
Expand Down
9 changes: 2 additions & 7 deletions sdk/storage_blobs/src/blob/operations/update_page.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
use crate::{prelude::*, BA512Range};
use azure_core::{
error::{ErrorKind, ResultExt},
headers::*,
prelude::*,
RequestId,
};
use azure_core::{headers::*, prelude::*, RequestId};
use azure_storage::{headers::content_md5_from_headers, ConsistencyMD5};
use bytes::Bytes;
use chrono::{DateTime, Utc};
Expand Down Expand Up @@ -93,7 +88,7 @@ impl UpdatePageResponse {
pub(crate) fn from_headers(headers: &Headers) -> azure_core::Result<UpdatePageResponse> {
let etag = etag_from_headers(headers)?;
let last_modified = last_modified_from_headers(headers)?;
let content_md5 = content_md5_from_headers(headers).map_kind(ErrorKind::DataConversion)?;
let content_md5 = content_md5_from_headers(headers)?;
let sequence_number = sequence_number_from_headers(headers)?;
let request_id = request_id_from_headers(headers)?;
let date = date_from_headers(headers)?;
Expand Down
48 changes: 14 additions & 34 deletions sdk/storage_blobs/src/container/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,39 +124,19 @@ impl Container {
}

fn parse(elem: &Element) -> azure_core::Result<Container> {
let name = cast_must::<String>(elem, &["Name"]).map_kind(ErrorKind::DataConversion)?;
let last_modified = cast_must::<DateTime<Utc>>(elem, &["Properties", "Last-Modified"])
.map_kind(ErrorKind::DataConversion)?;
let e_tag = cast_must::<String>(elem, &["Properties", "Etag"])
.map_kind(ErrorKind::DataConversion)?;

let lease_state = cast_must::<LeaseState>(elem, &["Properties", "LeaseState"])
.map_kind(ErrorKind::DataConversion)?;

let lease_duration = cast_optional::<LeaseDuration>(elem, &["Properties", "LeaseDuration"])
.map_kind(ErrorKind::DataConversion)?;

let lease_status = cast_must::<LeaseStatus>(elem, &["Properties", "LeaseStatus"])
.map_kind(ErrorKind::DataConversion)?;

let name = cast_must(elem, &["Name"]).map_kind(ErrorKind::DataConversion)?;
let last_modified = cast_must(elem, &["Properties", "Last-Modified"])?;
let e_tag = cast_must(elem, &["Properties", "Etag"])?;
let lease_state = cast_must(elem, &["Properties", "LeaseState"])?;
let lease_duration = cast_optional(elem, &["Properties", "LeaseDuration"])?;
let lease_status = cast_must(elem, &["Properties", "LeaseStatus"])?;
let public_access =
match cast_optional::<PublicAccess>(elem, &["Properties", "PublicAccess"])
.map_kind(ErrorKind::DataConversion)?
{
Some(pa) => pa,
None => PublicAccess::None,
};

let has_immutability_policy =
cast_must::<bool>(elem, &["Properties", "HasImmutabilityPolicy"])
.map_kind(ErrorKind::DataConversion)?;
let has_legal_hold = cast_must::<bool>(elem, &["Properties", "HasLegalHold"])
.map_kind(ErrorKind::DataConversion)?;

cast_optional(elem, &["Properties", "PublicAccess"])?.unwrap_or(PublicAccess::None);
let has_immutability_policy = cast_must(elem, &["Properties", "HasImmutabilityPolicy"])?;
let has_legal_hold = cast_must(elem, &["Properties", "HasLegalHold"])?;
let metadata = {
let mut hm = HashMap::new();
let metadata =
traverse(elem, &["Metadata"], true).map_kind(ErrorKind::DataConversion)?;
let metadata = traverse(elem, &["Metadata"], true)?;

for m in metadata {
for key in &m.children {
Expand All @@ -170,18 +150,18 @@ impl Container {
}
};

let key = elem.name.to_owned();

if elem.children.is_empty() {
return Err(Error::message(
ErrorKind::DataConversion,
"Metadata node should not be empty",
));
}

let key = elem.name.clone();

let content = {
match elem.children[0] {
Xml::CharacterNode(ref content) => content.to_owned(),
match &elem.children[0] {
Xml::CharacterNode(content) => content.clone(),
_ => {
return Err(Error::message(ErrorKind::DataConversion,
"Metadata node should contain a CharacterNode with metadata value",
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage_blobs/src/container/operations/acquire_lease.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ impl AcquireLeaseBuilder {
AcquireLeaseBuilder {
container_client,
lease_duration,
context: Context::new(),
timeout: None,
lease_id: None,
proposed_lease_id: None,
context: Context::new(),
}
}

setters! {
lease_id: LeaseId => Some(lease_id),
proposed_lease_id: ProposedLeaseId => Some(proposed_lease_id),

timeout: Timeout => Some(timeout),
context: Context => context,
}

pub fn into_future(mut self) -> Response {
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage_blobs/src/container/operations/break_lease.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ impl BreakLeaseBuilder {
pub(crate) fn new(container_client: ContainerClient) -> BreakLeaseBuilder {
Self {
container_client,
context: Context::new(),
timeout: None,
lease_break_period: None,
lease_id: None,
context: Context::new(),
}
}

setters! {
lease_id: LeaseId => Some(lease_id),
lease_break_period: LeaseBreakPeriod => Some(lease_break_period),

timeout: Timeout => Some(timeout),
context: Context => context,
}

pub fn into_future(mut self) -> Response {
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage_blobs/src/container/operations/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ impl CreateBuilder {
container_client,
public_access: PublicAccess::None,
metadata: None,
context: Context::new(),
timeout: None,
context: Context::new(),
}
}

setters! {
public_access: PublicAccess => public_access,
metadata: Metadata => Some(metadata),

timeout: Timeout => Some(timeout),
context: Context => context,
}

pub fn into_future(mut self) -> Response {
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage_blobs/src/container/operations/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ impl DeleteBuilder {
DeleteBuilder {
container_client,
lease_id: None,
context: Context::new(),
timeout: None,
context: Context::new(),
}
}

setters! {
lease_id: LeaseId => Some(lease_id),

timeout: Timeout => Some(timeout),
context: Context => context,
}

pub fn into_future(mut self) -> Response {
Expand Down
Loading

0 comments on commit 169fd92

Please sign in to comment.