Skip to content

Commit 66db4b4

Browse files
Rick Rainey, CKA,CKS,CKADbmc-msftctaggart
authored
Add 'get_status' to datalake file client (#722)
Co-authored-by: bmc-msft <[email protected]> Co-authored-by: Cameron Taggart <[email protected]>
1 parent 9be6cf0 commit 66db4b4

16 files changed

+244
-17
lines changed

sdk/storage_datalake/src/clients/file_client.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ impl FileClient {
118118
HeadPathBuilder::new(self.clone(), self.file_system_client.context.clone())
119119
}
120120

121+
pub fn get_status(&self) -> HeadPathBuilder<Self> {
122+
HeadPathBuilder::new(self.clone(), self.file_system_client.context.clone())
123+
.action(PathGetPropertiesAction::GetStatus)
124+
}
125+
121126
pub fn set_properties(&self, properties: Properties) -> PatchPathBuilder<Self> {
122127
PatchPathBuilder::new(self.clone(), self.file_system_client.context.clone())
123128
.properties(properties)

sdk/storage_datalake/src/operations/path_head.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use crate::{clients::PathClient, request_options::*, Properties};
2-
use azure_core::headers::{etag_from_headers, last_modified_from_headers};
2+
use azure_core::headers::{
3+
etag_from_headers, get_option_str_from_headers, last_modified_from_headers,
4+
};
35
use azure_core::prelude::*;
46
use azure_core::{AppendToUrlQuery, Response as HttpResponse};
57
use azure_storage::core::headers::CommonStorageResponseHeaders;
@@ -87,18 +89,20 @@ pub struct HeadPathResponse {
8789
pub common_storage_response_headers: CommonStorageResponseHeaders,
8890
pub etag: String,
8991
pub last_modified: DateTime<Utc>,
90-
pub properties: Properties,
92+
pub properties: Option<Properties>,
9193
}
9294

9395
impl HeadPathResponse {
9496
pub async fn try_from(response: HttpResponse) -> Result<Self, crate::Error> {
95-
let (_status_code, headers, _pinned_stream) = response.deconstruct();
97+
let headers = response.headers();
9698

9799
Ok(Self {
98-
common_storage_response_headers: (&headers).try_into()?,
99-
etag: etag_from_headers(&headers)?,
100-
last_modified: last_modified_from_headers(&headers)?,
101-
properties: (&headers).try_into()?,
100+
common_storage_response_headers: headers.try_into()?,
101+
etag: etag_from_headers(headers)?,
102+
last_modified: last_modified_from_headers(headers)?,
103+
properties: get_option_str_from_headers(headers, azure_core::headers::PROPERTIES)?
104+
.map(Properties::try_from)
105+
.transpose()?,
102106
})
103107
}
104108
}

sdk/storage_datalake/src/properties.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use azure_core::headers::{self, Header};
1+
use azure_core::headers::{self, Header, PROPERTIES};
22
use http::HeaderMap;
33
use std::borrow::Cow;
44
use std::collections::BTreeMap;
@@ -7,8 +7,6 @@ use std::convert::TryFrom;
77
#[derive(Debug, Clone, PartialEq, Eq)]
88
pub struct Properties(BTreeMap<Cow<'static, str>, Cow<'static, str>>);
99

10-
const HEADER: &str = "x-ms-properties";
11-
1210
impl Default for Properties {
1311
fn default() -> Self {
1412
Self::new()
@@ -35,7 +33,7 @@ impl Properties {
3533

3634
impl Header for Properties {
3735
fn name(&self) -> headers::HeaderName {
38-
HEADER.into()
36+
PROPERTIES.into()
3937
}
4038

4139
fn value(&self) -> headers::HeaderValue {
@@ -54,12 +52,21 @@ impl TryFrom<&HeaderMap> for Properties {
5452
type Error = crate::Error;
5553

5654
fn try_from(headers: &HeaderMap) -> Result<Self, Self::Error> {
57-
let mut properties = Self::new();
58-
5955
let header_value = headers
60-
.get(HEADER)
61-
.ok_or_else(|| crate::Error::HeaderNotFound(HEADER.to_owned()))?
56+
.get(PROPERTIES)
57+
.ok_or_else(|| crate::Error::HeaderNotFound(PROPERTIES.to_owned()))?
6258
.to_str()?;
59+
60+
Properties::try_from(header_value)
61+
}
62+
}
63+
64+
impl TryFrom<&str> for Properties {
65+
type Error = crate::Error;
66+
67+
fn try_from(header_value: &str) -> Result<Self, Self::Error> {
68+
let mut properties = Self::new();
69+
6370
if header_value.is_empty() {
6471
return Ok(properties);
6572
}

sdk/storage_datalake/tests/files.rs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![cfg(feature = "mock_transport_framework")]
22
use azure_storage_datalake::Properties;
3-
use std::error::Error;
3+
use std::{assert_eq, assert_ne, error::Error};
44

55
mod setup;
66

@@ -162,7 +162,7 @@ async fn file_rename() -> Result<(), Box<dyn Error + Send + Sync>> {
162162
let renamed_file_properties = file_client3.get_properties().into_future().await?;
163163

164164
// when renaming a file, the source file properties should be propagated
165-
assert_eq!(renamed_file_properties.properties, file_properties);
165+
assert_eq!(renamed_file_properties.properties, Some(file_properties));
166166
assert_ne!(
167167
renamed_file_properties.properties,
168168
original_target_file_properties.properties
@@ -176,3 +176,48 @@ async fn file_rename() -> Result<(), Box<dyn Error + Send + Sync>> {
176176

177177
Ok(())
178178
}
179+
180+
#[tokio::test]
181+
async fn file_get_properties() -> Result<(), Box<dyn Error + Send + Sync>> {
182+
let data_lake_client = setup::create_data_lake_client("datalake_file_properties")
183+
.await
184+
.unwrap();
185+
186+
let file_system_name = "azurerustsdk-datalake-file-get-properties";
187+
let file_system_client = data_lake_client
188+
.clone()
189+
.into_file_system_client(file_system_name.to_string());
190+
191+
let create_fs_response = file_system_client.create().into_future().await?;
192+
assert!(
193+
create_fs_response.namespace_enabled,
194+
"namespace should be enabled"
195+
);
196+
197+
let file_path = "some/path/e2etest-file.txt";
198+
let file_client = file_system_client.get_file_client(file_path);
199+
200+
file_client.create().into_future().await?;
201+
202+
let mut file_properties = Properties::new();
203+
file_properties.insert("AddedVia", "Azure SDK for Rust");
204+
205+
file_client
206+
.create()
207+
.properties(file_properties.clone())
208+
.into_future()
209+
.await?;
210+
211+
// Get properties
212+
let file_properties = file_client.get_properties().into_future().await?;
213+
assert!(file_properties.properties.is_some());
214+
215+
// Get status (ie: only system-defined properties)
216+
let file_properties = file_client.get_status().into_future().await?;
217+
assert!(!file_properties.properties.is_some());
218+
219+
// Cleanup
220+
file_system_client.delete().into_future().await?;
221+
222+
Ok(())
223+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"uri": "/azurerustsdk-datalake-file-get-properties?resource=filesystem",
3+
"method": "PUT",
4+
"headers": {
5+
"authorization": "<<STRIPPED>>",
6+
"content-length": "0",
7+
"user-agent": "azsdk-rust-storage_datalake/0.1.1 (1.59.0; linux; x86_64)",
8+
"x-ms-date": "Mon, 11 Apr 2022 16:19:46 GMT",
9+
"x-ms-version": "2019-12-12"
10+
},
11+
"body": ""
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"status": 201,
3+
"headers": {
4+
"content-length": "0",
5+
"date": "Mon, 11 Apr 2022 16:19:47 GMT",
6+
"etag": "\"0x8DA1BD718A4B558\"",
7+
"last-modified": "Mon, 11 Apr 2022 16:19:47 GMT",
8+
"server": "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0",
9+
"x-ms-namespace-enabled": "true",
10+
"x-ms-request-id": "def5aa2e-901f-0073-67bf-4d3635000000",
11+
"x-ms-version": "2019-12-12"
12+
},
13+
"body": ""
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"uri": "/azurerustsdk-datalake-file-get-properties/some/path/e2etest-file.txt?resource=file",
3+
"method": "PUT",
4+
"headers": {
5+
"authorization": "<<STRIPPED>>",
6+
"content-length": "0",
7+
"user-agent": "azsdk-rust-storage_datalake/0.1.1 (1.59.0; linux; x86_64)",
8+
"x-ms-date": "Mon, 11 Apr 2022 16:19:47 GMT",
9+
"x-ms-version": "2019-12-12"
10+
},
11+
"body": ""
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"status": 201,
3+
"headers": {
4+
"content-length": "0",
5+
"date": "Mon, 11 Apr 2022 16:19:47 GMT",
6+
"etag": "\"0x8DA1BD718F18E95\"",
7+
"last-modified": "Mon, 11 Apr 2022 16:19:47 GMT",
8+
"server": "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0",
9+
"x-ms-request-id": "def5aa30-901f-0073-69bf-4d3635000000",
10+
"x-ms-request-server-encrypted": "true",
11+
"x-ms-version": "2019-12-12"
12+
},
13+
"body": ""
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"uri": "/azurerustsdk-datalake-file-get-properties/some/path/e2etest-file.txt?resource=file",
3+
"method": "PUT",
4+
"headers": {
5+
"authorization": "<<STRIPPED>>",
6+
"content-length": "0",
7+
"user-agent": "azsdk-rust-storage_datalake/0.1.1 (1.59.0; linux; x86_64)",
8+
"x-ms-date": "Mon, 11 Apr 2022 16:19:47 GMT",
9+
"x-ms-properties": "AddedVia=QXp1cmUgU0RLIGZvciBSdXN0",
10+
"x-ms-version": "2019-12-12"
11+
},
12+
"body": ""
13+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"status": 201,
3+
"headers": {
4+
"content-length": "0",
5+
"date": "Mon, 11 Apr 2022 16:19:47 GMT",
6+
"etag": "\"0x8DA1BD71918DC66\"",
7+
"last-modified": "Mon, 11 Apr 2022 16:19:47 GMT",
8+
"server": "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0",
9+
"x-ms-request-id": "def5aa32-901f-0073-6bbf-4d3635000000",
10+
"x-ms-request-server-encrypted": "true",
11+
"x-ms-version": "2019-12-12"
12+
},
13+
"body": ""
14+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"uri": "/azurerustsdk-datalake-file-get-properties/some/path/e2etest-file.txt",
3+
"method": "HEAD",
4+
"headers": {
5+
"authorization": "<<STRIPPED>>",
6+
"user-agent": "azsdk-rust-storage_datalake/0.1.1 (1.59.0; linux; x86_64)",
7+
"x-ms-date": "Mon, 11 Apr 2022 16:19:47 GMT",
8+
"x-ms-version": "2019-12-12"
9+
},
10+
"body": ""
11+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"status": 200,
3+
"headers": {
4+
"accept-ranges": "bytes",
5+
"content-length": "0",
6+
"content-type": "application/octet-stream",
7+
"date": "Mon, 11 Apr 2022 16:19:48 GMT",
8+
"etag": "\"0x8DA1BD71918DC66\"",
9+
"last-modified": "Mon, 11 Apr 2022 16:19:47 GMT",
10+
"server": "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0",
11+
"x-ms-content-crc64": "AAAAAAAAAAA=",
12+
"x-ms-group": "$superuser",
13+
"x-ms-lease-state": "available",
14+
"x-ms-lease-status": "unlocked",
15+
"x-ms-owner": "$superuser",
16+
"x-ms-permissions": "rw-r-----",
17+
"x-ms-properties": "AddedVia=QXp1cmUgU0RLIGZvciBSdXN0",
18+
"x-ms-request-id": "def5aa4e-901f-0073-76bf-4d3635000000",
19+
"x-ms-resource-type": "file",
20+
"x-ms-server-encrypted": "true",
21+
"x-ms-version": "2019-12-12"
22+
},
23+
"body": ""
24+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"uri": "/azurerustsdk-datalake-file-get-properties/some/path/e2etest-file.txt?action=getStatus",
3+
"method": "HEAD",
4+
"headers": {
5+
"authorization": "<<STRIPPED>>",
6+
"user-agent": "azsdk-rust-storage_datalake/0.1.1 (1.59.0; linux; x86_64)",
7+
"x-ms-date": "Mon, 11 Apr 2022 16:19:48 GMT",
8+
"x-ms-version": "2019-12-12"
9+
},
10+
"body": ""
11+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"status": 200,
3+
"headers": {
4+
"content-length": "0",
5+
"date": "Mon, 11 Apr 2022 16:19:48 GMT",
6+
"etag": "\"0x8DA1BD71918DC66\"",
7+
"last-modified": "Mon, 11 Apr 2022 16:19:47 GMT",
8+
"server": "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0",
9+
"x-ms-group": "$superuser",
10+
"x-ms-owner": "$superuser",
11+
"x-ms-permissions": "rw-r-----",
12+
"x-ms-request-id": "def5aa4f-901f-0073-77bf-4d3635000000",
13+
"x-ms-resource-type": "file",
14+
"x-ms-server-encrypted": "true",
15+
"x-ms-version": "2019-12-12"
16+
},
17+
"body": ""
18+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"uri": "/azurerustsdk-datalake-file-get-properties?resource=filesystem",
3+
"method": "DELETE",
4+
"headers": {
5+
"authorization": "<<STRIPPED>>",
6+
"content-length": "0",
7+
"user-agent": "azsdk-rust-storage_datalake/0.1.1 (1.59.0; linux; x86_64)",
8+
"x-ms-date": "Mon, 11 Apr 2022 16:19:48 GMT",
9+
"x-ms-version": "2019-12-12"
10+
},
11+
"body": ""
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"status": 202,
3+
"headers": {
4+
"content-length": "0",
5+
"date": "Mon, 11 Apr 2022 16:19:48 GMT",
6+
"server": "Windows-Azure-HDFS/1.0 Microsoft-HTTPAPI/2.0",
7+
"x-ms-request-id": "def5aa50-901f-0073-78bf-4d3635000000",
8+
"x-ms-version": "2019-12-12"
9+
},
10+
"body": ""
11+
}

0 commit comments

Comments
 (0)