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

Commit 5c90b4a

Browse files
author
Francesco Cogno
authored
Merge pull request #313 from MindFlavor/issue/azure_flag
Workaround for Azurite Creation Dates
2 parents 618256c + 4dcf753 commit 5c90b4a

File tree

5 files changed

+56
-12
lines changed

5 files changed

+56
-12
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
[![Build Status](https://travis-ci.org/MindFlavor/AzureSDKForRust.svg?branch=master)](https://travis-ci.org/MindFlavor/AzureSDKForRust) [![Coverage Status](https://coveralls.io/repos/MindFlavor/AzureSDKForRust/badge.svg?branch=master&service=github)](https://coveralls.io/github/MindFlavor/AzureSDKForRust?branch=master) ![stability-unstable](https://img.shields.io/badge/stability-unstable-yellow.svg)
77

8-
[![tag](https://img.shields.io/github/tag/mindflavor/AzureSDKForRust.svg)](https://github.com/MindFlavor/AzureSDKForRust/tree/aad_0.47.0) [![release](https://img.shields.io/github/release/mindflavor/AzureSDKForRust.svg)](https://github.com/MindFlavor/AzureSDKForRust/releases/tag/aad_0.47.0) [![commitssince](https://img.shields.io/github/commits-since/mindflavor/AzureSDKForRust/aad_0.47.0)](https://github.com/MindFlavor/AzureSDKForRust/commits/master)
8+
[![tag](https://img.shields.io/github/tag/mindflavor/AzureSDKForRust.svg)](https://github.com/MindFlavor/AzureSDKForRust/tree/storage_blob_0.45.1) [![release](https://img.shields.io/github/release/mindflavor/AzureSDKForRust.svg)](https://github.com/MindFlavor/AzureSDKForRust/releases/tag/storage_blob_0.45.1) [![commitssince](https://img.shields.io/github/commits-since/mindflavor/AzureSDKForRust/storage_blob_0.45.1)](https://github.com/MindFlavor/AzureSDKForRust/commits/master)
99

1010
[![GitHub contributors](https://img.shields.io/github/contributors/MindFlavor/AzureSDKForRust.svg)](https://github.com/MindFlavor/AzureSDKForRust/graphs/contributors)
1111

azure_sdk_core/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "azure_sdk_core"
3-
version = "0.43.5"
3+
version = "0.43.6"
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]>"]
@@ -39,3 +39,4 @@ env_logger = "0.7"
3939

4040
[features]
4141
test_e2e = []
42+
azurite_workaround = []

azure_sdk_core/src/parsing.rs

+13
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,25 @@ impl FromStringOptional<chrono::DateTime<chrono::Utc>> for chrono::DateTime<chro
3939
}
4040

4141
#[inline]
42+
#[cfg(not(feature = "azurite_workaround"))]
4243
pub fn from_azure_time(s: &str) -> Result<chrono::DateTime<chrono::Utc>, chrono::ParseError> {
4344
let dt = chrono::DateTime::parse_from_rfc2822(s)?;
4445
let dt_utc: chrono::DateTime<chrono::Utc> = dt.with_timezone(&chrono::Utc);
4546
Ok(dt_utc)
4647
}
4748

49+
#[inline]
50+
#[cfg(feature = "azurite_workaround")]
51+
pub fn from_azure_time(s: &str) -> Result<chrono::DateTime<chrono::Utc>, chrono::ParseError> {
52+
if let Ok(dt) = chrono::DateTime::parse_from_rfc2822(s) {
53+
let dt_utc: chrono::DateTime<chrono::Utc> = dt.with_timezone(&chrono::Utc);
54+
Ok(dt_utc)
55+
} else {
56+
log::warn!("Received an invalid date: {}, returning now()", s);
57+
Ok(chrono::Utc::now())
58+
}
59+
}
60+
4861
#[inline]
4962
pub fn traverse_single_must<'a>(
5063
node: &'a Element,

azure_sdk_storage_blob/Cargo.toml

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "azure_sdk_storage_blob"
3-
version = "0.45.0"
3+
version = "0.45.1"
44
description = "Rust wrappers around Microsoft Azure REST APIs - Blob 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", optional = true }
1919
azure_sdk_storage_core = { path = "../azure_sdk_storage_core", version = "0.44.3" }
2020
md5 = "0.7"
2121
RustyXML = "0.3"
@@ -37,4 +37,6 @@ tokio = { version = "0.2", features = ["macros"] }
3737
azure_sdk_auth_aad = { path = "../azure_sdk_auth_aad" }
3838

3939
[features]
40-
test_e2e = []
40+
default = [ "azure_sdk_core" ]
41+
test_e2e = [ "azure_sdk_core" ]
42+
azurite_workaround = [ "azure_sdk_core/azurite_workaround" ]

azure_sdk_storage_blob/src/blob/mod.rs

+35-7
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@ use azure_sdk_core::{
4040
util::HeaderMapExt,
4141
};
4242

43+
#[cfg(feature = "azurite_workaround")]
44+
fn get_creation_time(h: &header::HeaderMap) -> Result<Option<DateTime<Utc>>, AzureError> {
45+
if let Some(creation_time) = h.get(CREATION_TIME) {
46+
// Check that the creation time is valid
47+
let creation_time = creation_time.to_str()?;
48+
let creation_time = DateTime::parse_from_rfc2822(creation_time)?;
49+
let creation_time = DateTime::from_utc(creation_time.naive_utc(), Utc);
50+
Ok(Some(creation_time))
51+
} else {
52+
// Not having a creation time is ok
53+
Ok(None)
54+
}
55+
}
56+
4357
pub trait BlockListTypeSupport {
4458
type O;
4559
fn with_block_list_type(self, block_list_type: BlockListType) -> Self::O;
@@ -94,7 +108,10 @@ pub struct Blob {
94108
pub name: String,
95109
pub container_name: String,
96110
pub snapshot_time: Option<DateTime<Utc>>,
111+
#[cfg(not(feature = "azurite_workaround"))]
97112
pub creation_time: DateTime<Utc>,
113+
#[cfg(feature = "azurite_workaround")]
114+
pub creation_time: Option<DateTime<Utc>>,
98115
pub last_modified: Option<DateTime<Utc>>, // optional because unavailable in uncommitted blobs
99116
pub etag: Option<String>, // optional because unavailable in uncommitted blobs
100117
pub content_length: u64,
@@ -129,7 +146,12 @@ impl Blob {
129146
pub(crate) fn parse(elem: &Element, container_name: &str) -> Result<Blob, AzureError> {
130147
let name = cast_must::<String>(elem, &["Name"])?;
131148
let snapshot_time = cast_optional::<DateTime<Utc>>(elem, &["Snapshot"])?;
149+
150+
#[cfg(feature = "azurite_workaround")]
151+
let creation_time = cast_optional::<DateTime<Utc>>(elem, &["Properties", "Creation-Time"])?;
152+
#[cfg(not(feature = "azurite_workaround"))]
132153
let creation_time = cast_must::<DateTime<Utc>>(elem, &["Properties", "Creation-Time"])?;
154+
133155
let last_modified = cast_optional::<DateTime<Utc>>(elem, &["Properties", "Last-Modified"])?;
134156
let etag = cast_optional::<String>(elem, &["Properties", "Etag"])?;
135157

@@ -252,13 +274,19 @@ impl Blob {
252274
) -> Result<Blob, AzureError> {
253275
trace!("\n{:?}", h);
254276

255-
let creation_time = h
256-
.get(CREATION_TIME)
257-
.ok_or_else(|| AzureError::HeaderNotFound(CREATION_TIME.to_owned()))?
258-
.to_str()?;
259-
let creation_time = DateTime::parse_from_rfc2822(creation_time)?;
260-
let creation_time = DateTime::from_utc(creation_time.naive_utc(), Utc);
261-
trace!("creation_time == {:?}", creation_time);
277+
#[cfg(not(feature = "azurite_workaround"))]
278+
let creation_time = {
279+
let creation_time = h
280+
.get(CREATION_TIME)
281+
.ok_or_else(|| AzureError::HeaderNotFound(CREATION_TIME.to_owned()))?
282+
.to_str()?;
283+
let creation_time = DateTime::parse_from_rfc2822(creation_time)?;
284+
let creation_time = DateTime::from_utc(creation_time.naive_utc(), Utc);
285+
trace!("creation_time == {:?}", creation_time);
286+
creation_time
287+
};
288+
#[cfg(feature = "azurite_workaround")]
289+
let creation_time = get_creation_time(h)?;
262290

263291
let content_type = h
264292
.get_as_string(header::CONTENT_TYPE)

0 commit comments

Comments
 (0)