From fa33443e8f5cbe87f4190ab53619d5408772bbb1 Mon Sep 17 00:00:00 2001 From: Francesco Cogno Date: Sat, 16 Jan 2016 19:31:17 +0100 Subject: [PATCH 1/8] prepared 0.1.1 tag in CHANGELOG --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88dc42905..0e37650bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Change Log +## [0.1.1](https://github.com/MindFlavor/AzureSDKForRust/releases/tag/0.0.7) (yet-to-publish) + +**Implemented features:** + +**Refactoring:** + +**Bugfixes:** + +**Removed methods:** + ## [0.1.0](https://github.com/MindFlavor/AzureSDKForRust/releases/tag/0.0.8) (2015-01-16) **Implemented features:** From 01d9c53708e3e04e2ba131b15400244c43f1e969 Mon Sep 17 00:00:00 2001 From: Francesco Cogno Date: Sat, 16 Jan 2016 20:32:09 +0100 Subject: [PATCH 2/8] Added the non-doc option for the bin test file --- CHANGELOG.md | 6 ++++++ Cargo.toml | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e37650bc..bada70c8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ **Refactoring:** **Bugfixes:** +* Added the non-doc option for the bin test file: +```rust +[[bin]] +name = "main" +doc = false +``` **Removed methods:** diff --git a/Cargo.toml b/Cargo.toml index a8c355329..d5385724c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,10 @@ name = "azure_sdk_for_rust" version = "0.1.0" authors = ["Francesco Cogno "] +[[bin]] +name = "main" +doc = false + [dependencies] chrono = "*" rust-crypto = "^0.2" From 5165afe83e96ea50725a3f6a1368c4f88e4752a1 Mon Sep 17 00:00:00 2001 From: Francesco Cogno Date: Sun, 17 Jan 2016 19:09:46 +0100 Subject: [PATCH 3/8] Started Blob::lease --- src/azure/storage/blob/lease_blob_options.rs | 22 ++++++++++++++++++++ src/azure/storage/blob/mod.rs | 16 ++++++++++++++ src/azure/storage/container/mod.rs | 3 +++ 3 files changed, 41 insertions(+) create mode 100644 src/azure/storage/blob/lease_blob_options.rs diff --git a/src/azure/storage/blob/lease_blob_options.rs b/src/azure/storage/blob/lease_blob_options.rs new file mode 100644 index 000000000..a8bd2d06c --- /dev/null +++ b/src/azure/storage/blob/lease_blob_options.rs @@ -0,0 +1,22 @@ +#[derive(Debug, Clone, PartialEq)] +pub struct LeaseBlobOptions { + pub max_results: u32, + pub include_snapshots: bool, + pub include_metadata: bool, + pub include_uncommittedblobs: bool, + pub include_copy: bool, + pub next_marker: Option, + pub prefix: Option, + pub timeout: Option, +} + +pub const LEASE_BLOB_OPTIONS_DEFAULT: LeaseBlobOptions = LeaseBlobOptions { + max_results: 5000, + include_snapshots: false, + include_metadata: false, + include_uncommittedblobs: false, + include_copy: false, + next_marker: None, + prefix: None, + timeout: None, +}; diff --git a/src/azure/storage/blob/mod.rs b/src/azure/storage/blob/mod.rs index 05ab652c3..e180e0bd5 100644 --- a/src/azure/storage/blob/mod.rs +++ b/src/azure/storage/blob/mod.rs @@ -10,6 +10,9 @@ pub use self::put_block_options::{PutBlockOptions, PUT_BLOCK_OPTIONS_DEFAULT}; mod put_page_options; pub use self::put_page_options::{PutPageOptions, PUT_PAGE_OPTIONS_DEFAULT}; +mod lease_blob_options; +pub use self::lease_blob_options::{LeaseBlobOptions, LEASE_BLOB_OPTIONS_DEFAULT}; + use chrono::datetime::DateTime; use chrono::UTC; @@ -503,6 +506,19 @@ impl Blob { Ok(()) } + pub fn lease(&self, c: &Client, lbo: &LeaseBlobOptions) -> Result { + let mut uri = format!("{}://{}.blob.core.windows.net/{}/{}?comp=lease", + c.auth_scheme(), + c.account(), + self.container_name, + self.name); + if let Some(ref timeout) = lbo.timeout { + uri = format!("{}&timeout={}", uri, timeout); + } + + Ok("todo".parse::().unwrap()) + } + pub fn put_page(&self, c: &Client, range: &BA512Range, diff --git a/src/azure/storage/container/mod.rs b/src/azure/storage/container/mod.rs index b5a8baaee..7a3b30c6a 100644 --- a/src/azure/storage/container/mod.rs +++ b/src/azure/storage/container/mod.rs @@ -117,6 +117,9 @@ impl Container { Ok(()) } + // TODO + // pub fn get_acl(c : &Client, gao : &GetAclOptions) + pub fn list(c: &Client, lco: &ListContainerOptions) -> Result, core::errors::AzureError> { From 42c1b27a4b4dec33f016c2ddcd65327ad546f12c Mon Sep 17 00:00:00 2001 From: Francesco Cogno Date: Sun, 17 Jan 2016 19:16:27 +0100 Subject: [PATCH 4/8] Implementing Blob::lease --- src/azure/core/lease_id.rs | 6 ++++++ src/azure/storage/blob/lease_blob_options.rs | 18 ++++-------------- src/azure/storage/blob/mod.rs | 8 +++++++- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/azure/core/lease_id.rs b/src/azure/core/lease_id.rs index 22797ce35..cb99a76d8 100644 --- a/src/azure/core/lease_id.rs +++ b/src/azure/core/lease_id.rs @@ -8,6 +8,12 @@ pub struct LeaseId { id: String, } +impl LeaseId { + pub fn new(s: &str) -> LeaseId { + LeaseId { id: s.to_owned() } + } +} + impl FromStr for LeaseId { type Err = ParseError; fn from_str(s: &str) -> Result { diff --git a/src/azure/storage/blob/lease_blob_options.rs b/src/azure/storage/blob/lease_blob_options.rs index a8bd2d06c..57e9f5d77 100644 --- a/src/azure/storage/blob/lease_blob_options.rs +++ b/src/azure/storage/blob/lease_blob_options.rs @@ -1,22 +1,12 @@ +use azure::core::lease_id::LeaseId; + #[derive(Debug, Clone, PartialEq)] pub struct LeaseBlobOptions { - pub max_results: u32, - pub include_snapshots: bool, - pub include_metadata: bool, - pub include_uncommittedblobs: bool, - pub include_copy: bool, - pub next_marker: Option, - pub prefix: Option, + pub lease_id: Option, pub timeout: Option, } pub const LEASE_BLOB_OPTIONS_DEFAULT: LeaseBlobOptions = LeaseBlobOptions { - max_results: 5000, - include_snapshots: false, - include_metadata: false, - include_uncommittedblobs: false, - include_copy: false, - next_marker: None, - prefix: None, + lease_id: None, timeout: None, }; diff --git a/src/azure/storage/blob/mod.rs b/src/azure/storage/blob/mod.rs index e180e0bd5..aa7b941c9 100644 --- a/src/azure/storage/blob/mod.rs +++ b/src/azure/storage/blob/mod.rs @@ -516,7 +516,13 @@ impl Blob { uri = format!("{}&timeout={}", uri, timeout); } - Ok("todo".parse::().unwrap()) + let mut headers = Headers::new(); + + if let Some(ref lease_id) = lbo.lease_id { + headers.set(XMSLeaseId(lease_id.to_owned())); + } + + Ok(LeaseId::new(&"test")) } pub fn put_page(&self, From 832942f7332bb9b33af768981b0fc375825cb4a0 Mon Sep 17 00:00:00 2001 From: Francesco Cogno Date: Mon, 18 Jan 2016 10:26:49 +0100 Subject: [PATCH 5/8] moved enumerations in azure::core::lease --- CHANGELOG.md | 5 +++- README.md | 1 + src/azure/core/{lease_id.rs => lease.rs} | 30 ++++++++++++++++++++ src/azure/core/mod.rs | 7 +++-- src/azure/storage/blob/lease_blob_options.rs | 2 +- src/azure/storage/blob/mod.rs | 6 ++-- src/azure/storage/blob/put_block_options.rs | 2 +- src/azure/storage/blob/put_options.rs | 2 +- src/azure/storage/blob/put_page_options.rs | 2 +- src/azure/storage/container/mod.rs | 2 +- src/azure/storage/mod.rs | 25 ---------------- src/main.rs | 2 +- 12 files changed, 49 insertions(+), 37 deletions(-) rename src/azure/core/{lease_id.rs => lease.rs} (51%) diff --git a/CHANGELOG.md b/CHANGELOG.md index bada70c8e..970a4c8d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,13 @@ -# Change Log +git# Change Log ## [0.1.1](https://github.com/MindFlavor/AzureSDKForRust/releases/tag/0.0.7) (yet-to-publish) **Implemented features:** +* Lease blob (https://msdn.microsoft.com/library/azure/ee691972.aspx). **Refactoring:** +* Renamed ```azure::core::lease_id``` module in ```azure::core::lease```. +* Moved lease enumerations in ```azure::core::lease``` module. **Bugfixes:** * Added the non-doc option for the bin test file: diff --git a/README.md b/README.md index 263967682..e0897c653 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,7 @@ If you want to contribute please do! No formality required! :wink: |Put blob page|[https://msdn.microsoft.com/en-us/library/azure/dd179451.aspx](https://msdn.microsoft.com/en-us/library/azure/dd179451.aspx)| |Clear blob page|[https://msdn.microsoft.com/en-us/library/azure/dd179451.aspx](https://msdn.microsoft.com/en-us/library/azure/dd179451.aspx)| |Put block|[https://msdn.microsoft.com/en-us/library/azure/dd135726.aspx](https://msdn.microsoft.com/en-us/library/azure/dd135726.aspx)| +|Lease blob|[https://msdn.microsoft.com/library/azure/ee691972.aspx](https://msdn.microsoft.com/library/azure/ee691972.aspx)| ## License This project is published under [The MIT License (MIT)](LICENSE). diff --git a/src/azure/core/lease_id.rs b/src/azure/core/lease.rs similarity index 51% rename from src/azure/core/lease_id.rs rename to src/azure/core/lease.rs index cb99a76d8..d4506a798 100644 --- a/src/azure/core/lease_id.rs +++ b/src/azure/core/lease.rs @@ -2,6 +2,36 @@ use std::str::FromStr; use std::string::ParseError; use std::fmt::{Display, Formatter}; use std::fmt; +use azure::core::enumerations; +use azure::core::errors::TraversingError; +use azure::core::parsing::FromStringOptional; + +create_enum!(LeaseStatus, + (Locked, "locked"), + (Unlocked, "unlocked") +); + +create_enum!(LeaseState, + (Available, "available"), + (Leased, "leased"), + (Expired, "expired"), + (Breaking, "breaking"), + (Broken, "broken") +); + +create_enum!(LeaseDuration, + (Infinite, "infinite"), + (Fixed, "fixed") +); + +create_enum!(LeaseAction, + (Acquire, "acquire"), + (Renew, "renew "), + (Change, "change"), + (Release, "release "), + (Break, "break") +); + #[derive(Debug, Clone, PartialEq)] pub struct LeaseId { diff --git a/src/azure/core/mod.rs b/src/azure/core/mod.rs index 7d967b158..079227276 100644 --- a/src/azure/core/mod.rs +++ b/src/azure/core/mod.rs @@ -20,7 +20,7 @@ use chrono; use std::io::Read; -use azure::storage::{LeaseStatus, LeaseState, LeaseDuration}; +use azure::core::lease::{LeaseId, LeaseStatus, LeaseState, LeaseDuration, LeaseAction}; #[macro_use] pub mod errors; @@ -28,7 +28,7 @@ pub mod parsing; #[macro_use] pub mod enumerations; pub mod incompletevector; -pub mod lease_id; +pub mod lease; pub mod range; pub mod ba512_range; @@ -51,9 +51,10 @@ header! { (IfMatch, "If-Match") => [String] } header! { (IfNoneMatch, "If-None-Match") => [String] } header! { (Range, "Range") => [String] } header! { (XMSRange, "x-ms-range") => [range::Range] } -header! { (XMSLeaseId, "x-ms-lease-id") => [lease_id::LeaseId] } +header! { (XMSLeaseId, "x-ms-lease-id") => [LeaseId] } header! { (XMSLeaseStatus, "x-ms-lease-status") => [LeaseStatus] } header! { (XMSLeaseState, "x-ms-lease-state") => [LeaseState] } +header! { (XMSLeaseAction, "x-ms-lease-action") => [LeaseAction] } header! { (XMSLeaseDuration, "x-ms-lease-duration") => [LeaseDuration] } header! { (ETag, "ETag") => [String] } header! { (XMSRangeGetContentMD5, "x-ms-range-get-content-md5") => [bool] } diff --git a/src/azure/storage/blob/lease_blob_options.rs b/src/azure/storage/blob/lease_blob_options.rs index 57e9f5d77..c5dfe8f30 100644 --- a/src/azure/storage/blob/lease_blob_options.rs +++ b/src/azure/storage/blob/lease_blob_options.rs @@ -1,4 +1,4 @@ -use azure::core::lease_id::LeaseId; +use azure::core::lease::LeaseId; #[derive(Debug, Clone, PartialEq)] pub struct LeaseBlobOptions { diff --git a/src/azure/storage/blob/mod.rs b/src/azure/storage/blob/mod.rs index aa7b941c9..c1e096ef5 100644 --- a/src/azure/storage/blob/mod.rs +++ b/src/azure/storage/blob/mod.rs @@ -16,13 +16,13 @@ pub use self::lease_blob_options::{LeaseBlobOptions, LEASE_BLOB_OPTIONS_DEFAULT} use chrono::datetime::DateTime; use chrono::UTC; -use azure::storage::{LeaseStatus, LeaseState, LeaseDuration}; +use azure::core::lease::{LeaseId, LeaseStatus, LeaseState, LeaseDuration}; use azure::storage::client::Client; use azure::core; use azure::core::{XMSRange, ContentMD5, XMSLeaseStatus, XMSLeaseDuration, XMSLeaseState, XMSLeaseId, XMSRangeGetContentMD5, XMSClientRequestId}; -use azure::core::lease_id::LeaseId; + use azure::core::parsing::{cast_must, cast_optional, from_azure_time, traverse}; use xml::Element; @@ -522,6 +522,8 @@ impl Blob { headers.set(XMSLeaseId(lease_id.to_owned())); } + + Ok(LeaseId::new(&"test")) } diff --git a/src/azure/storage/blob/put_block_options.rs b/src/azure/storage/blob/put_block_options.rs index 8d8006ddc..69f590dd5 100644 --- a/src/azure/storage/blob/put_block_options.rs +++ b/src/azure/storage/blob/put_block_options.rs @@ -1,4 +1,4 @@ -use azure::core::lease_id::LeaseId; +use azure::core::lease::LeaseId; #[derive(Debug, Clone, PartialEq)] pub struct PutBlockOptions { diff --git a/src/azure/storage/blob/put_options.rs b/src/azure/storage/blob/put_options.rs index d451b9944..502053575 100644 --- a/src/azure/storage/blob/put_options.rs +++ b/src/azure/storage/blob/put_options.rs @@ -1,4 +1,4 @@ -use azure::core::lease_id::LeaseId; +use azure::core::lease::LeaseId; #[derive(Debug, Clone, PartialEq)] pub struct PutOptions { diff --git a/src/azure/storage/blob/put_page_options.rs b/src/azure/storage/blob/put_page_options.rs index 8e7a3bca3..79f352a73 100644 --- a/src/azure/storage/blob/put_page_options.rs +++ b/src/azure/storage/blob/put_page_options.rs @@ -1,4 +1,4 @@ -use azure::core::lease_id::LeaseId; +use azure::core::lease::LeaseId; #[derive(Debug, Clone, PartialEq)] pub struct PutPageOptions { diff --git a/src/azure/storage/container/mod.rs b/src/azure/storage/container/mod.rs index 7a3b30c6a..33753dbcf 100644 --- a/src/azure/storage/container/mod.rs +++ b/src/azure/storage/container/mod.rs @@ -7,7 +7,7 @@ use azure::core::enumerations; use azure::core::parsing::{traverse, cast_must, cast_optional}; use azure::core::incompletevector::IncompleteVector; -use azure::storage::{LeaseStatus, LeaseState, LeaseDuration}; +use azure::core::lease::{LeaseStatus, LeaseState, LeaseDuration}; use azure::storage::client::Client; use hyper::header::Headers; diff --git a/src/azure/storage/mod.rs b/src/azure/storage/mod.rs index b6ada4928..1844cce14 100644 --- a/src/azure/storage/mod.rs +++ b/src/azure/storage/mod.rs @@ -1,28 +1,3 @@ pub mod client; pub mod container; pub mod blob; - -use std::fmt; -use std::str::FromStr; -use azure::core::enumerations; - -use azure::core::errors::TraversingError; -use azure::core::parsing::FromStringOptional; - -create_enum!(LeaseStatus, - (Locked, "locked"), - (Unlocked, "unlocked") -); - -create_enum!(LeaseState, - (Available, "available"), - (Leased, "leased"), - (Expired, "expired"), - (Breaking, "breaking"), - (Broken, "broken") -); - -create_enum!(LeaseDuration, - (Infinite, "infinite"), - (Fixed, "fixed") -); diff --git a/src/main.rs b/src/main.rs index 9cdf66265..ce2e2d366 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,7 @@ extern crate log; extern crate env_logger; -use azure::storage::{LeaseState, LeaseStatus}; +use azure::core::lease::{LeaseState, LeaseStatus}; use azure::storage::client::Client; use azure::storage::blob::{Blob, BlobType, ListBlobOptions, LIST_BLOB_OPTIONS_DEFAULT, PUT_OPTIONS_DEFAULT, PUT_BLOCK_OPTIONS_DEFAULT, From 125b50dfd557af1173344278eb311bd42d468d0e Mon Sep 17 00:00:00 2001 From: Francesco Cogno Date: Mon, 18 Jan 2016 10:58:36 +0100 Subject: [PATCH 6/8] Before migrating leaseid to uuid --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/azure/core/mod.rs | 5 ++++ src/azure/storage/blob/lease_blob_options.rs | 8 +++++++ src/azure/storage/blob/mod.rs | 24 +++++++++++++++++--- 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4c19f9790..b95d9430c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ [root] name = "azure_sdk_for_rust" -version = "0.1.0" +version = "0.1.1" dependencies = [ "RustyXML 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index d5385724c..2e4b83ff0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "azure_sdk_for_rust" -version = "0.1.0" +version = "0.1.1" authors = ["Francesco Cogno "] [[bin]] diff --git a/src/azure/core/mod.rs b/src/azure/core/mod.rs index 079227276..8c46964af 100644 --- a/src/azure/core/mod.rs +++ b/src/azure/core/mod.rs @@ -56,10 +56,15 @@ header! { (XMSLeaseStatus, "x-ms-lease-status") => [LeaseStatus] } header! { (XMSLeaseState, "x-ms-lease-state") => [LeaseState] } header! { (XMSLeaseAction, "x-ms-lease-action") => [LeaseAction] } header! { (XMSLeaseDuration, "x-ms-lease-duration") => [LeaseDuration] } +header! { (XMSLeaseDurationSeconds, "x-ms-lease-duration") => [u32] } +header! { (XMSLeaseBreakPeriod, "x-ms-lease-break-period") => [u32] } +header! { (XMSProposedLeaseId, "x-ms-proposed-lease-id") => [LeaseId] } header! { (ETag, "ETag") => [String] } header! { (XMSRangeGetContentMD5, "x-ms-range-get-content-md5") => [bool] } header! { (XMSClientRequestId, "x-ms-client-request-id") => [String] } + + pub fn generate_authorization(h: &Headers, u: &url::Url, method: HTTPMethod, diff --git a/src/azure/storage/blob/lease_blob_options.rs b/src/azure/storage/blob/lease_blob_options.rs index c5dfe8f30..f2f21f4e5 100644 --- a/src/azure/storage/blob/lease_blob_options.rs +++ b/src/azure/storage/blob/lease_blob_options.rs @@ -4,9 +4,17 @@ use azure::core::lease::LeaseId; pub struct LeaseBlobOptions { pub lease_id: Option, pub timeout: Option, + pub lease_break_period: Option, + pub lease_duration: Option, + pub proposed_lease_id: Option, + pub request_id: Option, } pub const LEASE_BLOB_OPTIONS_DEFAULT: LeaseBlobOptions = LeaseBlobOptions { lease_id: None, timeout: None, + lease_break_period: None, + lease_duration: None, + proposed_lease_id: None, + request_id: None, }; diff --git a/src/azure/storage/blob/mod.rs b/src/azure/storage/blob/mod.rs index c1e096ef5..f8e1c43d0 100644 --- a/src/azure/storage/blob/mod.rs +++ b/src/azure/storage/blob/mod.rs @@ -16,12 +16,13 @@ pub use self::lease_blob_options::{LeaseBlobOptions, LEASE_BLOB_OPTIONS_DEFAULT} use chrono::datetime::DateTime; use chrono::UTC; -use azure::core::lease::{LeaseId, LeaseStatus, LeaseState, LeaseDuration}; +use azure::core::lease::{LeaseId, LeaseStatus, LeaseState, LeaseDuration, LeaseAction}; use azure::storage::client::Client; use azure::core; use azure::core::{XMSRange, ContentMD5, XMSLeaseStatus, XMSLeaseDuration, XMSLeaseState, - XMSLeaseId, XMSRangeGetContentMD5, XMSClientRequestId}; + XMSLeaseId, XMSRangeGetContentMD5, XMSClientRequestId, XMSLeaseAction, + XMSLeaseDurationSeconds, XMSLeaseBreakPeriod, XMSProposedLeaseId}; use azure::core::parsing::{cast_must, cast_optional, from_azure_time, traverse}; @@ -506,7 +507,11 @@ impl Blob { Ok(()) } - pub fn lease(&self, c: &Client, lbo: &LeaseBlobOptions) -> Result { + pub fn lease(&self, + c: &Client, + la: LeaseAction, + lbo: &LeaseBlobOptions) + -> Result { let mut uri = format!("{}://{}.blob.core.windows.net/{}/{}?comp=lease", c.auth_scheme(), c.account(), @@ -522,7 +527,20 @@ impl Blob { headers.set(XMSLeaseId(lease_id.to_owned())); } + headers.set(XMSLeaseAction(la)); + if let Some(lease_break_period) = lbo.lease_break_period { + headers.set(XMSLeaseBreakPeriod(lease_break_period)); + } + if let Some(lease_duration) = lbo.lease_duration { + headers.set(XMSLeaseDurationSeconds(lease_duration)); + } + if let Some(ref proposed_lease_id) = lbo.proposed_lease_id { + headers.set(XMSProposedLeaseId(proposed_lease_id.clone())); + } + if let Some(ref request_id) = lbo.request_id { + headers.set(XMSClientRequestId(request_id.to_owned())); + } Ok(LeaseId::new(&"test")) } From 5bf3b6cbb3839db79ccb5603f6e2be606ffe4698 Mon Sep 17 00:00:00 2001 From: Francesco Cogno Date: Mon, 18 Jan 2016 11:45:04 +0100 Subject: [PATCH 7/8] Added Blob::lease --- Cargo.lock | 1 + Cargo.toml | 1 + src/azure/core/lease.rs | 54 ++--------------------------------- src/azure/core/mod.rs | 2 -- src/azure/storage/blob/mod.rs | 22 +++++++++++++- src/lib.rs | 2 ++ src/main.rs | 28 +++++++++++++++--- 7 files changed, 51 insertions(+), 59 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b95d9430c..87b6f2eed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,6 +11,7 @@ dependencies = [ "rust-crypto 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.5.2 (git+https://github.com/servo/rust-url)", + "uuid 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 2e4b83ff0..5218405fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ RustyXML = "*" mime = "*" log = "0.3" env_logger = "0.3" +uuid = "^0.1" [dependencies.hyper] version = "*" diff --git a/src/azure/core/lease.rs b/src/azure/core/lease.rs index d4506a798..7981b5ca3 100644 --- a/src/azure/core/lease.rs +++ b/src/azure/core/lease.rs @@ -5,6 +5,7 @@ use std::fmt; use azure::core::enumerations; use azure::core::errors::TraversingError; use azure::core::parsing::FromStringOptional; +use uuid::Uuid; create_enum!(LeaseStatus, (Locked, "locked"), @@ -32,55 +33,4 @@ create_enum!(LeaseAction, (Break, "break") ); - -#[derive(Debug, Clone, PartialEq)] -pub struct LeaseId { - id: String, -} - -impl LeaseId { - pub fn new(s: &str) -> LeaseId { - LeaseId { id: s.to_owned() } - } -} - -impl FromStr for LeaseId { - type Err = ParseError; - fn from_str(s: &str) -> Result { - Ok(LeaseId { id: s.to_owned() }) - } -} - -impl Display for LeaseId { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { - write!(f, "{}", self.id) - } -} - -impl LeaseId { - pub fn id(&self) -> &str { - &self.id - } - - pub fn set_id(&mut self, id: &str) { - self.id = id.to_owned(); - } -} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn test_lease_parse() { - let lease = "id".parse::().unwrap(); - assert_eq!(lease.id(), "id"); - } - - #[test] - fn test_lease_display() { - let lease = "id".parse::().unwrap(); - let r = format!("{}", lease); - assert_eq!(r, "id"); - } -} +pub type LeaseId = Uuid; diff --git a/src/azure/core/mod.rs b/src/azure/core/mod.rs index 8c46964af..f6f7898de 100644 --- a/src/azure/core/mod.rs +++ b/src/azure/core/mod.rs @@ -63,8 +63,6 @@ header! { (ETag, "ETag") => [String] } header! { (XMSRangeGetContentMD5, "x-ms-range-get-content-md5") => [bool] } header! { (XMSClientRequestId, "x-ms-client-request-id") => [String] } - - pub fn generate_authorization(h: &Headers, u: &url::Url, method: HTTPMethod, diff --git a/src/azure/storage/blob/mod.rs b/src/azure/storage/blob/mod.rs index f8e1c43d0..016a80e4a 100644 --- a/src/azure/storage/blob/mod.rs +++ b/src/azure/storage/blob/mod.rs @@ -1,3 +1,5 @@ +extern crate uuid; + mod put_options; pub use self::put_options::{PutOptions, PUT_OPTIONS_DEFAULT}; @@ -52,6 +54,7 @@ use hyper::header::{Headers, ContentType, ContentLength, LastModified, ContentEn use serialize::base64::{STANDARD, ToBase64}; +use uuid::Uuid; create_enum!(BlobType, (BlockBlob, "BlockBlob"), @@ -542,7 +545,24 @@ impl Blob { headers.set(XMSClientRequestId(request_id.to_owned())); } - Ok(LeaseId::new(&"test")) + let mut resp = try!(c.perform_request(&uri, core::HTTPMethod::Put, &headers, None)); + + let expected_result = match la { + LeaseAction::Acquire => StatusCode::Created, + LeaseAction::Renew => StatusCode::Ok, + LeaseAction::Change => StatusCode::Ok, + LeaseAction::Release => StatusCode::Ok, + LeaseAction::Break => StatusCode::Accepted, + }; + + try!(core::errors::check_status(&mut resp, expected_result)); + + let lid = match resp.headers.get::() { + Some(l) => l as &Uuid, + None => return Err(AzureError::HeaderNotFound("x-ms-lease-id".to_owned())), + }; + + Ok(lid.clone()) } pub fn put_page(&self, diff --git a/src/lib.rs b/src/lib.rs index 84d17e317..014ed5856 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,6 +5,8 @@ extern crate url; extern crate crypto; extern crate rustc_serialize as serialize; extern crate xml; +extern crate uuid; + #[macro_use] extern crate mime; diff --git a/src/main.rs b/src/main.rs index ce2e2d366..8920111f2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,12 +12,13 @@ extern crate mime; extern crate log; extern crate env_logger; +extern crate uuid; -use azure::core::lease::{LeaseState, LeaseStatus}; +use azure::core::lease::{LeaseState, LeaseStatus, LeaseAction}; use azure::storage::client::Client; use azure::storage::blob::{Blob, BlobType, ListBlobOptions, LIST_BLOB_OPTIONS_DEFAULT, PUT_OPTIONS_DEFAULT, PUT_BLOCK_OPTIONS_DEFAULT, - PUT_PAGE_OPTIONS_DEFAULT}; + PUT_PAGE_OPTIONS_DEFAULT, LEASE_BLOB_OPTIONS_DEFAULT}; use azure::storage::container::{Container, PublicAccess, LIST_CONTAINER_OPTIONS_DEFAULT}; use azure::core::ba512_range::BA512Range; @@ -56,9 +57,11 @@ fn main() { info!("Beginning tests"); - put_block_blob(&client); + lease_blob(&client); - put_page_blob(&client); + // put_block_blob(&client); + // + // put_page_blob(&client); // { // let vhds = ret.iter_mut().find(|x| x.name == "canotto").unwrap(); @@ -148,6 +151,23 @@ fn main() { // inc_a!("main"); } +fn lease_blob(client: &Client) { + println!("running lease_blob"); + + let ret = Container::list(client, &LIST_CONTAINER_OPTIONS_DEFAULT).unwrap(); + let vhds = ret.iter().find(|x| x.name == "rust").unwrap(); + let blobs = Blob::list(&client, &vhds.name, &LIST_BLOB_OPTIONS_DEFAULT).unwrap(); + let blob = blobs.iter().find(|ref x| x.name == "go_rust12.txt").unwrap(); + + println!("blob == {:?}", blob); + + let mut lbo = LEASE_BLOB_OPTIONS_DEFAULT.clone(); + lbo.lease_duration = Some(30); + let ret = blob.lease(client, LeaseAction::Acquire, &lbo).unwrap(); + println!("ret == {:?}", ret); + +} + fn list_blobs(client: &Client) { println!("running list_blobs"); From eaa0bc36ee6cd64fac4d967730b90174c3048f91 Mon Sep 17 00:00:00 2001 From: Francesco Cogno Date: Mon, 18 Jan 2016 11:47:24 +0100 Subject: [PATCH 8/8] Published on changelog 0.1.1 --- CHANGELOG.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 970a4c8d4..a64e8a0f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ git# Change Log -## [0.1.1](https://github.com/MindFlavor/AzureSDKForRust/releases/tag/0.0.7) (yet-to-publish) +## [0.1.1](https://github.com/MindFlavor/AzureSDKForRust/releases/tag/0.0.7) (2016-01-18) **Implemented features:** * Lease blob (https://msdn.microsoft.com/library/azure/ee691972.aspx). @@ -17,8 +17,6 @@ name = "main" doc = false ``` -**Removed methods:** - ## [0.1.0](https://github.com/MindFlavor/AzureSDKForRust/releases/tag/0.0.8) (2015-01-16) **Implemented features:**