Skip to content

Commit

Permalink
move azure_storage::xml to azure_core::xml behind xml feature (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ctaggart authored Aug 29, 2022
1 parent 25538f4 commit a2fc340
Show file tree
Hide file tree
Showing 18 changed files with 32 additions and 27 deletions.
2 changes: 2 additions & 0 deletions sdk/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ reqwest = { version = "0.11", features = [
], default-features = false, optional = true }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde-xml-rs = { version = "0.5", optional = true }
url = "2.2"
uuid = { version = "1.0" }
pin-project = "1.0"
Expand All @@ -51,3 +52,4 @@ enable_reqwest_gzip = ["reqwest/gzip"]
enable_reqwest_rustls = ["reqwest/rustls-tls"]
test_e2e = []
azurite_workaround = []
xml = ["serde-xml-rs"]
3 changes: 3 additions & 0 deletions sdk/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ pub mod util;

use uuid::Uuid;

#[cfg(feature = "xml")]
pub mod xml;

pub use bytes_stream::*;
pub use constants::*;
pub use context::Context;
Expand Down
5 changes: 3 additions & 2 deletions sdk/storage/src/core/xml.rs → sdk/core/src/xml.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use azure_core::error::{ErrorKind, ResultExt};
use crate::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]) -> azure_core::Result<T> {
pub fn read_xml<'de, T: serde::de::Deserialize<'de>>(body: &[u8]) -> crate::Result<T> {
serde_xml_rs::from_reader(slice_bom(body)).with_context(ErrorKind::DataConversion, || {
let t = core::any::type_name::<T>();
let xml = std::str::from_utf8(body).unwrap_or("<XML IS NOT UTF-8>");
Expand All @@ -24,6 +24,7 @@ fn slice_bom(bytes: &[u8]) -> &[u8] {
#[cfg(test)]
mod test {
use super::*;
use serde::Deserialize;

#[test]
fn test_slice_bom() {
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ edition = "2021"

[dependencies]
async-trait = "0.1"
azure_core = { path = "../core", version = "0.4" }
azure_core = { path = "../core", version = "0.4", features = ["xml"] }
base64 = "0.13"
time = "0.3.10"
futures = "0.3"
Expand Down
1 change: 0 additions & 1 deletion sdk/storage/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub mod parsing_xml;
pub mod storage_shared_key_credential;
mod stored_access_policy;
pub use azure_core::error::{Error, ErrorKind, ResultExt};
pub mod xml;

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct IPRange {
Expand Down
4 changes: 1 addition & 3 deletions sdk/storage/src/core/stored_access_policy.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::xml::read_xml;
use azure_core::date;
use azure_core::{date, xml::read_xml};
use time::OffsetDateTime;

#[derive(Debug, Clone, Default, PartialEq, Eq)]
Expand Down Expand Up @@ -117,7 +116,6 @@ struct AccessPolicy {
#[cfg(test)]
mod test {
use super::*;
use crate::xml::read_xml;

#[test]
fn parse_from_xml() {
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage_blobs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ categories = ["api-bindings"]
edition = "2021"

[dependencies]
azure_core = { path = "../core", version = "0.4" }
azure_core = { path = "../core", version = "0.4", features = ["xml"] }
azure_storage = { path = "../storage", version = "0.5", default-features = false }
base64 = "0.13"
bytes = "1.0"
Expand Down
3 changes: 1 addition & 2 deletions sdk/storage_blobs/src/blob/operations/get_tags.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::prelude::*;
use azure_core::{headers::*, prelude::*, RequestId};
use azure_storage::xml::read_xml;
use azure_core::{headers::*, prelude::*, xml::read_xml, RequestId};
use time::OffsetDateTime;

operation! {
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage_blobs/src/container/operations/list_blobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use azure_core::{
error::Error,
headers::{date_from_headers, request_id_from_headers, Headers},
prelude::*,
xml::read_xml,
Pageable, RequestId, Response as AzureResponse,
};
use azure_storage::xml::read_xml;
use time::OffsetDateTime;

operation! {
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage_blobs/src/options/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl Header for Tags {
#[cfg(test)]
mod tests {
use super::*;
use azure_storage::xml::read_xml;
use azure_core::xml::read_xml;

#[test]
fn parse_tags_xml() -> azure_core::Result<()> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use azure_core::prelude::*;
use azure_core::Response as HttpResponse;
use azure_storage::{headers::CommonStorageResponseHeaders, xml::read_xml};
use azure_core::{prelude::*, xml::read_xml, Response as HttpResponse};
use azure_storage::headers::CommonStorageResponseHeaders;

use crate::prelude::BlobServiceClient;

Expand Down
2 changes: 1 addition & 1 deletion sdk/storage_queues/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ categories = ["api-bindings"]
edition = "2021"

[dependencies]
azure_core = { path = "../core", version = "0.4", default-features=false }
azure_core = { path = "../core", version = "0.4", default-features=false, features = ["xml"] }
azure_storage = { path = "../storage", version = "0.5", default-features=false }
time = "0.3.10"
futures = "0.3"
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage_queues/src/operations/get_messages.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{clients::QueueClient, prelude::*, PopReceipt};
use azure_core::{headers::Headers, prelude::*, Method, Response as AzureResponse};
use azure_storage::core::{headers::CommonStorageResponseHeaders, xml::read_xml};
use azure_core::{headers::Headers, prelude::*, xml::read_xml, Method, Response as AzureResponse};
use azure_storage::core::headers::CommonStorageResponseHeaders;
use serde::Deserialize;
use std::convert::TryInto;
use time::OffsetDateTime;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{QueueServiceClient, QueueServiceProperties};
use azure_core::{headers::Headers, Method, Response as AzureResponse};
use azure_storage::core::{headers::CommonStorageResponseHeaders, xml::read_xml};
use azure_core::{headers::Headers, xml::read_xml, Method, Response as AzureResponse};
use azure_storage::core::headers::CommonStorageResponseHeaders;
use std::convert::TryInto;

operation! {
Expand Down
3 changes: 2 additions & 1 deletion sdk/storage_queues/src/operations/get_queue_service_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ use azure_core::{
date,
error::{ErrorKind, ResultExt},
headers::Headers,
xml::read_xml,
Method, Response as AzureResponse,
};
use azure_storage::core::{headers::CommonStorageResponseHeaders, xml::read_xml};
use azure_storage::core::headers::CommonStorageResponseHeaders;
use std::convert::TryInto;
use time::OffsetDateTime;

Expand Down
5 changes: 3 additions & 2 deletions sdk/storage_queues/src/operations/list_queues.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::QueueServiceClient;
use azure_core::{
error::Error, headers::Headers, prelude::*, Method, Pageable, Response as AzureResponse,
error::Error, headers::Headers, prelude::*, xml::read_xml, Method, Pageable,
Response as AzureResponse,
};
use azure_storage::{core::headers::CommonStorageResponseHeaders, xml::read_xml};
use azure_storage::core::headers::CommonStorageResponseHeaders;
use std::convert::TryInto;

operation! {
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage_queues/src/operations/peek_messages.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{clients::QueueClient, prelude::*};
use azure_core::{headers::Headers, prelude::*, Method, Response as AzureResponse};
use azure_storage::core::{headers::CommonStorageResponseHeaders, xml::read_xml};
use azure_core::{headers::Headers, prelude::*, xml::read_xml, Method, Response as AzureResponse};
use azure_storage::core::headers::CommonStorageResponseHeaders;
use std::convert::TryInto;
use time::OffsetDateTime;

Expand Down
6 changes: 4 additions & 2 deletions sdk/storage_queues/src/operations/put_message.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::prelude::*;
use azure_core::{date, headers::Headers, prelude::*, Method, Response as AzureResponse};
use azure_storage::{core::headers::CommonStorageResponseHeaders, xml::read_xml};
use azure_core::{
date, headers::Headers, prelude::*, xml::read_xml, Method, Response as AzureResponse,
};
use azure_storage::core::headers::CommonStorageResponseHeaders;
use std::convert::TryInto;
use time::OffsetDateTime;

Expand Down

0 comments on commit a2fc340

Please sign in to comment.