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

Commit e2e9789

Browse files
authored
Merge pull request #60 from MindFlavor/feat/container/lease_container/pr
Implemented container::break_lease
2 parents 549c3ce + a32ab8e commit e2e9789

14 files changed

+449
-13
lines changed

README.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,16 @@ If you want to contribute please do! No formality required! :wink:. Please note
202202

203203
| Method | URL | Builder pattern
204204
| ---- | --- | ---
205-
| Create container | [https://msdn.microsoft.com/en-us/library/azure/dd179468.aspx](https://msdn.microsoft.com/en-us/library/azure/dd179468.aspx) | yes
206-
| List containers | [https://msdn.microsoft.com/en-us/library/azure/dd179352.aspx](https://msdn.microsoft.com/en-us/library/azure/dd179352.aspx) | yes
207-
| Delete container | [https://msdn.microsoft.com/en-us/library/azure/dd179408.aspx](https://msdn.microsoft.com/en-us/library/azure/dd179408.aspx) | yes
205+
| Create container | [https://docs.microsoft.com/en-us/rest/api/storageservices/create-container](https://docs.microsoft.com/en-us/rest/api/storageservices/create-container) | yes
206+
| List containers | [https://docs.microsoft.com/en-us/rest/api/storageservices/list-containers2](https://docs.microsoft.com/en-us/rest/api/storageservices/list-containers2) | yes
207+
| Delete container | [https://docs.microsoft.com/en-us/rest/api/storageservices/delete-container](https://docs.microsoft.com/en-us/rest/api/storageservices/delete-container) | yes
208208
| Get ACLs | [https://docs.microsoft.com/en-us/rest/api/storageservices/get-container-acl](https://docs.microsoft.com/en-us/rest/api/storageservices/get-container-acl) | yes
209209
| Set ACLs | [https://docs.microsoft.com/en-us/rest/api/storageservices/set-container-acl](https://docs.microsoft.com/en-us/rest/api/storageservices/set-container-acl) | yes
210210
| Get properties | [https://docs.microsoft.com/en-us/rest/api/storageservices/get-container-properties](https://docs.microsoft.com/en-us/rest/api/storageservices/get-container-properties) | yes
211+
| Acquire lease | [https://docs.microsoft.com/en-us/rest/api/storageservices/lease-container](https://docs.microsoft.com/en-us/rest/api/storageservices/lease-container) | yes
212+
| Break lease | [https://docs.microsoft.com/en-us/rest/api/storageservices/lease-container](https://docs.microsoft.com/en-us/rest/api/storageservices/lease-container) | yes
213+
| Release lease | [https://docs.microsoft.com/en-us/rest/api/storageservices/lease-container](https://docs.microsoft.com/en-us/rest/api/storageservices/lease-container) | yes
214+
| Renew lease | [https://docs.microsoft.com/en-us/rest/api/storageservices/lease-container](https://docs.microsoft.com/en-us/rest/api/storageservices/lease-container) | yes
211215

212216
#### Storage blobs
213217

src/azure/core/headers.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ pub const HAS_IMMUTABILITY_POLICY: &str = "x-ms-has-immutability-policy";
99
pub const HAS_LEGAL_HOLD: &str = "x-ms-has-legal-hold";
1010
pub const META_PREFIX: &str = "x-ms-meta-";
1111
pub const LEASE_ACTION: &str = "x-ms-lease-action"; //=> [LeaseAction] }
12+
pub const LEASE_BREAK_PERIOD: &str = "x-ms-lease-break-period"; //=> [u32] }
1213
pub const PROPOSED_LEASE_ID: &str = "x-ms-proposed-lease-id"; //=> [LeaseId] }
14+
pub const LEASE_TIME: &str = "x-ms-lease-time";

src/azure/core/mod.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ define_encode_set! {
2020
}
2121
}
2222
pub mod headers;
23-
use self::headers::{CLIENT_REQUEST_ID, LEASE_DURATION, LEASE_ID, PROPOSED_LEASE_ID};
23+
use self::headers::{CLIENT_REQUEST_ID, LEASE_BREAK_PERIOD, LEASE_DURATION, LEASE_ID, PROPOSED_LEASE_ID};
2424
use uuid::Uuid;
2525
pub type RequestId = Uuid;
2626
use azure::core::lease::LeaseId;
@@ -173,6 +173,21 @@ pub trait ProposedLeaseIdRequired<'a> {
173173
}
174174
}
175175

176+
pub trait LeaseBreakPeriodSupport {
177+
type O;
178+
fn with_lease_break_period(self, lease_break_period: u8) -> Self::O;
179+
}
180+
181+
pub trait LeaseBreakPeriodOption {
182+
fn lease_break_period(&self) -> Option<u8>;
183+
184+
fn add_header(&self, builder: &mut Builder) {
185+
if let Some(lease_break_period) = self.lease_break_period() {
186+
builder.header(LEASE_BREAK_PERIOD, &lease_break_period.to_string() as &str);
187+
}
188+
}
189+
}
190+
176191
pub trait ContainerNameSupport<'a> {
177192
type O;
178193
fn with_container_name(self, container_name: &'a str) -> Self::O;

src/azure/storage/blob/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ mod get_block_list_response;
3535
pub use self::get_block_list_response::GetBlockListResponse;
3636

3737
use azure::core::headers::{
38-
CLIENT_REQUEST_ID, LEASE_ACTION, LEASE_DURATION, LEASE_ID, LEASE_STATE, LEASE_STATUS, PROPOSED_LEASE_ID, REQUEST_ID,
38+
CLIENT_REQUEST_ID, LEASE_ACTION, LEASE_BREAK_PERIOD, LEASE_DURATION, LEASE_ID, LEASE_STATE, LEASE_STATUS, PROPOSED_LEASE_ID, REQUEST_ID,
3939
};
4040
use base64;
4141
use chrono::{DateTime, Utc};
@@ -500,7 +500,7 @@ impl Blob {
500500
request.header_formatted(LEASE_ACTION, la);
501501

502502
if let Some(lease_break_period) = lbo.lease_break_period {
503-
request.header_formatted(HEADER_LEASE_BREAK_PERIOD, lease_break_period);
503+
request.header_formatted(LEASE_BREAK_PERIOD, lease_break_period);
504504
}
505505
if let Some(lease_duration) = lbo.lease_duration {
506506
request.header_formatted(LEASE_DURATION, lease_duration);

src/azure/storage/client.rs

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub trait Container {
1919
fn acquire_lease<'a>(&'a self) -> container::requests::AcquireLeaseBuilder<'a, No, No>;
2020
fn renew_lease<'a>(&'a self) -> container::requests::RenewLeaseBuilder<'a, No, No>;
2121
fn release_lease<'a>(&'a self) -> container::requests::ReleaseLeaseBuilder<'a, No, No>;
22+
fn break_lease<'a>(&'a self) -> container::requests::BreakLeaseBuilder<'a, No>;
2223
}
2324

2425
#[derive(Debug)]
@@ -64,6 +65,10 @@ impl Container for Client {
6465
fn release_lease<'a>(&'a self) -> container::requests::ReleaseLeaseBuilder<'a, No, No> {
6566
container::requests::ReleaseLeaseBuilder::new(self)
6667
}
68+
69+
fn break_lease<'a>(&'a self) -> container::requests::BreakLeaseBuilder<'a, No> {
70+
container::requests::BreakLeaseBuilder::new(self)
71+
}
6772
}
6873

6974
impl Client {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"name": "BreakLeaseBuilder",
3+
"extra_types": [ "'a" ],
4+
"constructor_fields": [
5+
{
6+
"name": "client",
7+
"field_type": "&'a Client",
8+
"trait_get": "ClientRequired<'a>"
9+
}
10+
],
11+
"fields": [
12+
{
13+
"name": "container_name",
14+
"field_type": "&'a str",
15+
"builder_type": "ContainerNameSet",
16+
"optional": false,
17+
"trait_get": "ContainerNameRequired<'a>",
18+
"trait_set": "ContainerNameSupport<'a>"
19+
},
20+
{
21+
"name": "client_request_id",
22+
"field_type": "&'a str",
23+
"optional": true,
24+
"trait_get": "ClientRequestIdOption<'a>",
25+
"trait_set": "ClientRequestIdSupport<'a>"
26+
},
27+
{
28+
"name": "timeout",
29+
"field_type": "u64",
30+
"optional": true,
31+
"trait_get": "TimeoutOption",
32+
"trait_set": "TimeoutSupport"
33+
},
34+
{
35+
"name": "lease_break_period",
36+
"field_type": "u8",
37+
"optional": true,
38+
"trait_get": "LeaseBreakPeriodOption",
39+
"trait_set": "LeaseBreakPeriodSupport"
40+
},
41+
{
42+
"name": "lease_id",
43+
"field_type": "&'a LeaseId",
44+
"optional": true,
45+
"trait_get": "LeaseIdOption<'a>",
46+
"trait_set": "LeaseIdSupport<'a>"
47+
}
48+
]
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
use azure::core::errors::{check_status_extract_headers_and_body, AzureError};
2+
use azure::core::headers::LEASE_ACTION;
3+
use azure::core::lease::LeaseId;
4+
use azure::core::{
5+
ClientRequestIdOption, ClientRequestIdSupport, ClientRequired, ContainerNameRequired, ContainerNameSupport, LeaseBreakPeriodOption,
6+
LeaseBreakPeriodSupport, LeaseIdOption, LeaseIdSupport, TimeoutOption, TimeoutSupport,
7+
};
8+
use azure::core::{No, ToAssign, Yes};
9+
use azure::storage::client::Client;
10+
use azure::storage::container::responses::BreakLeaseResponse;
11+
use futures::future::{done, Future};
12+
use hyper::{Method, StatusCode};
13+
use std::marker::PhantomData;
14+
15+
#[derive(Debug, Clone)]
16+
pub struct BreakLeaseBuilder<'a, ContainerNameSet>
17+
where
18+
ContainerNameSet: ToAssign,
19+
{
20+
client: &'a Client,
21+
p_container_name: PhantomData<ContainerNameSet>,
22+
container_name: Option<&'a str>,
23+
client_request_id: Option<&'a str>,
24+
timeout: Option<u64>,
25+
lease_break_period: Option<u8>,
26+
lease_id: Option<&'a LeaseId>,
27+
}
28+
29+
impl<'a> BreakLeaseBuilder<'a, No> {
30+
pub(crate) fn new(client: &'a Client) -> BreakLeaseBuilder<'a, No> {
31+
BreakLeaseBuilder {
32+
client,
33+
p_container_name: PhantomData {},
34+
container_name: None,
35+
client_request_id: None,
36+
timeout: None,
37+
lease_break_period: None,
38+
lease_id: None,
39+
}
40+
}
41+
}
42+
43+
impl<'a, ContainerNameSet> ClientRequired<'a> for BreakLeaseBuilder<'a, ContainerNameSet>
44+
where
45+
ContainerNameSet: ToAssign,
46+
{
47+
fn client(&self) -> &'a Client {
48+
self.client
49+
}
50+
}
51+
52+
impl<'a> ContainerNameRequired<'a> for BreakLeaseBuilder<'a, Yes> {
53+
fn container_name(&self) -> &'a str {
54+
self.container_name.unwrap()
55+
}
56+
}
57+
58+
impl<'a, ContainerNameSet> ClientRequestIdOption<'a> for BreakLeaseBuilder<'a, ContainerNameSet>
59+
where
60+
ContainerNameSet: ToAssign,
61+
{
62+
fn client_request_id(&self) -> Option<&'a str> {
63+
self.client_request_id
64+
}
65+
}
66+
67+
impl<'a, ContainerNameSet> TimeoutOption for BreakLeaseBuilder<'a, ContainerNameSet>
68+
where
69+
ContainerNameSet: ToAssign,
70+
{
71+
fn timeout(&self) -> Option<u64> {
72+
self.timeout
73+
}
74+
}
75+
76+
impl<'a, ContainerNameSet> LeaseBreakPeriodOption for BreakLeaseBuilder<'a, ContainerNameSet>
77+
where
78+
ContainerNameSet: ToAssign,
79+
{
80+
fn lease_break_period(&self) -> Option<u8> {
81+
self.lease_break_period
82+
}
83+
}
84+
85+
impl<'a, ContainerNameSet> LeaseIdOption<'a> for BreakLeaseBuilder<'a, ContainerNameSet>
86+
where
87+
ContainerNameSet: ToAssign,
88+
{
89+
fn lease_id(&self) -> Option<&'a LeaseId> {
90+
self.lease_id
91+
}
92+
}
93+
94+
impl<'a, ContainerNameSet> ContainerNameSupport<'a> for BreakLeaseBuilder<'a, ContainerNameSet>
95+
where
96+
ContainerNameSet: ToAssign,
97+
{
98+
type O = BreakLeaseBuilder<'a, Yes>;
99+
100+
fn with_container_name(self, container_name: &'a str) -> Self::O {
101+
BreakLeaseBuilder {
102+
client: self.client,
103+
p_container_name: PhantomData {},
104+
container_name: Some(container_name),
105+
client_request_id: self.client_request_id,
106+
timeout: self.timeout,
107+
lease_break_period: self.lease_break_period,
108+
lease_id: self.lease_id,
109+
}
110+
}
111+
}
112+
113+
impl<'a, ContainerNameSet> ClientRequestIdSupport<'a> for BreakLeaseBuilder<'a, ContainerNameSet>
114+
where
115+
ContainerNameSet: ToAssign,
116+
{
117+
type O = BreakLeaseBuilder<'a, ContainerNameSet>;
118+
119+
fn with_client_request_id(self, client_request_id: &'a str) -> Self::O {
120+
BreakLeaseBuilder {
121+
client: self.client,
122+
p_container_name: PhantomData {},
123+
container_name: self.container_name,
124+
client_request_id: Some(client_request_id),
125+
timeout: self.timeout,
126+
lease_break_period: self.lease_break_period,
127+
lease_id: self.lease_id,
128+
}
129+
}
130+
}
131+
132+
impl<'a, ContainerNameSet> TimeoutSupport for BreakLeaseBuilder<'a, ContainerNameSet>
133+
where
134+
ContainerNameSet: ToAssign,
135+
{
136+
type O = BreakLeaseBuilder<'a, ContainerNameSet>;
137+
138+
fn with_timeout(self, timeout: u64) -> Self::O {
139+
BreakLeaseBuilder {
140+
client: self.client,
141+
p_container_name: PhantomData {},
142+
container_name: self.container_name,
143+
client_request_id: self.client_request_id,
144+
timeout: Some(timeout),
145+
lease_break_period: self.lease_break_period,
146+
lease_id: self.lease_id,
147+
}
148+
}
149+
}
150+
151+
impl<'a, ContainerNameSet> LeaseBreakPeriodSupport for BreakLeaseBuilder<'a, ContainerNameSet>
152+
where
153+
ContainerNameSet: ToAssign,
154+
{
155+
type O = BreakLeaseBuilder<'a, ContainerNameSet>;
156+
157+
fn with_lease_break_period(self, lease_break_period: u8) -> Self::O {
158+
BreakLeaseBuilder {
159+
client: self.client,
160+
p_container_name: PhantomData {},
161+
container_name: self.container_name,
162+
client_request_id: self.client_request_id,
163+
timeout: self.timeout,
164+
lease_break_period: Some(lease_break_period),
165+
lease_id: self.lease_id,
166+
}
167+
}
168+
}
169+
170+
impl<'a, ContainerNameSet> LeaseIdSupport<'a> for BreakLeaseBuilder<'a, ContainerNameSet>
171+
where
172+
ContainerNameSet: ToAssign,
173+
{
174+
type O = BreakLeaseBuilder<'a, ContainerNameSet>;
175+
176+
fn with_lease_id(self, lease_id: &'a LeaseId) -> Self::O {
177+
BreakLeaseBuilder {
178+
client: self.client,
179+
p_container_name: PhantomData {},
180+
container_name: self.container_name,
181+
client_request_id: self.client_request_id,
182+
timeout: self.timeout,
183+
lease_break_period: self.lease_break_period,
184+
lease_id: Some(lease_id),
185+
}
186+
}
187+
}
188+
189+
// methods callable regardless
190+
impl<'a, ContainerNameSet> BreakLeaseBuilder<'a, ContainerNameSet> where ContainerNameSet: ToAssign {}
191+
192+
impl<'a> BreakLeaseBuilder<'a, Yes> {
193+
pub fn finalize(self) -> impl Future<Item = BreakLeaseResponse, Error = AzureError> {
194+
let mut uri = format!(
195+
"https://{}.blob.core.windows.net/{}?comp=lease&restype=container",
196+
self.client().account(),
197+
self.container_name()
198+
);
199+
200+
if let Some(nm) = TimeoutOption::to_uri_parameter(&self) {
201+
uri = format!("{}&{}", uri, nm);
202+
}
203+
204+
let req = self.client().perform_request(
205+
&uri,
206+
Method::PUT,
207+
|ref mut request| {
208+
ClientRequestIdOption::add_header(&self, request);
209+
LeaseIdOption::add_header(&self, request);
210+
request.header(LEASE_ACTION, "break");
211+
LeaseBreakPeriodOption::add_header(&self, request);
212+
},
213+
Some(&[]),
214+
);
215+
216+
done(req)
217+
.from_err()
218+
.and_then(move |future_response| check_status_extract_headers_and_body(future_response, StatusCode::ACCEPTED))
219+
.and_then(|(headers, _body)| done(BreakLeaseResponse::from_response(&headers)))
220+
}
221+
}

src/azure/storage/container/requests/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod acquire_lease_builder;
2+
mod break_lease_builder;
23
mod create_builder;
34
mod delete_builder;
45
mod get_acl_builder;
@@ -16,3 +17,4 @@ pub use self::list_builder::ListBuilder;
1617
pub use self::release_lease_builder::ReleaseLeaseBuilder;
1718
pub use self::renew_lease_builder::RenewLeaseBuilder;
1819
pub use self::set_acl_builder::SetACLBuilder;
20+
pub use self::break_lease_builder::BreakLeaseBuilder;

src/azure/storage/container/requests/release_lease_builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl<'a> ReleaseLeaseBuilder<'a, Yes, Yes> {
194194
|ref mut request| {
195195
ClientRequestIdOption::add_header(&self, request);
196196
LeaseIdRequired::add_header(&self, request);
197-
request.header(LEASE_ACTION, "renew");
197+
request.header(LEASE_ACTION, "release");
198198
},
199199
Some(&[]),
200200
);

0 commit comments

Comments
 (0)