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

Commit

Permalink
Merge pull request #8 from MindFlavor/work
Browse files Browse the repository at this point in the history
Lease blob
  • Loading branch information
MindFlavor committed Jan 18, 2016
2 parents 0db0aec + eaa0bc3 commit d26d052
Show file tree
Hide file tree
Showing 16 changed files with 188 additions and 92 deletions.
19 changes: 18 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
# Change Log
git# Change Log

## [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).

**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:
```rust
[[bin]]
name = "main"
doc = false
```

## [0.1.0](https://github.com/MindFlavor/AzureSDKForRust/releases/tag/0.0.8) (2015-01-16)

Expand Down
3 changes: 2 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
[package]
name = "azure_sdk_for_rust"
version = "0.1.0"
version = "0.1.1"
authors = ["Francesco Cogno <[email protected]>"]

[[bin]]
name = "main"
doc = false

[dependencies]
chrono = "*"
rust-crypto = "^0.2"
Expand All @@ -11,6 +15,7 @@ RustyXML = "*"
mime = "*"
log = "0.3"
env_logger = "0.3"
uuid = "^0.1"

[dependencies.hyper]
version = "*"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
36 changes: 36 additions & 0 deletions src/azure/core/lease.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;
use uuid::Uuid;

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")
);

pub type LeaseId = Uuid;
50 changes: 0 additions & 50 deletions src/azure/core/lease_id.rs

This file was deleted.

10 changes: 7 additions & 3 deletions src/azure/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ 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;
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;
Expand All @@ -51,10 +51,14 @@ 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! { (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] }
Expand Down
20 changes: 20 additions & 0 deletions src/azure/storage/blob/lease_blob_options.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use azure::core::lease::LeaseId;

#[derive(Debug, Clone, PartialEq)]
pub struct LeaseBlobOptions {
pub lease_id: Option<LeaseId>,
pub timeout: Option<u64>,
pub lease_break_period: Option<u32>,
pub lease_duration: Option<u32>,
pub proposed_lease_id: Option<LeaseId>,
pub request_id: Option<String>,
}

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,
};
68 changes: 65 additions & 3 deletions src/azure/storage/blob/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
extern crate uuid;

mod put_options;
pub use self::put_options::{PutOptions, PUT_OPTIONS_DEFAULT};

Expand All @@ -10,16 +12,20 @@ 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;

use azure::storage::{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};
use azure::core::lease_id::LeaseId;
XMSLeaseId, XMSRangeGetContentMD5, XMSClientRequestId, XMSLeaseAction,
XMSLeaseDurationSeconds, XMSLeaseBreakPeriod, XMSProposedLeaseId};

use azure::core::parsing::{cast_must, cast_optional, from_azure_time, traverse};

use xml::Element;
Expand Down Expand Up @@ -48,6 +54,7 @@ use hyper::header::{Headers, ContentType, ContentLength, LastModified, ContentEn

use serialize::base64::{STANDARD, ToBase64};

use uuid::Uuid;

create_enum!(BlobType,
(BlockBlob, "BlockBlob"),
Expand Down Expand Up @@ -503,6 +510,61 @@ impl Blob {
Ok(())
}

pub fn lease(&self,
c: &Client,
la: LeaseAction,
lbo: &LeaseBlobOptions)
-> Result<LeaseId, AzureError> {
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);
}

let mut headers = Headers::new();

if let Some(ref lease_id) = lbo.lease_id {
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()));
}

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::<XMSLeaseId>() {
Some(l) => l as &Uuid,
None => return Err(AzureError::HeaderNotFound("x-ms-lease-id".to_owned())),
};

Ok(lid.clone())
}

pub fn put_page(&self,
c: &Client,
range: &BA512Range,
Expand Down
2 changes: 1 addition & 1 deletion src/azure/storage/blob/put_block_options.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use azure::core::lease_id::LeaseId;
use azure::core::lease::LeaseId;

#[derive(Debug, Clone, PartialEq)]
pub struct PutBlockOptions {
Expand Down
2 changes: 1 addition & 1 deletion src/azure/storage/blob/put_options.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use azure::core::lease_id::LeaseId;
use azure::core::lease::LeaseId;

#[derive(Debug, Clone, PartialEq)]
pub struct PutOptions {
Expand Down
2 changes: 1 addition & 1 deletion src/azure/storage/blob/put_page_options.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use azure::core::lease_id::LeaseId;
use azure::core::lease::LeaseId;

#[derive(Debug, Clone, PartialEq)]
pub struct PutPageOptions {
Expand Down
5 changes: 4 additions & 1 deletion src/azure/storage/container/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -117,6 +117,9 @@ impl Container {
Ok(())
}

// TODO
// pub fn get_acl(c : &Client, gao : &GetAclOptions)

pub fn list(c: &Client,
lco: &ListContainerOptions)
-> Result<IncompleteVector<Container>, core::errors::AzureError> {
Expand Down
25 changes: 0 additions & 25 deletions src/azure/storage/mod.rs
Original file line number Diff line number Diff line change
@@ -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")
);
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Loading

0 comments on commit d26d052

Please sign in to comment.