Skip to content

Commit 5f4fdd1

Browse files
authored
data_lake/create_path improvements (#451)
* Add break statement in loop. * Remove explicit type. * Use vec! macro. * Remove println! calls. * Remove unused. * Add guard to auth policy send function.
1 parent 0f36ea2 commit 5f4fdd1

File tree

4 files changed

+13
-44
lines changed

4 files changed

+13
-44
lines changed

sdk/storage/src/data_lake/authorization_policy.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ impl Policy<DataLakeContext> for AuthorizationPolicy {
2525
request: &mut Request,
2626
next: &[Arc<dyn Policy<DataLakeContext>>],
2727
) -> PolicyResult<Response> {
28+
if next.is_empty() {
29+
return Err(Box::new(azure_core::PipelineError::InvalidTailPolicy(
30+
"Authorization policies cannot be the last policy of a pipeline".to_owned(),
31+
)));
32+
}
33+
2834
let auth_header_value = format!("Bearer {}", &self.bearer_token);
2935

3036
request

sdk/storage/src/data_lake/clients/data_lake_client.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,10 @@ impl DataLakeClient {
114114
let auth_policy: Arc<dyn azure_core::Policy<DataLakeContext>> =
115115
Arc::new(AuthorizationPolicy::new(bearer_token.clone()));
116116

117-
let mut per_retry_policies = Vec::new();
118117
// take care of adding the AuthorizationPolicy as **last** retry policy.
119118
// Policies can change the url and/or the headers and the AuthorizationPolicy
120119
// must be able to inspect them or the resulting token will be invalid.
121-
per_retry_policies.push(auth_policy);
120+
let per_retry_policies = vec![auth_policy];
122121

123122
let pipeline = Pipeline::new(
124123
option_env!("CARGO_PKG_NAME"),

sdk/storage/src/data_lake/clients/file_system_client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl FileSystemClient {
7070
options: CreatePathOptions<'_>,
7171
) -> Result<CreatePathResponse, crate::Error> {
7272
let mut request = self.prepare_request_pipeline(&path_name, http::Method::PUT);
73-
let contents: DataLakeContext = DataLakeContext {};
73+
let contents = DataLakeContext {};
7474
let mut pipeline_context = PipelineContext::new(ctx, contents);
7575

7676
options.decorate_request(&mut request)?;

sdk/storage/tests/data_lake.rs

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ async fn test_data_lake_file_system_functions() -> Result<(), Box<dyn Error + Se
2727
StorageAccountClient::new_access_key(http_client.clone(), &account, &master_key);
2828

2929
let resource_id = "https://storage.azure.com/";
30-
println!("getting bearer token for '{}'...", resource_id);
3130
let bearer_token = DefaultCredential::default().get_token(resource_id).await?;
32-
println!("token expires on {}", bearer_token.expires_on);
33-
println!();
3431

3532
let data_lake_client = storage_account_client
3633
.as_storage_client()
@@ -43,21 +40,16 @@ async fn test_data_lake_file_system_functions() -> Result<(), Box<dyn Error + Se
4340
let mut fs_properties = Properties::new();
4441
fs_properties.insert("AddedVia", "Azure SDK for Rust");
4542

46-
println!("creating file system '{}'...", &file_system_name);
4743
let create_fs_response = file_system_client
4844
.create()
4945
.properties(&fs_properties)
5046
.execute()
5147
.await?;
52-
println!("create file system response == {:?}", create_fs_response);
5348
assert!(
5449
create_fs_response.namespace_enabled,
5550
"namespace should be enabled"
5651
);
57-
println!("namespace is enabled");
58-
println!();
5952

60-
println!("listing file systems...");
6153
let mut stream = Box::pin(
6254
data_lake_client
6355
.list()
@@ -69,14 +61,12 @@ async fn test_data_lake_file_system_functions() -> Result<(), Box<dyn Error + Se
6961
for fs in list_fs_response.unwrap().file_systems {
7062
if fs.name == file_system_name {
7163
found = true;
64+
break;
7265
}
7366
}
7467
}
7568
assert!(found, "did not find created file system");
76-
println!("found created file system");
77-
println!();
7869

79-
println!("getting file system properties...");
8070
let get_fs_props_response = file_system_client.get_properties().execute().await?;
8171
let properties_hashmap = get_fs_props_response.properties.hash_map();
8272
let added_via_option = properties_hashmap.get("AddedVia");
@@ -89,51 +79,30 @@ async fn test_data_lake_file_system_functions() -> Result<(), Box<dyn Error + Se
8979
"Azure SDK for Rust",
9080
"did not find expected property value for: AddedVia"
9181
);
92-
println!("found expected file system property: AddedVia");
93-
println!();
9482

9583
let file_name = "e2etest-file.txt";
9684

97-
println!("creating path '{}'...", file_name);
98-
let create_path_response = file_system_client
85+
file_system_client
9986
.create_path(Context::default(), file_name, CreatePathOptions::default())
10087
.await?;
101-
println!("create path response == {:?}", create_path_response);
102-
println!();
10388

104-
println!("creating path '{}' (overwrite)...", file_name);
105-
let create_path_response = file_system_client
89+
file_system_client
10690
.create_path(Context::default(), file_name, CreatePathOptions::default())
10791
.await?;
108-
println!("create path response == {:?}", create_path_response);
109-
println!();
11092

111-
println!("creating path '{}' (do not overwrite)...", file_name);
11293
let do_not_overwrite =
11394
CreatePathOptions::new().if_match_condition(IfMatchCondition::NotMatch("*"));
11495
let create_path_result = file_system_client
11596
.create_path(Context::default(), file_name, do_not_overwrite)
11697
.await;
11798
assert!(create_path_result.is_err());
118-
println!(
119-
"create path result (should fail) == {:?}",
120-
create_path_result
121-
);
122-
println!();
12399

124-
println!("setting file system properties...");
125100
fs_properties.insert("ModifiedBy", "Iota");
126-
let set_fs_props_response = file_system_client
101+
file_system_client
127102
.set_properties(Some(&fs_properties))
128103
.execute()
129104
.await?;
130-
println!(
131-
"set file system properties response == {:?}",
132-
set_fs_props_response
133-
);
134-
println!();
135105

136-
println!("getting file system properties...");
137106
let get_fs_props_response = file_system_client.get_properties().execute().await?;
138107
let properties_hashmap = get_fs_props_response.properties.hash_map();
139108
let modified_by_option = properties_hashmap.get("ModifiedBy");
@@ -146,13 +115,8 @@ async fn test_data_lake_file_system_functions() -> Result<(), Box<dyn Error + Se
146115
"Iota",
147116
"did not find expected property value for: ModifiedBy"
148117
);
149-
println!("found expected file system property: ModifiedBy");
150-
println!();
151118

152-
println!("deleting file system...");
153-
let delete_fs_response = file_system_client.delete().execute().await?;
154-
println!("delete file system response == {:?}", delete_fs_response);
155-
println!();
119+
file_system_client.delete().execute().await?;
156120

157121
Ok(())
158122
}

0 commit comments

Comments
 (0)